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 | ||
652ed95d | 14 | #include <linux/err.h> |
64909882 G |
15 | #include <linux/kernel.h> |
16 | #include <linux/types.h> | |
17 | #include <linux/init.h> | |
18 | #include <linux/clk.h> | |
19 | #include <linux/cpufreq.h> | |
20 | ||
21 | #include <mach/hardware.h> | |
22 | ||
23 | static struct cpufreq_driver ucv2_driver; | |
24 | ||
25 | /* make sure that only the "userspace" governor is run | |
26 | * -- anything else wouldn't make sense on this platform, anyway. | |
27 | */ | |
0e25246f | 28 | static int ucv2_verify_speed(struct cpufreq_policy *policy) |
64909882 G |
29 | { |
30 | if (policy->cpu) | |
31 | return -EINVAL; | |
32 | ||
be49e346 | 33 | cpufreq_verify_within_cpu_limits(policy); |
64909882 G |
34 | return 0; |
35 | } | |
36 | ||
64909882 G |
37 | static int ucv2_target(struct cpufreq_policy *policy, |
38 | unsigned int target_freq, | |
39 | unsigned int relation) | |
40 | { | |
64909882 | 41 | struct cpufreq_freqs freqs; |
ab1b1c4e | 42 | int ret; |
64909882 | 43 | |
ab1b1c4e VK |
44 | freqs.old = policy->cur; |
45 | freqs.new = target_freq; | |
64909882 | 46 | |
8fec051e | 47 | cpufreq_freq_transition_begin(policy, &freqs); |
b4ddad95 | 48 | ret = clk_set_rate(policy->clk, target_freq * 1000); |
8fec051e | 49 | cpufreq_freq_transition_end(policy, &freqs, ret); |
64909882 | 50 | |
ab1b1c4e | 51 | return ret; |
64909882 G |
52 | } |
53 | ||
54 | static int __init ucv2_cpu_init(struct cpufreq_policy *policy) | |
55 | { | |
56 | if (policy->cpu != 0) | |
57 | return -EINVAL; | |
652ed95d | 58 | |
64909882 G |
59 | policy->min = policy->cpuinfo.min_freq = 250000; |
60 | policy->max = policy->cpuinfo.max_freq = 1000000; | |
61 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | |
652ed95d | 62 | policy->clk = clk_get(NULL, "MAIN_CLK"); |
8ab4e2b3 | 63 | return PTR_ERR_OR_ZERO(policy->clk); |
64909882 G |
64 | } |
65 | ||
66 | static struct cpufreq_driver ucv2_driver = { | |
67 | .flags = CPUFREQ_STICKY, | |
68 | .verify = ucv2_verify_speed, | |
69 | .target = ucv2_target, | |
652ed95d | 70 | .get = cpufreq_generic_get, |
64909882 G |
71 | .init = ucv2_cpu_init, |
72 | .name = "UniCore-II", | |
73 | }; | |
74 | ||
75 | static int __init ucv2_cpufreq_init(void) | |
76 | { | |
77 | return cpufreq_register_driver(&ucv2_driver); | |
78 | } | |
79 | ||
80 | arch_initcall(ucv2_cpufreq_init); |