Blame view

drivers/cpufreq/unicore2-cpufreq.c 1.9 KB
649098828   GuanXuetao   unicore32 additio...
1
  /*
73cc9c8ca   Viresh Kumar   cpufreq: unicore2...
2
   * clock scaling for the UniCore-II
649098828   GuanXuetao   unicore32 additio...
3
4
5
6
7
8
9
10
11
12
   *
   * Code specific to PKUnity SoC and UniCore ISA
   *
   *	Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
   *	Copyright (C) 2001-2010 Guan Xuetao
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
652ed95d5   Viresh Kumar   cpufreq: introduc...
13
  #include <linux/err.h>
649098828   GuanXuetao   unicore32 additio...
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <linux/kernel.h>
  #include <linux/types.h>
  #include <linux/init.h>
  #include <linux/clk.h>
  #include <linux/cpufreq.h>
  
  #include <mach/hardware.h>
  
  static struct cpufreq_driver ucv2_driver;
  
  /* make sure that only the "userspace" governor is run
   * -- anything else wouldn't make sense on this platform, anyway.
   */
0e25246fb   Jingoo Han   cpufreq: unicore2...
27
  static int ucv2_verify_speed(struct cpufreq_policy *policy)
649098828   GuanXuetao   unicore32 additio...
28
29
30
  {
  	if (policy->cpu)
  		return -EINVAL;
be49e3465   Viresh Kumar   cpufreq: add new ...
31
  	cpufreq_verify_within_cpu_limits(policy);
649098828   GuanXuetao   unicore32 additio...
32
33
  	return 0;
  }
649098828   GuanXuetao   unicore32 additio...
34
35
36
37
  static int ucv2_target(struct cpufreq_policy *policy,
  			 unsigned int target_freq,
  			 unsigned int relation)
  {
649098828   GuanXuetao   unicore32 additio...
38
  	struct cpufreq_freqs freqs;
ab1b1c4e8   Viresh Kumar   cpufreq: send new...
39
  	int ret;
649098828   GuanXuetao   unicore32 additio...
40

ab1b1c4e8   Viresh Kumar   cpufreq: send new...
41
42
  	freqs.old = policy->cur;
  	freqs.new = target_freq;
649098828   GuanXuetao   unicore32 additio...
43

8fec051ee   Viresh Kumar   cpufreq: Convert ...
44
  	cpufreq_freq_transition_begin(policy, &freqs);
b4ddad950   Chen Gang   cpufreq: unicore3...
45
  	ret = clk_set_rate(policy->clk, target_freq * 1000);
8fec051ee   Viresh Kumar   cpufreq: Convert ...
46
  	cpufreq_freq_transition_end(policy, &freqs, ret);
649098828   GuanXuetao   unicore32 additio...
47

ab1b1c4e8   Viresh Kumar   cpufreq: send new...
48
  	return ret;
649098828   GuanXuetao   unicore32 additio...
49
50
51
52
53
54
  }
  
  static int __init ucv2_cpu_init(struct cpufreq_policy *policy)
  {
  	if (policy->cpu != 0)
  		return -EINVAL;
652ed95d5   Viresh Kumar   cpufreq: introduc...
55

649098828   GuanXuetao   unicore32 additio...
56
57
58
  	policy->min = policy->cpuinfo.min_freq = 250000;
  	policy->max = policy->cpuinfo.max_freq = 1000000;
  	policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
652ed95d5   Viresh Kumar   cpufreq: introduc...
59
  	policy->clk = clk_get(NULL, "MAIN_CLK");
8ab4e2b30   Duan Jiong   cpufreq: unicore3...
60
  	return PTR_ERR_OR_ZERO(policy->clk);
649098828   GuanXuetao   unicore32 additio...
61
62
63
64
65
66
  }
  
  static struct cpufreq_driver ucv2_driver = {
  	.flags		= CPUFREQ_STICKY,
  	.verify		= ucv2_verify_speed,
  	.target		= ucv2_target,
652ed95d5   Viresh Kumar   cpufreq: introduc...
67
  	.get		= cpufreq_generic_get,
649098828   GuanXuetao   unicore32 additio...
68
69
70
71
72
73
74
75
76
77
  	.init		= ucv2_cpu_init,
  	.name		= "UniCore-II",
  };
  
  static int __init ucv2_cpufreq_init(void)
  {
  	return cpufreq_register_driver(&ucv2_driver);
  }
  
  arch_initcall(ucv2_cpufreq_init);