Commit | Line | Data |
---|---|---|
64909882 | 1 | /* |
73cc9c8c | 2 | * clock scaling for the UniCore-II |
64909882 G |
3 | * |
4 | * Code specific to PKUnity SoC and UniCore ISA | |
5 | * | |
6 | * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn> | |
7 | * Copyright (C) 2001-2010 Guan Xuetao | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
14 | #include <linux/kernel.h> | |
15 | #include <linux/types.h> | |
16 | #include <linux/init.h> | |
17 | #include <linux/clk.h> | |
18 | #include <linux/cpufreq.h> | |
19 | ||
20 | #include <mach/hardware.h> | |
21 | ||
22 | static struct cpufreq_driver ucv2_driver; | |
23 | ||
24 | /* make sure that only the "userspace" governor is run | |
25 | * -- anything else wouldn't make sense on this platform, anyway. | |
26 | */ | |
0e25246f | 27 | static int ucv2_verify_speed(struct cpufreq_policy *policy) |
64909882 G |
28 | { |
29 | if (policy->cpu) | |
30 | return -EINVAL; | |
31 | ||
be49e346 | 32 | cpufreq_verify_within_cpu_limits(policy); |
64909882 G |
33 | return 0; |
34 | } | |
35 | ||
36 | static unsigned int ucv2_getspeed(unsigned int cpu) | |
37 | { | |
38 | struct clk *mclk = clk_get(NULL, "MAIN_CLK"); | |
39 | ||
40 | if (cpu) | |
41 | return 0; | |
42 | return clk_get_rate(mclk)/1000; | |
43 | } | |
44 | ||
45 | static int ucv2_target(struct cpufreq_policy *policy, | |
46 | unsigned int target_freq, | |
47 | unsigned int relation) | |
48 | { | |
49 | unsigned int cur = ucv2_getspeed(0); | |
50 | struct cpufreq_freqs freqs; | |
51 | struct clk *mclk = clk_get(NULL, "MAIN_CLK"); | |
52 | ||
b43a7ffb | 53 | cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); |
64909882 G |
54 | |
55 | if (!clk_set_rate(mclk, target_freq * 1000)) { | |
56 | freqs.old = cur; | |
57 | freqs.new = target_freq; | |
64909882 G |
58 | } |
59 | ||
b43a7ffb | 60 | cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); |
64909882 G |
61 | |
62 | return 0; | |
63 | } | |
64 | ||
65 | static int __init ucv2_cpu_init(struct cpufreq_policy *policy) | |
66 | { | |
67 | if (policy->cpu != 0) | |
68 | return -EINVAL; | |
64909882 G |
69 | policy->min = policy->cpuinfo.min_freq = 250000; |
70 | policy->max = policy->cpuinfo.max_freq = 1000000; | |
71 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | |
72 | return 0; | |
73 | } | |
74 | ||
75 | static struct cpufreq_driver ucv2_driver = { | |
76 | .flags = CPUFREQ_STICKY, | |
77 | .verify = ucv2_verify_speed, | |
78 | .target = ucv2_target, | |
79 | .get = ucv2_getspeed, | |
80 | .init = ucv2_cpu_init, | |
81 | .name = "UniCore-II", | |
82 | }; | |
83 | ||
84 | static int __init ucv2_cpufreq_init(void) | |
85 | { | |
86 | return cpufreq_register_driver(&ucv2_driver); | |
87 | } | |
88 | ||
89 | arch_initcall(ucv2_cpufreq_init); |