diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-04-30 18:21:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-04-30 18:21:02 -0400 |
commit | 3ed1c478eff8db80e234d5446cb378b503135888 (patch) | |
tree | e1c8e0f488ca49c49b5a31fe59add4254381dd4b /drivers/cpufreq/at32ap-cpufreq.c | |
parent | 151173e8ce9b95bbbbd7eedb9035cfaffbdb7cb2 (diff) | |
parent | 371deb9500831ad1afbf9ea00e373f650deaed2f (diff) |
Merge tag 'pm+acpi-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull power management and ACPI updates from Rafael J Wysocki:
- ARM big.LITTLE cpufreq driver from Viresh Kumar.
- exynos5440 cpufreq driver from Amit Daniel Kachhap.
- cpufreq core cleanup and code consolidation from Viresh Kumar and
Stratos Karafotis.
- cpufreq scalability improvement from Nathan Zimmer.
- AMD "frequency sensitivity feedback" powersave bias for the ondemand
cpufreq governor from Jacob Shin.
- cpuidle code consolidation and cleanups from Daniel Lezcano.
- ARM OMAP cpuidle fixes from Santosh Shilimkar and Daniel Lezcano.
- ACPICA fixes and other improvements from Bob Moore, Jung-uk Kim, Lv
Zheng, Yinghai Lu, Tang Chen, Colin Ian King, and Linn Crosetto.
- ACPI core updates related to hotplug from Toshi Kani, Paul Bolle,
Yasuaki Ishimatsu, and Rafael J Wysocki.
- Intel Lynxpoint LPSS (Low-Power Subsystem) support improvements from
Rafael J Wysocki and Andy Shevchenko.
* tag 'pm+acpi-3.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (192 commits)
cpufreq: Revert incorrect commit 5800043
cpufreq: MAINTAINERS: Add co-maintainer
cpuidle: add maintainer entry
ACPI / thermal: do not always return THERMAL_TREND_RAISING for active trip points
ARM: s3c64xx: cpuidle: use init/exit common routine
cpufreq: pxa2xx: initialize variables
ACPI: video: correct acpi_video_bus_add error processing
SH: cpuidle: use init/exit common routine
ARM: S5pv210: compiling issue, ARM_S5PV210_CPUFREQ needs CONFIG_CPU_FREQ_TABLE=y
ACPI: Fix wrong parameter passed to memblock_reserve
cpuidle: fix comment format
pnp: use %*phC to dump small buffers
isapnp: remove debug leftovers
ARM: imx: cpuidle: use init/exit common routine
ARM: davinci: cpuidle: use init/exit common routine
ARM: kirkwood: cpuidle: use init/exit common routine
ARM: calxeda: cpuidle: use init/exit common routine
ARM: tegra: cpuidle: use init/exit common routine for tegra3
ARM: tegra: cpuidle: use init/exit common routine for tegra2
ARM: OMAP4: cpuidle: use init/exit common routine
...
Diffstat (limited to 'drivers/cpufreq/at32ap-cpufreq.c')
-rw-r--r-- | drivers/cpufreq/at32ap-cpufreq.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/drivers/cpufreq/at32ap-cpufreq.c b/drivers/cpufreq/at32ap-cpufreq.c new file mode 100644 index 000000000000..654488723cb5 --- /dev/null +++ b/drivers/cpufreq/at32ap-cpufreq.c | |||
@@ -0,0 +1,123 @@ | |||
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); | ||