Skip to contentSkip to conversation

ARM: NUC900: Add cpufreq driver for nuc900 CPUs

PATCH New Li Jie 3 participants 7 messages Dec 14, 2009 – Dec 21, 2009

Subsystems (2)
lore
Share & tools
lore

Li Jie

author
#0 lore raw

PATCH 1/1 ARM: NUC900: Add cpufreq driver for nuc900 CPUs

Hi, Wan ZongShun:

This patch add cpufreq support for nuc900 CPUs.

---
 arch/arm/Kconfig                |    1 +
 arch/arm/mach-w90x900/Makefile  |    2 +-
 arch/arm/mach-w90x900/cpu.c     |    4 +-
 arch/arm/mach-w90x900/cpufreq.c |  146 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 151 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/mach-w90x900/cpufreq.c
arch/arm/Kconfig +1 -0
index cf8a99f..60186fe 100644
@@ -539,6 +539,7 @@ config ARCH_W90X900
 	select COMMON_CLKDEV
 	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
+	select ARCH_HAS_CPUFREQ
 	help
 	  Support for Nuvoton (Winbond logic dept.) ARM9 processor,
 	  At present, the w90x900 has been renamed nuc900, regarding
arch/arm/mach-w90x900/Makefile +1 -1
index 828c032..7f114fb 100644
@@ -5,7 +5,7 @@
 # Object file lists.
 
 obj-y				:= irq.o time.o mfp.o gpio.o clock.o
-obj-y				+= clksel.o dev.o cpu.o
+obj-y				+= clksel.o dev.o cpu.o cpufreq.o
 # W90X900 CPU support files
 
 obj-$(CONFIG_CPU_W90P910)	+= nuc910.o
arch/arm/mach-w90x900/cpu.c +3 -1
index 921cef9..7b608b8 100644
@@ -107,7 +107,7 @@ struct platform_device nuc900_serial_device = {
 };
 
 /*Set NUC900 series cpu frequence*/
-static int __init nuc900_set_clkval(unsigned int cpufreq)
+int nuc900_set_clkval(unsigned int cpufreq)
 {
 	unsigned int pllclk, ahbclk, apbclk, val;
 
@@ -156,6 +156,8 @@ static int __init nuc900_set_clkval(unsigned int cpufreq)
 
 	return 	0;
 }
+EXPORT_SYMBOL(nuc900_set_clkval);
+
 static int __init nuc900_set_cpufreq(char *str)
 {
 	unsigned long cpufreq, val;
arch/arm/mach-w90x900/cpufreq.c new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
1.6.5.4
#1 lore raw

PATCH 1/1 ARM: NUC900: Add cpufreq driver for nuc900 CPUs

Hi Jie,

This is a good patch, thanks!
Some comments below:

2009/12/14 Li Jie <[email protected]>:

Quoted 80 lines

Hi, Wan ZongShun:

This patch add cpufreq support for nuc900 CPUs.

---

?arch/arm/Kconfig ? ? ? ? ? ? ? ?| ? ?1 +
?arch/arm/mach-w90x900/Makefile ?| ? ?2 +-
?arch/arm/mach-w90x900/cpu.c ? ? | ? ?4 +-
?arch/arm/mach-w90x900/cpufreq.c | ?146 +++++++++++++++++++++++++++++++++++++++

?4 files changed, 151 insertions(+), 2 deletions(-) ?create mode 100644 arch/arm/mach-w90x900/cpufreq.c

arch/arm/Kconfig +0 -0
index cf8a99f..60186fe 100644
@@ -539,6 +539,7 @@ config ARCH_W90X900

? ? ? ?select COMMON_CLKDEV
? ? ? ?select GENERIC_TIME
? ? ? ?select GENERIC_CLOCKEVENTS
+ ? ? ? select ARCH_HAS_CPUFREQ
? ? ? ?help
? ? ? ? ?Support for Nuvoton (Winbond logic dept.) ARM9 processor, ? ? ? ? ?At present, the w90x900 has been renamed nuc900, regarding

arch/arm/mach-w90x900/Makefile +0 -0
index 828c032..7f114fb 100644
@@ -5,7 +5,7 @@

?# Object file lists.

?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?:= irq.o time.o mfp.o gpio.o clock.o

arch/arm/mach-w90x900/Makefile +1 -1
-obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= clksel.o dev.o cpu.o
+obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= clksel.o dev.o cpu.o cpufreq.o

?# W90X900 CPU support files

?obj-$(CONFIG_CPU_W90P910) ? ? ?+= nuc910.o

arch/arm/mach-w90x900/cpu.c +0 -0
index 921cef9..7b608b8 100644
@@ -107,7 +107,7 @@ struct platform_device nuc900_serial_device = {
 ?};
 

?/*Set NUC900 series cpu frequence*/

arch/arm/mach-w90x900/cpu.c +1 -1
-static int __init nuc900_set_clkval(unsigned int cpufreq)
+int nuc900_set_clkval(unsigned int cpufreq)

?{
? ? ? ?unsigned int pllclk, ahbclk, apbclk, val;

arch/arm/mach-w90x900/cpu.c +2 -0
@@ -156,6 +156,8 @@ static int __init nuc900_set_clkval(unsigned int cpufreq)
 
 ? ? ? ?return ?0;
 ?}
+EXPORT_SYMBOL(nuc900_set_clkval);
+
 ?static int __init nuc900_set_cpufreq(char *str)
 ?{
 ? ? ? ?unsigned long cpufreq, val;
arch/arm/mach-w90x900/cpufreq.c new file +14 -0
new file mode 100644
index 0000000..07b8685
@@ -0,0 +1,146 @@
+/* linux/arch/arm/mach-w90x900/cpufreq.c
+ *
+ * NUC900 CPUfreq Support
+ *
+ * Li Jie <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/init.h>

arch/arm/mach-w90x900/cpufreq.c line 24

Quoted 10 lines
arch/arm/mach-w90x900/cpufreq.c new file +10 -0
+#include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include <asm/io.h>
+#include <mach/hardware.h>
+#include <mach/regs-clock.h>
+
+extern int nuc900_set_clkval(unsigned int cpufreq);
+

Please put this extern definition in cpu.h file and add include "cpu.h".

arch/arm/mach-w90x900/cpufreq.c line 33

Quoted 9 lines
arch/arm/mach-w90x900/cpufreq.c new file +9 -0
+static struct cpufreq_frequency_table nuc900_freq_table[] = {
+ ? ? ? { 0, ?66000 },
+ ? ? ? { 1, 100000 },
+ ? ? ? { 2, 120000 },
+ ? ? ? { 3, 166000 },
+ ? ? ? { 4, 200000 },
+ ? ? ? { 5, CPUFREQ_TABLE_END },
+};
+

Please define those cpu frequncy number as clear Marco, such as:

#define FREQ_66M 66000

and, the Macro can be re-used by below codes.

Quoted 21 lines
arch/arm/mach-w90x900/cpufreq.c new file +21 -0
+static int nuc900_cpufreq_verify_speed(struct cpufreq_policy *policy)
+{
+ ? ? ? if (policy->cpu != 0)
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? return cpufreq_frequency_table_verify(policy, nuc900_freq_table);
+}
+
+static unsigned int nuc900_cpufreq_get_speed(unsigned int cpu)
+{
+ ? ? ? int pllclk;
+
+ ? ? ? if (cpu != 0)
+ ? ? ? ? ? ? ? return 0;
+
+ ? ? ? pllclk = __raw_readl(REG_PLLCON0);
+
+ ? ? ? switch (pllclk) {
+ ? ? ? case PLL_66MHZ:
+ ? ? ? ? ? ? ? return 66 * 1000;
+ ? ? ? case PLL_100MHZ:

arch/arm/mach-w90x900/cpufreq.c line 64

Quoted 10 lines
arch/arm/mach-w90x900/cpufreq.c new file +10 -0
+ ? ? ? ? ? ? ? return 100 * 1000;
+ ? ? ? case PLL_120MHZ:
+ ? ? ? ? ? ? ? return 120 * 1000;
+ ? ? ? case PLL_166MHZ:
+ ? ? ? ? ? ? ? return 166 * 1000;
+ ? ? ? case PLL_200MHZ:
+ ? ? ? ? ? ? ? return 200 * 1000;
+ ? ? ? }
+
+ ? ? ? pr_err("cpufreq: Failed to get frequency: %X\n", pllclk);

Though %X is right, but ,is lowercase more unanimous?

Quoted 55 lines
arch/arm/mach-w90x900/cpufreq.c new file +55 -0
+ ? ? ? return 0;
+}
+
+static int nuc900_cpufreq_set_target(struct cpufreq_policy *policy,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned int target_freq,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned int relation)
+{
+ ? ? ? int ret;
+ ? ? ? unsigned int i;
+ ? ? ? struct cpufreq_freqs freqs;
+
+ ? ? ? ret = cpufreq_frequency_table_target(policy, nuc900_freq_table,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?target_freq, relation, &i);
+ ? ? ? if (ret != 0)
+ ? ? ? ? ? ? ? return ret;
+
+ ? ? ? freqs.cpu = 0;
+ ? ? ? freqs.old = nuc900_cpufreq_get_speed(0);
+ ? ? ? freqs.new = nuc900_freq_table[i].frequency;
+ ? ? ? freqs.flags = 0;
+
+ ? ? ? if (freqs.old == freqs.new)
+ ? ? ? ? ? ? ? return 0;
+
+ ? ? ? pr_debug("cpufreq: Transition %d-%dkHz\n", freqs.old, freqs.new);
+
+ ? ? ? cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+
+ ? ? ? nuc900_set_clkval(freqs.new / 1000);
+ ? ? ? cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+
+ ? ? ? return 0;
+}
+
+static int __init nuc900_cpufreq_driver_init(struct cpufreq_policy *policy)
+{
+ ? ? ? int ret;
+
+ ? ? ? if (policy->cpu != 0)
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? policy->cur = nuc900_cpufreq_get_speed(0);
+
+ ? ? ? policy->cpuinfo.transition_latency = 2 * 1000; /* FIXME, assumed */
+ ? ? ? policy->cpuinfo.min_freq = 66000; ? ? ? ? ? ? ?/* khz */
+ ? ? ? policy->cpuinfo.max_freq = 200000;
+ ? ? ? policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
+
+ ? ? ? ret = cpufreq_frequency_table_cpuinfo(policy, nuc900_freq_table);
+ ? ? ? if (ret != 0)
+ ? ? ? ? ? ? ? pr_err("cpufreq: Failed to configure frequency table: %d\n",
+ ? ? ? ? ? ? ? ? ? ? ?ret);
+
+ ? ? ? return ret;
+}

arch/arm/mach-w90x900/cpufreq.c line 129

Quoted 10 lines
arch/arm/mach-w90x900/cpufreq.c new file +10 -0
+
+static struct cpufreq_driver nuc900_cpufreq_driver = {
+ ? ? ? .owner ? ? ? ? ?= THIS_MODULE,
+ ? ? ? .flags ? ? ? ? ?= 0,
+ ? ? ? .verify ? ? ? ? = nuc900_cpufreq_verify_speed,
+ ? ? ? .target ? ? ? ? = nuc900_cpufreq_set_target,
+ ? ? ? .get ? ? ? ? ? ?= nuc900_cpufreq_get_speed,
+ ? ? ? .init ? ? ? ? ? = nuc900_cpufreq_driver_init,
+ ? ? ? .name ? ? ? ? ? = "nuc900",
+};

Don't name this cpufreq driver 'nuc900'.

Quoted 19 lines
arch/arm/mach-w90x900/cpufreq.c new file +16 -1
+static int __init nuc900_cpufreq_init(void)
+{
+ ? ? ? return cpufreq_register_driver(&nuc900_cpufreq_driver);
+}
+
+static void __exit nuc900_cpufreq_exit(void)
+{
+ ? ? ? cpufreq_unregister_driver(&nuc900_cpufreq_driver);
+}
+
+MODULE_AUTHOR ("Li Jie <[email protected]>");
+MODULE_DESCRIPTION ("cpufreq driver for NUC900");
+MODULE_LICENSE ("GPL");
+
+module_init(nuc900_cpufreq_init);
+module_exit(nuc900_cpufreq_exit);
--

1.6.5.4

Signature · 3 lines
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#2 lore raw

PATCH 1/1 ARM: NUC900: Add cpufreq driver for nuc900 CPUs

Quoted 4 lines · Wan ZongShun

Hi Jie,

This is a good patch, thanks!
Some comments below:

Hi Wan,

Thanks for you comments,
I'll send a new patch later.

Quoted 240 lines

2009/12/14 Li Jie <[email protected]>:

Quoted 80 lines

Hi, Wan ZongShun:

This patch add cpufreq support for nuc900 CPUs.

---

?arch/arm/Kconfig ? ? ? ? ? ? ? ?| ? ?1 +
?arch/arm/mach-w90x900/Makefile ?| ? ?2 +-
?arch/arm/mach-w90x900/cpu.c ? ? | ? ?4 +-
?arch/arm/mach-w90x900/cpufreq.c | ?146 +++++++++++++++++++++++++++++++++++++++

?4 files changed, 151 insertions(+), 2 deletions(-) ?create mode 100644 arch/arm/mach-w90x900/cpufreq.c

arch/arm/Kconfig +0 -0
index cf8a99f..60186fe 100644
@@ -539,6 +539,7 @@ config ARCH_W90X900

? ? ? ?select COMMON_CLKDEV
? ? ? ?select GENERIC_TIME
? ? ? ?select GENERIC_CLOCKEVENTS
+ ? ? ? select ARCH_HAS_CPUFREQ
? ? ? ?help
? ? ? ? ?Support for Nuvoton (Winbond logic dept.) ARM9 processor, ? ? ? ? ?At present, the w90x900 has been renamed nuc900, regarding

arch/arm/mach-w90x900/Makefile +0 -0
index 828c032..7f114fb 100644
@@ -5,7 +5,7 @@

?# Object file lists.

?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?:= irq.o time.o mfp.o gpio.o clock.o

arch/arm/mach-w90x900/Makefile +1 -1
-obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= clksel.o dev.o cpu.o
+obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= clksel.o dev.o cpu.o cpufreq.o

?# W90X900 CPU support files

?obj-$(CONFIG_CPU_W90P910) ? ? ?+= nuc910.o

arch/arm/mach-w90x900/cpu.c +0 -0
index 921cef9..7b608b8 100644
@@ -107,7 +107,7 @@ struct platform_device nuc900_serial_device = {
 ?};
 

?/*Set NUC900 series cpu frequence*/

arch/arm/mach-w90x900/cpu.c +1 -1
-static int __init nuc900_set_clkval(unsigned int cpufreq)
+int nuc900_set_clkval(unsigned int cpufreq)

?{
? ? ? ?unsigned int pllclk, ahbclk, apbclk, val;

arch/arm/mach-w90x900/cpu.c +2 -0
@@ -156,6 +156,8 @@ static int __init nuc900_set_clkval(unsigned int cpufreq)
 
 ? ? ? ?return ?0;
 ?}
+EXPORT_SYMBOL(nuc900_set_clkval);
+
 ?static int __init nuc900_set_cpufreq(char *str)
 ?{
 ? ? ? ?unsigned long cpufreq, val;
arch/arm/mach-w90x900/cpufreq.c new file +14 -0
new file mode 100644
index 0000000..07b8685
@@ -0,0 +1,146 @@
+/* linux/arch/arm/mach-w90x900/cpufreq.c
+ *
+ * NUC900 CPUfreq Support
+ *
+ * Li Jie <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/init.h>

arch/arm/mach-w90x900/cpufreq.c line 24

Quoted 10 lines
arch/arm/mach-w90x900/cpufreq.c new file +10 -0
+#include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include <asm/io.h>
+#include <mach/hardware.h>
+#include <mach/regs-clock.h>
+
+extern int nuc900_set_clkval(unsigned int cpufreq);
+

Please put this extern definition in cpu.h file and add include "cpu.h".

arch/arm/mach-w90x900/cpufreq.c line 33

Quoted 9 lines
arch/arm/mach-w90x900/cpufreq.c new file +9 -0
+static struct cpufreq_frequency_table nuc900_freq_table[] = {
+ ? ? ? { 0, ?66000 },
+ ? ? ? { 1, 100000 },
+ ? ? ? { 2, 120000 },
+ ? ? ? { 3, 166000 },
+ ? ? ? { 4, 200000 },
+ ? ? ? { 5, CPUFREQ_TABLE_END },
+};
+

Please define those cpu frequncy number as clear Marco, such as:

#define ?FREQ_66M 66000

and, the Macro can be re-used by below codes.

Quoted 21 lines
arch/arm/mach-w90x900/cpufreq.c new file +21 -0
+static int nuc900_cpufreq_verify_speed(struct cpufreq_policy *policy)
+{
+ ? ? ? if (policy->cpu != 0)
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? return cpufreq_frequency_table_verify(policy, nuc900_freq_table);
+}
+
+static unsigned int nuc900_cpufreq_get_speed(unsigned int cpu)
+{
+ ? ? ? int pllclk;
+
+ ? ? ? if (cpu != 0)
+ ? ? ? ? ? ? ? return 0;
+
+ ? ? ? pllclk = __raw_readl(REG_PLLCON0);
+
+ ? ? ? switch (pllclk) {
+ ? ? ? case PLL_66MHZ:
+ ? ? ? ? ? ? ? return 66 * 1000;
+ ? ? ? case PLL_100MHZ:

arch/arm/mach-w90x900/cpufreq.c line 64

Quoted 10 lines
arch/arm/mach-w90x900/cpufreq.c new file +10 -0
+ ? ? ? ? ? ? ? return 100 * 1000;
+ ? ? ? case PLL_120MHZ:
+ ? ? ? ? ? ? ? return 120 * 1000;
+ ? ? ? case PLL_166MHZ:
+ ? ? ? ? ? ? ? return 166 * 1000;
+ ? ? ? case PLL_200MHZ:
+ ? ? ? ? ? ? ? return 200 * 1000;
+ ? ? ? }
+
+ ? ? ? pr_err("cpufreq: Failed to get frequency: %X\n", pllclk);

Though %X is right, but ,is lowercase more unanimous?

Quoted 55 lines
arch/arm/mach-w90x900/cpufreq.c new file +55 -0
+ ? ? ? return 0;
+}
+
+static int nuc900_cpufreq_set_target(struct cpufreq_policy *policy,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned int target_freq,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned int relation)
+{
+ ? ? ? int ret;
+ ? ? ? unsigned int i;
+ ? ? ? struct cpufreq_freqs freqs;
+
+ ? ? ? ret = cpufreq_frequency_table_target(policy, nuc900_freq_table,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?target_freq, relation, &i);
+ ? ? ? if (ret != 0)
+ ? ? ? ? ? ? ? return ret;
+
+ ? ? ? freqs.cpu = 0;
+ ? ? ? freqs.old = nuc900_cpufreq_get_speed(0);
+ ? ? ? freqs.new = nuc900_freq_table[i].frequency;
+ ? ? ? freqs.flags = 0;
+
+ ? ? ? if (freqs.old == freqs.new)
+ ? ? ? ? ? ? ? return 0;
+
+ ? ? ? pr_debug("cpufreq: Transition %d-%dkHz\n", freqs.old, freqs.new);
+
+ ? ? ? cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+
+ ? ? ? nuc900_set_clkval(freqs.new / 1000);
+ ? ? ? cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+
+ ? ? ? return 0;
+}
+
+static int __init nuc900_cpufreq_driver_init(struct cpufreq_policy *policy)
+{
+ ? ? ? int ret;
+
+ ? ? ? if (policy->cpu != 0)
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? policy->cur = nuc900_cpufreq_get_speed(0);
+
+ ? ? ? policy->cpuinfo.transition_latency = 2 * 1000; /* FIXME, assumed */
+ ? ? ? policy->cpuinfo.min_freq = 66000; ? ? ? ? ? ? ?/* khz */
+ ? ? ? policy->cpuinfo.max_freq = 200000;
+ ? ? ? policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
+
+ ? ? ? ret = cpufreq_frequency_table_cpuinfo(policy, nuc900_freq_table);
+ ? ? ? if (ret != 0)
+ ? ? ? ? ? ? ? pr_err("cpufreq: Failed to configure frequency table: %d\n",
+ ? ? ? ? ? ? ? ? ? ? ?ret);
+
+ ? ? ? return ret;
+}

arch/arm/mach-w90x900/cpufreq.c line 129

Quoted 10 lines
arch/arm/mach-w90x900/cpufreq.c new file +10 -0
+
+static struct cpufreq_driver nuc900_cpufreq_driver = {
+ ? ? ? .owner ? ? ? ? ?= THIS_MODULE,
+ ? ? ? .flags ? ? ? ? ?= 0,
+ ? ? ? .verify ? ? ? ? = nuc900_cpufreq_verify_speed,
+ ? ? ? .target ? ? ? ? = nuc900_cpufreq_set_target,
+ ? ? ? .get ? ? ? ? ? ?= nuc900_cpufreq_get_speed,
+ ? ? ? .init ? ? ? ? ? = nuc900_cpufreq_driver_init,
+ ? ? ? .name ? ? ? ? ? = "nuc900",
+};

Don't name this cpufreq driver 'nuc900'.

Quoted 17 lines
arch/arm/mach-w90x900/cpufreq.c new file +16 -1
+static int __init nuc900_cpufreq_init(void)
+{
+ ? ? ? return cpufreq_register_driver(&nuc900_cpufreq_driver);
+}
+
+static void __exit nuc900_cpufreq_exit(void)
+{
+ ? ? ? cpufreq_unregister_driver(&nuc900_cpufreq_driver);
+}
+
+MODULE_AUTHOR ("Li Jie <[email protected]>");
+MODULE_DESCRIPTION ("cpufreq driver for NUC900");
+MODULE_LICENSE ("GPL");
+
+module_init(nuc900_cpufreq_init);
+module_exit(nuc900_cpufreq_exit);
--
Quoted 2 lines

1.6.5.4

--
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Signature · 2 lines
Regards
Li Jie
#3 lore raw

PATCH 1/1 ARM: NUC900: Add cpufreq driver for nuc900 CPUs

In reply to Li Jie

arch/arm/mach-w90x900/cpufreq.c line 19

Quoted 8 lines · Li Jie
arch/arm/mach-w90x900/cpufreq.c new file +8 -0
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include <asm/io.h>

I'm still on my crusade against this. linux/io.h please.

author
#4 lore raw

PATCH 1/1 ARM: NUC900: Add cpufreq driver for nuc900 CPUs

Quoted 12 lines · Russell King - ARM Linux

arch/arm/mach-w90x900/cpufreq.c line 19

Quoted 8 lines · Li Jie
arch/arm/mach-w90x900/cpufreq.c new file +8 -0
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include <asm/io.h>

I'm still on my crusade against this. ?linux/io.h please.

OK, thank you for the comment.

Signature · 2 lines
Regards
Li Jie
author
#5 lore raw

PATCH v2 1/1 ARM: NUC900: Add cpufreq driver for nuc900 CPUs

Hi, Wan:

This this the cpufreq_driver for NUC900 v2.
Problems which you and Russell mentioned in v1 have been fixed:

1. declare nuc900_set_clkval() in cpu.h
2. use macros instead of numbers
3. rename module, nuc900 -> nuc900-cpufreq
4. include linux/io.h, not asm/io.h
....and so on

arch/arm/Kconfig +1 -0
index 233a222..600b313 100644
@@ -539,6 +539,7 @@ config ARCH_W90X900
 	select COMMON_CLKDEV
 	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
+	select ARCH_HAS_CPUFREQ
 	help
 	  Support for Nuvoton (Winbond logic dept.) ARM9 processor,
 	  At present, the w90x900 has been renamed nuc900, regarding
arch/arm/mach-w90x900/Makefile +1 -1
index 828c032..7f114fb 100644
@@ -5,7 +5,7 @@
 # Object file lists.
 
 obj-y				:= irq.o time.o mfp.o gpio.o clock.o
-obj-y				+= clksel.o dev.o cpu.o
+obj-y				+= clksel.o dev.o cpu.o cpufreq.o
 # W90X900 CPU support files
 
 obj-$(CONFIG_CPU_W90P910)	+= nuc910.o
arch/arm/mach-w90x900/cpu.c +3 -1
index 921cef9..7b608b8 100644
@@ -107,7 +107,7 @@ struct platform_device nuc900_serial_device = {
 };
 
 /*Set NUC900 series cpu frequence*/
-static int __init nuc900_set_clkval(unsigned int cpufreq)
+int nuc900_set_clkval(unsigned int cpufreq)
 {
 	unsigned int pllclk, ahbclk, apbclk, val;
 
@@ -156,6 +156,8 @@ static int __init nuc900_set_clkval(unsigned int cpufreq)
 
 	return 	0;
 }
+EXPORT_SYMBOL(nuc900_set_clkval);
+
 static int __init nuc900_set_cpufreq(char *str)
 {
 	unsigned long cpufreq, val;
arch/arm/mach-w90x900/cpu.h +0 -0
index 4d58ba1..ca0bce5 100644
@@ -49,6 +49,7 @@ extern void nuc900_clock_source(struct device *dev,

unsigned char *src);
extern void nuc900_init_clocks(void);
extern void nuc900_map_io(struct map_desc *mach_desc, int mach_size); extern void nuc900_board_init(struct platform_device **device, int size);
+extern int nuc900_set_clkval(unsigned int cpufreq);

/* for either public between 910 and 920, or between 920 and 950 */

arch/arm/mach-w90x900/cpufreq.c new file +154 -0

154 lines not on this page · raw message

arch/arm/mach-w90x900/dev.c +1 -1
index 51f17b7..ec711f4 100644
@@ -197,7 +197,7 @@ static struct platform_device nuc900_device_emc = {
 
 /* SPI device */
 
-static struct w90p910_spi_info nuc900_spiflash_data = {
+static struct nuc900_spi_info nuc900_spiflash_data = {
 	.num_cs		= 1,
 	.lsb		= 0,
 	.txneg		= 1,
Signature · 2 lines
Regards
Li Jie
author
#6 lore raw

PATCH v2 1/1 ARM: NUC900: Add cpufreq driver for nuc900 CPUs

Quoted 241 lines · Li Jie

Hi, Wan:

This this the cpufreq_driver for NUC900 v2.
Problems which you and Russell mentioned in v1 have been fixed:

1. declare nuc900_set_clkval() in cpu.h
2. use macros instead of numbers
3. rename module, nuc900 -> nuc900-cpufreq
4. include linux/io.h, not asm/io.h
....and so on

arch/arm/Kconfig +0 -0
index 233a222..600b313 100644
@@ -539,6 +539,7 @@ config ARCH_W90X900

? ? ? ?select COMMON_CLKDEV
? ? ? ?select GENERIC_TIME
? ? ? ?select GENERIC_CLOCKEVENTS
+ ? ? ? select ARCH_HAS_CPUFREQ
? ? ? ?help
? ? ? ? ?Support for Nuvoton (Winbond logic dept.) ARM9 processor, ? ? ? ? ?At present, the w90x900 has been renamed nuc900, regarding

arch/arm/mach-w90x900/Makefile +0 -0
index 828c032..7f114fb 100644
@@ -5,7 +5,7 @@

?# Object file lists.

?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?:= irq.o time.o mfp.o gpio.o clock.o

arch/arm/mach-w90x900/Makefile +1 -1
-obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= clksel.o dev.o cpu.o
+obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= clksel.o dev.o cpu.o cpufreq.o

?# W90X900 CPU support files

?obj-$(CONFIG_CPU_W90P910) ? ? ?+= nuc910.o

arch/arm/mach-w90x900/cpu.c +0 -0
index 921cef9..7b608b8 100644
@@ -107,7 +107,7 @@ struct platform_device nuc900_serial_device = {
 ?};
 

?/*Set NUC900 series cpu frequence*/

arch/arm/mach-w90x900/cpu.c +1 -1
-static int __init nuc900_set_clkval(unsigned int cpufreq)
+int nuc900_set_clkval(unsigned int cpufreq)

?{
? ? ? ?unsigned int pllclk, ahbclk, apbclk, val;

arch/arm/mach-w90x900/cpu.c +2 -0
@@ -156,6 +156,8 @@ static int __init nuc900_set_clkval(unsigned int cpufreq)
 
 ? ? ? ?return ?0;
 ?}
+EXPORT_SYMBOL(nuc900_set_clkval);
+
 ?static int __init nuc900_set_cpufreq(char *str)
 ?{
 ? ? ? ?unsigned long cpufreq, val;
arch/arm/mach-w90x900/cpu.h +1 -0
index 4d58ba1..ca0bce5 100644
@@ -49,6 +49,7 @@ extern void nuc900_clock_source(struct device *dev,
 unsigned char *src);
 ?extern void nuc900_init_clocks(void);
 ?extern void nuc900_map_io(struct map_desc *mach_desc, int mach_size);
 ?extern void nuc900_board_init(struct platform_device **device, int size);
+extern int nuc900_set_clkval(unsigned int cpufreq);
 

?/* for either public between 910 and 920, or between 920 and 950 */

arch/arm/mach-w90x900/cpufreq.c new file +154 -0
new file mode 100644
index 0000000..467fc26
@@ -0,0 +1,154 @@
+/* linux/arch/arm/mach-w90x900/cpufreq.c
+ *
+ * NUC900 CPUfreq Support
+ *
+ * Li Jie <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+
+#include <asm/mach/map.h>
+#include <mach/hardware.h>
+#include <mach/regs-clock.h>
+
+#include "cpu.h"
+
+#define ? ? ? ?CPUFREQ_66M ? ? 66000
+#define ? ? ? ?CPUFREQ_100M ? ?100000
+#define ? ? ? ?CPUFREQ_120M ? ?120000
+#define ? ? ? ?CPUFREQ_166M ? ?166000
+#define ? ? ? ?CPUFREQ_200M ? ?200000
+
+static struct cpufreq_frequency_table nuc900_freq_table[] = {
+ ? ? ? { 0, CPUFREQ_66M ?},
+ ? ? ? { 1, CPUFREQ_100M },
+ ? ? ? { 2, CPUFREQ_120M },
+ ? ? ? { 3, CPUFREQ_166M },
+ ? ? ? { 4, CPUFREQ_200M },
+ ? ? ? { 5, CPUFREQ_TABLE_END },
+};
+
+static int nuc900_cpufreq_verify_speed(struct cpufreq_policy *policy)
+{
+ ? ? ? if (policy->cpu != 0)
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? return cpufreq_frequency_table_verify(policy, nuc900_freq_table);
+}
+
+static unsigned int nuc900_cpufreq_get_speed(unsigned int cpu)
+{
+ ? ? ? int pllclk;
+
+ ? ? ? if (cpu != 0)
+ ? ? ? ? ? ? ? return 0;
+
+ ? ? ? pllclk = __raw_readl(REG_PLLCON0);
+
+ ? ? ? switch (pllclk) {
+ ? ? ? case PLL_66MHZ:
+ ? ? ? ? ? ? ? return CPUFREQ_66M;
+ ? ? ? case PLL_100MHZ:
+ ? ? ? ? ? ? ? return CPUFREQ_100M;
+ ? ? ? case PLL_120MHZ:
+ ? ? ? ? ? ? ? return CPUFREQ_120M;
+ ? ? ? case PLL_166MHZ:
+ ? ? ? ? ? ? ? return CPUFREQ_166M;
+ ? ? ? case PLL_200MHZ:
+ ? ? ? ? ? ? ? return CPUFREQ_200M;
+ ? ? ? }
+
+ ? ? ? pr_err("cpufreq: Failed to get frequency: %x\n", pllclk);
+ ? ? ? return 0;
+}
+
+static int nuc900_cpufreq_set_target(struct cpufreq_policy *policy,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned int target_freq,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned int relation)
+{
+ ? ? ? int ret;
+ ? ? ? unsigned int i;
+ ? ? ? struct cpufreq_freqs freqs;
+
+ ? ? ? ret = cpufreq_frequency_table_target(policy, nuc900_freq_table,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?target_freq, relation, &i);
+ ? ? ? if (ret != 0)
+ ? ? ? ? ? ? ? return ret;
+
+ ? ? ? freqs.cpu = 0;
+ ? ? ? freqs.old = nuc900_cpufreq_get_speed(0);
+ ? ? ? freqs.new = nuc900_freq_table[i].frequency;
+ ? ? ? freqs.flags = 0;
+
+ ? ? ? if (freqs.old == freqs.new)
+ ? ? ? ? ? ? ? return 0;
+
+ ? ? ? pr_debug("cpufreq: Transition %d-%dkHz\n", freqs.old, freqs.new);
+
+ ? ? ? cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
+
+ ? ? ? nuc900_set_clkval(freqs.new / 1000);
+ ? ? ? cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
+
+ ? ? ? return 0;
+}
+
+static int __init nuc900_cpufreq_driver_init(struct cpufreq_policy *policy)
+{
+ ? ? ? int ret;
+
+ ? ? ? if (policy->cpu != 0)
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? policy->cur = nuc900_cpufreq_get_speed(0);
+
+ ? ? ? policy->cpuinfo.transition_latency = 2 * 1000; /* FIXME, assumed */
+ ? ? ? policy->cpuinfo.min_freq = 66000; ? ? ? ? ? ? ?/* khz */
+ ? ? ? policy->cpuinfo.max_freq = 200000;
+ ? ? ? policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
+
+ ? ? ? ret = cpufreq_frequency_table_cpuinfo(policy, nuc900_freq_table);
+ ? ? ? if (ret != 0)
+ ? ? ? ? ? ? ? pr_err("cpufreq: Failed to configure frequency table: %d\n",
+ ? ? ? ? ? ? ? ? ? ? ?ret);
+
+ ? ? ? return ret;
+}
+
+static struct cpufreq_driver nuc900_cpufreq_driver = {
+ ? ? ? .owner ? ? ? ? ?= THIS_MODULE,
+ ? ? ? .flags ? ? ? ? ?= 0,
+ ? ? ? .verify ? ? ? ? = nuc900_cpufreq_verify_speed,
+ ? ? ? .target ? ? ? ? = nuc900_cpufreq_set_target,
+ ? ? ? .get ? ? ? ? ? ?= nuc900_cpufreq_get_speed,
+ ? ? ? .init ? ? ? ? ? = nuc900_cpufreq_driver_init,
+ ? ? ? .name ? ? ? ? ? = "nuc900-cpufreq",
+};
+
+static int __init nuc900_cpufreq_init(void)
+{
+ ? ? ? return cpufreq_register_driver(&nuc900_cpufreq_driver);
+}
+
+static void __exit nuc900_cpufreq_exit(void)
+{
+ ? ? ? cpufreq_unregister_driver(&nuc900_cpufreq_driver);
+}
+
+MODULE_AUTHOR ("Li Jie <[email protected]>");
+MODULE_DESCRIPTION ("cpufreq driver for NUC900");
+MODULE_LICENSE ("GPL");
+
+module_init(nuc900_cpufreq_init);
+module_exit(nuc900_cpufreq_exit);
arch/arm/mach-w90x900/dev.c +0 -0
index 51f17b7..ec711f4 100644
@@ -197,7 +197,7 @@ static struct platform_device nuc900_device_emc = {
 

?/* SPI device */

arch/arm/mach-w90x900/dev.c +1 -1
-static struct w90p910_spi_info nuc900_spiflash_data = {
+static struct nuc900_spi_info nuc900_spiflash_data = {
Quoted 3 lines

? ? ? ?.num_cs ? ? ? ? = 1,
? ? ? ?.lsb ? ? ? ? ? ?= 0,
? ? ? ?.txneg ? ? ? ? ?= 1,

This diff shouldn't be included in this patch, sorry for my mistake. I'll resend, please ignore this one.

Quoted 6 lines

--
Regards
Li Jie

Signature · 2 lines
Regards
Li Jie