blob: 86f6cfec2e09fe7595379b6f64dba144a0a1c224 [file] [log] [blame]
GuanXuetao64909882011-02-26 20:23:59 +08001/*
Viresh Kumar73cc9c82013-04-04 12:54:23 +00002 * clock scaling for the UniCore-II
GuanXuetao64909882011-02-26 20:23:59 +08003 *
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
22static 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 */
Jingoo Han0e252462013-08-09 16:14:51 +090027static int ucv2_verify_speed(struct cpufreq_policy *policy)
GuanXuetao64909882011-02-26 20:23:59 +080028{
29 if (policy->cpu)
30 return -EINVAL;
31
Viresh Kumarbe49e342013-10-02 14:13:19 +053032 cpufreq_verify_within_cpu_limits(policy);
GuanXuetao64909882011-02-26 20:23:59 +080033 return 0;
34}
35
36static 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
45static int ucv2_target(struct cpufreq_policy *policy,
46 unsigned int target_freq,
47 unsigned int relation)
48{
GuanXuetao64909882011-02-26 20:23:59 +080049 struct cpufreq_freqs freqs;
50 struct clk *mclk = clk_get(NULL, "MAIN_CLK");
Viresh Kumarab1b1c42013-12-02 11:04:13 +053051 int ret;
52
53 freqs.old = policy->cur;
54 freqs.new = target_freq;
GuanXuetao64909882011-02-26 20:23:59 +080055
Viresh Kumarb43a7ff2013-03-24 11:56:43 +053056 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
Viresh Kumarab1b1c42013-12-02 11:04:13 +053057 ret = clk_set_rate(mclk, target_freq * 1000);
58 cpufreq_notify_post_transition(policy, &freqs, ret);
GuanXuetao64909882011-02-26 20:23:59 +080059
Viresh Kumarab1b1c42013-12-02 11:04:13 +053060 return ret;
GuanXuetao64909882011-02-26 20:23:59 +080061}
62
63static int __init ucv2_cpu_init(struct cpufreq_policy *policy)
64{
65 if (policy->cpu != 0)
66 return -EINVAL;
GuanXuetao64909882011-02-26 20:23:59 +080067 policy->min = policy->cpuinfo.min_freq = 250000;
68 policy->max = policy->cpuinfo.max_freq = 1000000;
69 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
70 return 0;
71}
72
73static struct cpufreq_driver ucv2_driver = {
74 .flags = CPUFREQ_STICKY,
75 .verify = ucv2_verify_speed,
76 .target = ucv2_target,
77 .get = ucv2_getspeed,
78 .init = ucv2_cpu_init,
79 .name = "UniCore-II",
80};
81
82static int __init ucv2_cpufreq_init(void)
83{
84 return cpufreq_register_driver(&ucv2_driver);
85}
86
87arch_initcall(ucv2_cpufreq_init);