| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | *  linux/arch/arm/plat-omap/cpu-omap.c | 
|  | 3 | * | 
|  | 4 | *  CPU frequency scaling for OMAP | 
|  | 5 | * | 
|  | 6 | *  Copyright (C) 2005 Nokia Corporation | 
|  | 7 | *  Written by Tony Lindgren <tony@atomide.com> | 
|  | 8 | * | 
|  | 9 | *  Based on cpu-sa1110.c, Copyright (C) 2001 Russell King | 
|  | 10 | * | 
|  | 11 | * This program is free software; you can redistribute it and/or modify | 
|  | 12 | * it under the terms of the GNU General Public License version 2 as | 
|  | 13 | * published by the Free Software Foundation. | 
|  | 14 | */ | 
|  | 15 | #include <linux/types.h> | 
|  | 16 | #include <linux/kernel.h> | 
|  | 17 | #include <linux/sched.h> | 
|  | 18 | #include <linux/cpufreq.h> | 
|  | 19 | #include <linux/delay.h> | 
|  | 20 | #include <linux/init.h> | 
|  | 21 | #include <linux/err.h> | 
| Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 22 | #include <linux/clk.h> | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 23 |  | 
|  | 24 | #include <asm/hardware.h> | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 25 | #include <asm/io.h> | 
|  | 26 | #include <asm/system.h> | 
|  | 27 |  | 
| Tony Lindgren | a7ca9d2 | 2006-06-26 16:16:17 -0700 | [diff] [blame] | 28 | #define VERY_HI_RATE	900000000 | 
|  | 29 |  | 
|  | 30 | #ifdef CONFIG_ARCH_OMAP1 | 
|  | 31 | #define MPU_CLK		"mpu" | 
|  | 32 | #else | 
|  | 33 | #define MPU_CLK		"virt_prcm_set" | 
|  | 34 | #endif | 
|  | 35 |  | 
| Hiroshi DOYU | b8488fb | 2007-08-30 12:46:39 +0300 | [diff] [blame] | 36 | static struct clk *mpu_clk; | 
|  | 37 |  | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 38 | /* TODO: Add support for SDRAM timing changes */ | 
|  | 39 |  | 
|  | 40 | int omap_verify_speed(struct cpufreq_policy *policy) | 
|  | 41 | { | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 42 | if (policy->cpu) | 
|  | 43 | return -EINVAL; | 
|  | 44 |  | 
|  | 45 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, | 
|  | 46 | policy->cpuinfo.max_freq); | 
| Hiroshi DOYU | b8488fb | 2007-08-30 12:46:39 +0300 | [diff] [blame] | 47 |  | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 48 | policy->min = clk_round_rate(mpu_clk, policy->min * 1000) / 1000; | 
|  | 49 | policy->max = clk_round_rate(mpu_clk, policy->max * 1000) / 1000; | 
|  | 50 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, | 
|  | 51 | policy->cpuinfo.max_freq); | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 52 | return 0; | 
|  | 53 | } | 
|  | 54 |  | 
|  | 55 | unsigned int omap_getspeed(unsigned int cpu) | 
|  | 56 | { | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 57 | unsigned long rate; | 
|  | 58 |  | 
|  | 59 | if (cpu) | 
|  | 60 | return 0; | 
|  | 61 |  | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 62 | rate = clk_get_rate(mpu_clk) / 1000; | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 63 | return rate; | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | static int omap_target(struct cpufreq_policy *policy, | 
|  | 67 | unsigned int target_freq, | 
|  | 68 | unsigned int relation) | 
|  | 69 | { | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 70 | struct cpufreq_freqs freqs; | 
|  | 71 | int ret = 0; | 
|  | 72 |  | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 73 | freqs.old = omap_getspeed(0); | 
|  | 74 | freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000; | 
|  | 75 | freqs.cpu = 0; | 
|  | 76 |  | 
|  | 77 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | 
|  | 78 | ret = clk_set_rate(mpu_clk, target_freq * 1000); | 
|  | 79 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 80 |  | 
|  | 81 | return ret; | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | static int __init omap_cpu_init(struct cpufreq_policy *policy) | 
|  | 85 | { | 
| Tony Lindgren | a7ca9d2 | 2006-06-26 16:16:17 -0700 | [diff] [blame] | 86 | mpu_clk = clk_get(NULL, MPU_CLK); | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 87 | if (IS_ERR(mpu_clk)) | 
|  | 88 | return PTR_ERR(mpu_clk); | 
|  | 89 |  | 
|  | 90 | if (policy->cpu != 0) | 
|  | 91 | return -EINVAL; | 
|  | 92 | policy->cur = policy->min = policy->max = omap_getspeed(0); | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 93 | policy->cpuinfo.min_freq = clk_round_rate(mpu_clk, 0) / 1000; | 
| Tony Lindgren | a7ca9d2 | 2006-06-26 16:16:17 -0700 | [diff] [blame] | 94 | policy->cpuinfo.max_freq = clk_round_rate(mpu_clk, VERY_HI_RATE) / 1000; | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 95 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 96 |  | 
|  | 97 | return 0; | 
|  | 98 | } | 
|  | 99 |  | 
| Hiroshi DOYU | b8488fb | 2007-08-30 12:46:39 +0300 | [diff] [blame] | 100 | static int omap_cpu_exit(struct cpufreq_policy *policy) | 
|  | 101 | { | 
|  | 102 | clk_put(mpu_clk); | 
|  | 103 | return 0; | 
|  | 104 | } | 
|  | 105 |  | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 106 | static struct cpufreq_driver omap_driver = { | 
|  | 107 | .flags		= CPUFREQ_STICKY, | 
|  | 108 | .verify		= omap_verify_speed, | 
|  | 109 | .target		= omap_target, | 
|  | 110 | .get		= omap_getspeed, | 
|  | 111 | .init		= omap_cpu_init, | 
| Hiroshi DOYU | b8488fb | 2007-08-30 12:46:39 +0300 | [diff] [blame] | 112 | .exit		= omap_cpu_exit, | 
| Tony Lindgren | ec6bced | 2005-07-10 19:58:20 +0100 | [diff] [blame] | 113 | .name		= "omap", | 
|  | 114 | }; | 
|  | 115 |  | 
|  | 116 | static int __init omap_cpufreq_init(void) | 
|  | 117 | { | 
|  | 118 | return cpufreq_register_driver(&omap_driver); | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | arch_initcall(omap_cpufreq_init); |