Path: blob/master/arch/unicore32/kernel/cpu-ucv2.c
10817 views
/*1* linux/arch/unicore32/kernel/cpu-ucv2.c: clock scaling for the UniCore-II2*3* Code specific to PKUnity SoC and UniCore ISA4*5* Maintained by GUAN Xue-tao <[email protected]>6* Copyright (C) 2001-2010 Guan Xuetao7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License version 2 as10* published by the Free Software Foundation.11*/1213#include <linux/kernel.h>14#include <linux/types.h>15#include <linux/init.h>16#include <linux/clk.h>17#include <linux/cpufreq.h>1819#include <mach/hardware.h>2021static struct cpufreq_driver ucv2_driver;2223/* make sure that only the "userspace" governor is run24* -- anything else wouldn't make sense on this platform, anyway.25*/26int ucv2_verify_speed(struct cpufreq_policy *policy)27{28if (policy->cpu)29return -EINVAL;3031cpufreq_verify_within_limits(policy,32policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);3334return 0;35}3637static unsigned int ucv2_getspeed(unsigned int cpu)38{39struct clk *mclk = clk_get(NULL, "MAIN_CLK");4041if (cpu)42return 0;43return clk_get_rate(mclk)/1000;44}4546static int ucv2_target(struct cpufreq_policy *policy,47unsigned int target_freq,48unsigned int relation)49{50unsigned int cur = ucv2_getspeed(0);51struct cpufreq_freqs freqs;52struct clk *mclk = clk_get(NULL, "MAIN_CLK");5354cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);5556if (!clk_set_rate(mclk, target_freq * 1000)) {57freqs.old = cur;58freqs.new = target_freq;59freqs.cpu = 0;60}6162cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);6364return 0;65}6667static int __init ucv2_cpu_init(struct cpufreq_policy *policy)68{69if (policy->cpu != 0)70return -EINVAL;71policy->cur = ucv2_getspeed(0);72policy->min = policy->cpuinfo.min_freq = 250000;73policy->max = policy->cpuinfo.max_freq = 1000000;74policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;75return 0;76}7778static struct cpufreq_driver ucv2_driver = {79.flags = CPUFREQ_STICKY,80.verify = ucv2_verify_speed,81.target = ucv2_target,82.get = ucv2_getspeed,83.init = ucv2_cpu_init,84.name = "UniCore-II",85};8687static int __init ucv2_cpufreq_init(void)88{89return cpufreq_register_driver(&ucv2_driver);90}9192arch_initcall(ucv2_cpufreq_init);939495