Commit 81c720c90e6fbda5a1f53f932035de899f27adb6

Authored by Viresh Kumar
Committed by Rafael J. Wysocki
1 parent 59a2e613d0

cpufreq: AVR32: move cpufreq driver to drivers/cpufreq

This patch moves cpufreq driver of AVR32 based at32ap platform to
drivers/cpufreq.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Showing 20 changed files with 154 additions and 151 deletions Side-by-side Diff

... ... @@ -250,20 +250,7 @@
250 250 def_bool y
251 251  
252 252 menu "CPU Frequency scaling"
253   -
254 253 source "drivers/cpufreq/Kconfig"
255   -
256   -config CPU_FREQ_AT32AP
257   - bool "CPU frequency driver for AT32AP"
258   - depends on CPU_FREQ && PLATFORM_AT32AP
259   - default n
260   - help
261   - This enables the CPU frequency driver for AT32AP processors.
262   -
263   - For details, take a look in <file:Documentation/cpu-freq>.
264   -
265   - If in doubt, say N.
266   -
267 254 endmenu
268 255  
269 256 endmenu
arch/avr32/configs/atngw100_defconfig
... ... @@ -26,7 +26,7 @@
26 26 # CONFIG_CPU_FREQ_STAT is not set
27 27 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
28 28 CONFIG_CPU_FREQ_GOV_USERSPACE=y
29   -CONFIG_CPU_FREQ_AT32AP=y
  29 +CONFIG_AVR32_AT32AP_CPUFREQ=y
30 30 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
31 31 CONFIG_NET=y
32 32 CONFIG_PACKET=y
arch/avr32/configs/atngw100_evklcd100_defconfig
... ... @@ -28,7 +28,7 @@
28 28 # CONFIG_CPU_FREQ_STAT is not set
29 29 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
30 30 CONFIG_CPU_FREQ_GOV_USERSPACE=y
31   -CONFIG_CPU_FREQ_AT32AP=y
  31 +CONFIG_AVR32_AT32AP_CPUFREQ=y
32 32 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
33 33 CONFIG_NET=y
34 34 CONFIG_PACKET=y
arch/avr32/configs/atngw100_evklcd101_defconfig
... ... @@ -27,7 +27,7 @@
27 27 # CONFIG_CPU_FREQ_STAT is not set
28 28 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
29 29 CONFIG_CPU_FREQ_GOV_USERSPACE=y
30   -CONFIG_CPU_FREQ_AT32AP=y
  30 +CONFIG_AVR32_AT32AP_CPUFREQ=y
31 31 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
32 32 CONFIG_NET=y
33 33 CONFIG_PACKET=y
arch/avr32/configs/atngw100_mrmt_defconfig
... ... @@ -23,7 +23,7 @@
23 23 CONFIG_CPU_FREQ_GOV_POWERSAVE=y
24 24 CONFIG_CPU_FREQ_GOV_USERSPACE=y
25 25 CONFIG_CPU_FREQ_GOV_ONDEMAND=y
26   -CONFIG_CPU_FREQ_AT32AP=y
  26 +CONFIG_AVR32_AT32AP_CPUFREQ=y
27 27 CONFIG_NET=y
28 28 CONFIG_PACKET=y
29 29 CONFIG_UNIX=y
arch/avr32/configs/atngw100mkii_defconfig
... ... @@ -26,7 +26,7 @@
26 26 # CONFIG_CPU_FREQ_STAT is not set
27 27 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
28 28 CONFIG_CPU_FREQ_GOV_USERSPACE=y
29   -CONFIG_CPU_FREQ_AT32AP=y
  29 +CONFIG_AVR32_AT32AP_CPUFREQ=y
30 30 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
31 31 CONFIG_NET=y
32 32 CONFIG_PACKET=y
arch/avr32/configs/atngw100mkii_evklcd100_defconfig
... ... @@ -29,7 +29,7 @@
29 29 # CONFIG_CPU_FREQ_STAT is not set
30 30 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
31 31 CONFIG_CPU_FREQ_GOV_USERSPACE=y
32   -CONFIG_CPU_FREQ_AT32AP=y
  32 +CONFIG_AVR32_AT32AP_CPUFREQ=y
33 33 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
34 34 CONFIG_NET=y
35 35 CONFIG_PACKET=y
arch/avr32/configs/atngw100mkii_evklcd101_defconfig
... ... @@ -28,7 +28,7 @@
28 28 # CONFIG_CPU_FREQ_STAT is not set
29 29 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
30 30 CONFIG_CPU_FREQ_GOV_USERSPACE=y
31   -CONFIG_CPU_FREQ_AT32AP=y
  31 +CONFIG_AVR32_AT32AP_CPUFREQ=y
32 32 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
33 33 CONFIG_NET=y
34 34 CONFIG_PACKET=y
arch/avr32/configs/atstk1002_defconfig
... ... @@ -25,7 +25,7 @@
25 25 # CONFIG_CPU_FREQ_STAT is not set
26 26 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
27 27 CONFIG_CPU_FREQ_GOV_USERSPACE=y
28   -CONFIG_CPU_FREQ_AT32AP=y
  28 +CONFIG_AVR32_AT32AP_CPUFREQ=y
29 29 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
30 30 CONFIG_NET=y
31 31 CONFIG_PACKET=y
arch/avr32/configs/atstk1003_defconfig
... ... @@ -26,7 +26,7 @@
26 26 # CONFIG_CPU_FREQ_STAT is not set
27 27 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
28 28 CONFIG_CPU_FREQ_GOV_USERSPACE=y
29   -CONFIG_CPU_FREQ_AT32AP=y
  29 +CONFIG_AVR32_AT32AP_CPUFREQ=y
30 30 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
31 31 CONFIG_NET=y
32 32 CONFIG_PACKET=y
arch/avr32/configs/atstk1004_defconfig
... ... @@ -26,7 +26,7 @@
26 26 # CONFIG_CPU_FREQ_STAT is not set
27 27 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
28 28 CONFIG_CPU_FREQ_GOV_USERSPACE=y
29   -CONFIG_CPU_FREQ_AT32AP=y
  29 +CONFIG_AVR32_AT32AP_CPUFREQ=y
30 30 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
31 31 CONFIG_NET=y
32 32 CONFIG_PACKET=y
arch/avr32/configs/atstk1006_defconfig
... ... @@ -26,7 +26,7 @@
26 26 # CONFIG_CPU_FREQ_STAT is not set
27 27 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
28 28 CONFIG_CPU_FREQ_GOV_USERSPACE=y
29   -CONFIG_CPU_FREQ_AT32AP=y
  29 +CONFIG_AVR32_AT32AP_CPUFREQ=y
30 30 CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
31 31 CONFIG_NET=y
32 32 CONFIG_PACKET=y
arch/avr32/configs/favr-32_defconfig
... ... @@ -27,7 +27,7 @@
27 27 # CONFIG_CPU_FREQ_STAT is not set
28 28 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
29 29 CONFIG_CPU_FREQ_GOV_USERSPACE=y
30   -CONFIG_CPU_FREQ_AT32AP=y
  30 +CONFIG_AVR32_AT32AP_CPUFREQ=y
31 31 CONFIG_NET=y
32 32 CONFIG_PACKET=y
33 33 CONFIG_UNIX=y
arch/avr32/configs/hammerhead_defconfig
... ... @@ -31,7 +31,7 @@
31 31 # CONFIG_CPU_FREQ_STAT is not set
32 32 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
33 33 CONFIG_CPU_FREQ_GOV_USERSPACE=y
34   -CONFIG_CPU_FREQ_AT32AP=y
  34 +CONFIG_AVR32_AT32AP_CPUFREQ=y
35 35 CONFIG_NET=y
36 36 CONFIG_PACKET=y
37 37 CONFIG_UNIX=y
arch/avr32/configs/mimc200_defconfig
... ... @@ -24,7 +24,7 @@
24 24 # CONFIG_CPU_FREQ_STAT is not set
25 25 CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
26 26 CONFIG_CPU_FREQ_GOV_USERSPACE=y
27   -CONFIG_CPU_FREQ_AT32AP=y
  27 +CONFIG_AVR32_AT32AP_CPUFREQ=y
28 28 CONFIG_NET=y
29 29 CONFIG_PACKET=y
30 30 CONFIG_UNIX=y
arch/avr32/mach-at32ap/Makefile
1 1 obj-y += pdc.o clock.o intc.o extint.o pio.o hsmc.o
2 2 obj-y += hmatrix.o
3 3 obj-$(CONFIG_CPU_AT32AP700X) += at32ap700x.o pm-at32ap700x.o
4   -obj-$(CONFIG_CPU_FREQ_AT32AP) += cpufreq.o
5 4 obj-$(CONFIG_PM) += pm.o
6 5  
7 6 ifeq ($(CONFIG_PM_DEBUG),y)
arch/avr32/mach-at32ap/cpufreq.c
1   -/*
2   - * Copyright (C) 2004-2007 Atmel Corporation
3   - *
4   - * Based on MIPS implementation arch/mips/kernel/time.c
5   - * Copyright 2001 MontaVista Software Inc.
6   - *
7   - * This program is free software; you can redistribute it and/or modify
8   - * it under the terms of the GNU General Public License version 2 as
9   - * published by the Free Software Foundation.
10   - */
11   -
12   -/*#define DEBUG*/
13   -
14   -#include <linux/kernel.h>
15   -#include <linux/types.h>
16   -#include <linux/init.h>
17   -#include <linux/cpufreq.h>
18   -#include <linux/io.h>
19   -#include <linux/clk.h>
20   -#include <linux/err.h>
21   -#include <linux/export.h>
22   -
23   -static struct clk *cpuclk;
24   -
25   -static int at32_verify_speed(struct cpufreq_policy *policy)
26   -{
27   - if (policy->cpu != 0)
28   - return -EINVAL;
29   -
30   - cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
31   - policy->cpuinfo.max_freq);
32   - return 0;
33   -}
34   -
35   -static unsigned int at32_get_speed(unsigned int cpu)
36   -{
37   - /* No SMP support */
38   - if (cpu)
39   - return 0;
40   - return (unsigned int)((clk_get_rate(cpuclk) + 500) / 1000);
41   -}
42   -
43   -static unsigned int ref_freq;
44   -static unsigned long loops_per_jiffy_ref;
45   -
46   -static int at32_set_target(struct cpufreq_policy *policy,
47   - unsigned int target_freq,
48   - unsigned int relation)
49   -{
50   - struct cpufreq_freqs freqs;
51   - long freq;
52   -
53   - /* Convert target_freq from kHz to Hz */
54   - freq = clk_round_rate(cpuclk, target_freq * 1000);
55   -
56   - /* Check if policy->min <= new_freq <= policy->max */
57   - if(freq < (policy->min * 1000) || freq > (policy->max * 1000))
58   - return -EINVAL;
59   -
60   - pr_debug("cpufreq: requested frequency %u Hz\n", target_freq * 1000);
61   -
62   - freqs.old = at32_get_speed(0);
63   - freqs.new = (freq + 500) / 1000;
64   - freqs.flags = 0;
65   -
66   - if (!ref_freq) {
67   - ref_freq = freqs.old;
68   - loops_per_jiffy_ref = boot_cpu_data.loops_per_jiffy;
69   - }
70   -
71   - cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
72   - if (freqs.old < freqs.new)
73   - boot_cpu_data.loops_per_jiffy = cpufreq_scale(
74   - loops_per_jiffy_ref, ref_freq, freqs.new);
75   - clk_set_rate(cpuclk, freq);
76   - if (freqs.new < freqs.old)
77   - boot_cpu_data.loops_per_jiffy = cpufreq_scale(
78   - loops_per_jiffy_ref, ref_freq, freqs.new);
79   - cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
80   -
81   - pr_debug("cpufreq: set frequency %lu Hz\n", freq);
82   -
83   - return 0;
84   -}
85   -
86   -static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
87   -{
88   - if (policy->cpu != 0)
89   - return -EINVAL;
90   -
91   - cpuclk = clk_get(NULL, "cpu");
92   - if (IS_ERR(cpuclk)) {
93   - pr_debug("cpufreq: could not get CPU clk\n");
94   - return PTR_ERR(cpuclk);
95   - }
96   -
97   - policy->cpuinfo.min_freq = (clk_round_rate(cpuclk, 1) + 500) / 1000;
98   - policy->cpuinfo.max_freq = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
99   - policy->cpuinfo.transition_latency = 0;
100   - policy->cur = at32_get_speed(0);
101   - policy->min = policy->cpuinfo.min_freq;
102   - policy->max = policy->cpuinfo.max_freq;
103   -
104   - printk("cpufreq: AT32AP CPU frequency driver\n");
105   -
106   - return 0;
107   -}
108   -
109   -static struct cpufreq_driver at32_driver = {
110   - .name = "at32ap",
111   - .owner = THIS_MODULE,
112   - .init = at32_cpufreq_driver_init,
113   - .verify = at32_verify_speed,
114   - .target = at32_set_target,
115   - .get = at32_get_speed,
116   - .flags = CPUFREQ_STICKY,
117   -};
118   -
119   -static int __init at32_cpufreq_init(void)
120   -{
121   - return cpufreq_register_driver(&at32_driver);
122   -}
123   -late_initcall(at32_cpufreq_init);
drivers/cpufreq/Kconfig
... ... @@ -205,6 +205,19 @@
205 205 source "drivers/cpufreq/Kconfig.arm"
206 206 endmenu
207 207  
  208 +menu "AVR32 CPU frequency scaling drivers"
  209 +depends on AVR32
  210 +
  211 +config AVR32_AT32AP_CPUFREQ
  212 + bool "CPU frequency driver for AT32AP"
  213 + depends on PLATFORM_AT32AP
  214 + default n
  215 + help
  216 + This enables the CPU frequency driver for AT32AP processors.
  217 + If in doubt, say N.
  218 +
  219 +endmenu
  220 +
208 221 menu "PowerPC CPU frequency scaling drivers"
209 222 depends on PPC32 || PPC64
210 223 source "drivers/cpufreq/Kconfig.powerpc"
drivers/cpufreq/Makefile
... ... @@ -74,4 +74,8 @@
74 74 ##################################################################################
75 75 # PowerPC platform drivers
76 76 obj-$(CONFIG_CPU_FREQ_MAPLE) += maple-cpufreq.o
  77 +
  78 +##################################################################################
  79 +# Other platform drivers
  80 +obj-$(CONFIG_AVR32_AT32AP_CPUFREQ) += at32ap-cpufreq.o
drivers/cpufreq/at32ap-cpufreq.c
  1 +/*
  2 + * Copyright (C) 2004-2007 Atmel Corporation
  3 + *
  4 + * Based on MIPS implementation arch/mips/kernel/time.c
  5 + * Copyright 2001 MontaVista Software Inc.
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License version 2 as
  9 + * published by the Free Software Foundation.
  10 + */
  11 +
  12 +/*#define DEBUG*/
  13 +
  14 +#include <linux/kernel.h>
  15 +#include <linux/types.h>
  16 +#include <linux/init.h>
  17 +#include <linux/cpufreq.h>
  18 +#include <linux/io.h>
  19 +#include <linux/clk.h>
  20 +#include <linux/err.h>
  21 +#include <linux/export.h>
  22 +
  23 +static struct clk *cpuclk;
  24 +
  25 +static int at32_verify_speed(struct cpufreq_policy *policy)
  26 +{
  27 + if (policy->cpu != 0)
  28 + return -EINVAL;
  29 +
  30 + cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
  31 + policy->cpuinfo.max_freq);
  32 + return 0;
  33 +}
  34 +
  35 +static unsigned int at32_get_speed(unsigned int cpu)
  36 +{
  37 + /* No SMP support */
  38 + if (cpu)
  39 + return 0;
  40 + return (unsigned int)((clk_get_rate(cpuclk) + 500) / 1000);
  41 +}
  42 +
  43 +static unsigned int ref_freq;
  44 +static unsigned long loops_per_jiffy_ref;
  45 +
  46 +static int at32_set_target(struct cpufreq_policy *policy,
  47 + unsigned int target_freq,
  48 + unsigned int relation)
  49 +{
  50 + struct cpufreq_freqs freqs;
  51 + long freq;
  52 +
  53 + /* Convert target_freq from kHz to Hz */
  54 + freq = clk_round_rate(cpuclk, target_freq * 1000);
  55 +
  56 + /* Check if policy->min <= new_freq <= policy->max */
  57 + if(freq < (policy->min * 1000) || freq > (policy->max * 1000))
  58 + return -EINVAL;
  59 +
  60 + pr_debug("cpufreq: requested frequency %u Hz\n", target_freq * 1000);
  61 +
  62 + freqs.old = at32_get_speed(0);
  63 + freqs.new = (freq + 500) / 1000;
  64 + freqs.flags = 0;
  65 +
  66 + if (!ref_freq) {
  67 + ref_freq = freqs.old;
  68 + loops_per_jiffy_ref = boot_cpu_data.loops_per_jiffy;
  69 + }
  70 +
  71 + cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
  72 + if (freqs.old < freqs.new)
  73 + boot_cpu_data.loops_per_jiffy = cpufreq_scale(
  74 + loops_per_jiffy_ref, ref_freq, freqs.new);
  75 + clk_set_rate(cpuclk, freq);
  76 + if (freqs.new < freqs.old)
  77 + boot_cpu_data.loops_per_jiffy = cpufreq_scale(
  78 + loops_per_jiffy_ref, ref_freq, freqs.new);
  79 + cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
  80 +
  81 + pr_debug("cpufreq: set frequency %lu Hz\n", freq);
  82 +
  83 + return 0;
  84 +}
  85 +
  86 +static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
  87 +{
  88 + if (policy->cpu != 0)
  89 + return -EINVAL;
  90 +
  91 + cpuclk = clk_get(NULL, "cpu");
  92 + if (IS_ERR(cpuclk)) {
  93 + pr_debug("cpufreq: could not get CPU clk\n");
  94 + return PTR_ERR(cpuclk);
  95 + }
  96 +
  97 + policy->cpuinfo.min_freq = (clk_round_rate(cpuclk, 1) + 500) / 1000;
  98 + policy->cpuinfo.max_freq = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
  99 + policy->cpuinfo.transition_latency = 0;
  100 + policy->cur = at32_get_speed(0);
  101 + policy->min = policy->cpuinfo.min_freq;
  102 + policy->max = policy->cpuinfo.max_freq;
  103 +
  104 + printk("cpufreq: AT32AP CPU frequency driver\n");
  105 +
  106 + return 0;
  107 +}
  108 +
  109 +static struct cpufreq_driver at32_driver = {
  110 + .name = "at32ap",
  111 + .owner = THIS_MODULE,
  112 + .init = at32_cpufreq_driver_init,
  113 + .verify = at32_verify_speed,
  114 + .target = at32_set_target,
  115 + .get = at32_get_speed,
  116 + .flags = CPUFREQ_STICKY,
  117 +};
  118 +
  119 +static int __init at32_cpufreq_init(void)
  120 +{
  121 + return cpufreq_register_driver(&at32_driver);
  122 +}
  123 +late_initcall(at32_cpufreq_init);