blob: 36cc330b8747c70b3430175c6fec28891526688c [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
Viresh Kumar652ed952014-01-09 20:38:43 +053014#include <linux/err.h>
GuanXuetao64909882011-02-26 20:23:59 +080015#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
23static 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 */
Jingoo Han0e252462013-08-09 16:14:51 +090028static int ucv2_verify_speed(struct cpufreq_policy *policy)
GuanXuetao64909882011-02-26 20:23:59 +080029{
30 if (policy->cpu)
31 return -EINVAL;
32
Viresh Kumarbe49e342013-10-02 14:13:19 +053033 cpufreq_verify_within_cpu_limits(policy);
GuanXuetao64909882011-02-26 20:23:59 +080034 return 0;
35}
36
GuanXuetao64909882011-02-26 20:23:59 +080037static int ucv2_target(struct cpufreq_policy *policy,
38 unsigned int target_freq,
39 unsigned int relation)
40{
GuanXuetao64909882011-02-26 20:23:59 +080041 struct cpufreq_freqs freqs;
Viresh Kumarab1b1c42013-12-02 11:04:13 +053042 int ret;
43
44 freqs.old = policy->cur;
45 freqs.new = target_freq;
GuanXuetao64909882011-02-26 20:23:59 +080046
Viresh Kumarb43a7ff2013-03-24 11:56:43 +053047 cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
Viresh Kumar652ed952014-01-09 20:38:43 +053048 ret = clk_set_rate(policy->mclk, target_freq * 1000);
Viresh Kumarab1b1c42013-12-02 11:04:13 +053049 cpufreq_notify_post_transition(policy, &freqs, ret);
GuanXuetao64909882011-02-26 20:23:59 +080050
Viresh Kumarab1b1c42013-12-02 11:04:13 +053051 return ret;
GuanXuetao64909882011-02-26 20:23:59 +080052}
53
54static int __init ucv2_cpu_init(struct cpufreq_policy *policy)
55{
56 if (policy->cpu != 0)
57 return -EINVAL;
Viresh Kumar652ed952014-01-09 20:38:43 +053058
GuanXuetao64909882011-02-26 20:23:59 +080059 policy->min = policy->cpuinfo.min_freq = 250000;
60 policy->max = policy->cpuinfo.max_freq = 1000000;
61 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
Viresh Kumar652ed952014-01-09 20:38:43 +053062 policy->clk = clk_get(NULL, "MAIN_CLK");
63 if (IS_ERR(policy->clk))
64 return PTR_ERR(policy->clk);
GuanXuetao64909882011-02-26 20:23:59 +080065 return 0;
66}
67
68static struct cpufreq_driver ucv2_driver = {
69 .flags = CPUFREQ_STICKY,
70 .verify = ucv2_verify_speed,
71 .target = ucv2_target,
Viresh Kumar652ed952014-01-09 20:38:43 +053072 .get = cpufreq_generic_get,
GuanXuetao64909882011-02-26 20:23:59 +080073 .init = ucv2_cpu_init,
74 .name = "UniCore-II",
75};
76
77static int __init ucv2_cpufreq_init(void)
78{
79 return cpufreq_register_driver(&ucv2_driver);
80}
81
82arch_initcall(ucv2_cpufreq_init);