GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 1 | /* |
Viresh Kumar | 73cc9c8 | 2013-04-04 12:54:23 +0000 | [diff] [blame] | 2 | * clock scaling for the UniCore-II |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 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 | |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 14 | #include <linux/err.h> |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 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 | */ |
Jingoo Han | 0e25246 | 2013-08-09 16:14:51 +0900 | [diff] [blame] | 28 | static int ucv2_verify_speed(struct cpufreq_policy *policy) |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 29 | { |
| 30 | if (policy->cpu) |
| 31 | return -EINVAL; |
| 32 | |
Viresh Kumar | be49e34 | 2013-10-02 14:13:19 +0530 | [diff] [blame] | 33 | cpufreq_verify_within_cpu_limits(policy); |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 34 | return 0; |
| 35 | } |
| 36 | |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 37 | static int ucv2_target(struct cpufreq_policy *policy, |
| 38 | unsigned int target_freq, |
| 39 | unsigned int relation) |
| 40 | { |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 41 | struct cpufreq_freqs freqs; |
Viresh Kumar | ab1b1c4 | 2013-12-02 11:04:13 +0530 | [diff] [blame] | 42 | int ret; |
| 43 | |
| 44 | freqs.old = policy->cur; |
| 45 | freqs.new = target_freq; |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 46 | |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 47 | cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 48 | ret = clk_set_rate(policy->mclk, target_freq * 1000); |
Viresh Kumar | ab1b1c4 | 2013-12-02 11:04:13 +0530 | [diff] [blame] | 49 | cpufreq_notify_post_transition(policy, &freqs, ret); |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 50 | |
Viresh Kumar | ab1b1c4 | 2013-12-02 11:04:13 +0530 | [diff] [blame] | 51 | return ret; |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static int __init ucv2_cpu_init(struct cpufreq_policy *policy) |
| 55 | { |
| 56 | if (policy->cpu != 0) |
| 57 | return -EINVAL; |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 58 | |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 59 | policy->min = policy->cpuinfo.min_freq = 250000; |
| 60 | policy->max = policy->cpuinfo.max_freq = 1000000; |
| 61 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 62 | policy->clk = clk_get(NULL, "MAIN_CLK"); |
| 63 | if (IS_ERR(policy->clk)) |
| 64 | return PTR_ERR(policy->clk); |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static struct cpufreq_driver ucv2_driver = { |
| 69 | .flags = CPUFREQ_STICKY, |
| 70 | .verify = ucv2_verify_speed, |
| 71 | .target = ucv2_target, |
Viresh Kumar | 652ed95 | 2014-01-09 20:38:43 +0530 | [diff] [blame] | 72 | .get = cpufreq_generic_get, |
GuanXuetao | 6490988 | 2011-02-26 20:23:59 +0800 | [diff] [blame] | 73 | .init = ucv2_cpu_init, |
| 74 | .name = "UniCore-II", |
| 75 | }; |
| 76 | |
| 77 | static int __init ucv2_cpufreq_init(void) |
| 78 | { |
| 79 | return cpufreq_register_driver(&ucv2_driver); |
| 80 | } |
| 81 | |
| 82 | arch_initcall(ucv2_cpufreq_init); |