]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/cpufreq/omap-cpufreq.c
cpufreq: OMAP: cleanup for multi-SoC support, move into drivers/cpufreq
[mirror_ubuntu-bionic-kernel.git] / drivers / cpufreq / omap-cpufreq.c
CommitLineData
ec6bced6 1/*
ec6bced6
TL
2 * CPU frequency scaling for OMAP
3 *
4 * Copyright (C) 2005 Nokia Corporation
5 * Written by Tony Lindgren <tony@atomide.com>
6 *
7 * Based on cpu-sa1110.c, Copyright (C) 2001 Russell King
8 *
731e0cc6
SS
9 * Copyright (C) 2007-2011 Texas Instruments, Inc.
10 * - OMAP3/4 support by Rajendra Nayak, Santosh Shilimkar
11 *
ec6bced6
TL
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/sched.h>
19#include <linux/cpufreq.h>
20#include <linux/delay.h>
21#include <linux/init.h>
22#include <linux/err.h>
f8ce2547 23#include <linux/clk.h>
fced80c7 24#include <linux/io.h>
731e0cc6 25#include <linux/opp.h>
ec6bced6 26
ec6bced6 27#include <asm/system.h>
731e0cc6 28#include <asm/smp_plat.h>
ec6bced6 29
731e0cc6
SS
30#include <plat/clock.h>
31#include <plat/omap-pm.h>
32#include <plat/common.h>
a7ca9d2b 33
731e0cc6 34#include <mach/hardware.h>
aeec2990 35
731e0cc6 36#define VERY_HI_RATE 900000000
a7ca9d2b 37
731e0cc6 38static struct cpufreq_frequency_table *freq_table;
b8488fbe
HD
39static struct clk *mpu_clk;
40
b0a330dc 41static int omap_verify_speed(struct cpufreq_policy *policy)
ec6bced6 42{
aeec2990
KH
43 if (freq_table)
44 return cpufreq_frequency_table_verify(policy, freq_table);
45
ec6bced6
TL
46 if (policy->cpu)
47 return -EINVAL;
48
49 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
50 policy->cpuinfo.max_freq);
b8488fbe 51
ec6bced6
TL
52 policy->min = clk_round_rate(mpu_clk, policy->min * 1000) / 1000;
53 policy->max = clk_round_rate(mpu_clk, policy->max * 1000) / 1000;
54 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
55 policy->cpuinfo.max_freq);
ec6bced6
TL
56 return 0;
57}
58
b0a330dc 59static unsigned int omap_getspeed(unsigned int cpu)
ec6bced6 60{
ec6bced6
TL
61 unsigned long rate;
62
63 if (cpu)
64 return 0;
65
ec6bced6 66 rate = clk_get_rate(mpu_clk) / 1000;
ec6bced6
TL
67 return rate;
68}
69
70static int omap_target(struct cpufreq_policy *policy,
71 unsigned int target_freq,
72 unsigned int relation)
73{
ec6bced6 74 int ret = 0;
731e0cc6 75 struct cpufreq_freqs freqs;
ec6bced6 76
aeec2990
KH
77 /* Ensure desired rate is within allowed range. Some govenors
78 * (ondemand) will just pass target_freq=0 to get the minimum. */
60c45ae1
EN
79 if (target_freq < policy->min)
80 target_freq = policy->min;
81 if (target_freq > policy->max)
82 target_freq = policy->max;
aeec2990 83
ec6bced6
TL
84 freqs.old = omap_getspeed(0);
85 freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
86 freqs.cpu = 0;
87
aeec2990
KH
88 if (freqs.old == freqs.new)
89 return ret;
90
ec6bced6 91 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
731e0cc6 92
aeec2990 93#ifdef CONFIG_CPU_FREQ_DEBUG
731e0cc6 94 pr_info("cpufreq-omap: transition: %u --> %u\n", freqs.old, freqs.new);
aeec2990 95#endif
731e0cc6 96
aeec2990 97 ret = clk_set_rate(mpu_clk, freqs.new * 1000);
731e0cc6 98
ec6bced6 99 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
ec6bced6
TL
100
101 return ret;
102}
103
790ab7e9 104static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
ec6bced6 105{
aeec2990 106 int result = 0;
731e0cc6
SS
107 struct device *mpu_dev;
108
109 if (cpu_is_omap24xx())
110 mpu_clk = clk_get(NULL, "virt_prcm_set");
111 else if (cpu_is_omap34xx())
112 mpu_clk = clk_get(NULL, "dpll1_ck");
113 else if (cpu_is_omap44xx())
114 mpu_clk = clk_get(NULL, "dpll_mpu_ck");
aeec2990 115
ec6bced6
TL
116 if (IS_ERR(mpu_clk))
117 return PTR_ERR(mpu_clk);
118
119 if (policy->cpu != 0)
120 return -EINVAL;
aeec2990 121
ec6bced6 122 policy->cur = policy->min = policy->max = omap_getspeed(0);
aeec2990 123
731e0cc6
SS
124 mpu_dev = omap2_get_mpuss_device();
125 if (!mpu_dev) {
126 pr_warning("%s: unable to get the mpu device\n", __func__);
127 return -EINVAL;
128 }
129 opp_init_cpufreq_table(mpu_dev, &freq_table);
130
aeec2990
KH
131 if (freq_table) {
132 result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
133 if (!result)
134 cpufreq_frequency_table_get_attr(freq_table,
135 policy->cpu);
136 } else {
137 policy->cpuinfo.min_freq = clk_round_rate(mpu_clk, 0) / 1000;
138 policy->cpuinfo.max_freq = clk_round_rate(mpu_clk,
139 VERY_HI_RATE) / 1000;
140 }
141
731e0cc6
SS
142 policy->min = policy->cpuinfo.min_freq;
143 policy->max = policy->cpuinfo.max_freq;
144 policy->cur = omap_getspeed(0);
145
aeec2990 146 /* FIXME: what's the actual transition time? */
b029839c 147 policy->cpuinfo.transition_latency = 300 * 1000;
ec6bced6
TL
148
149 return 0;
150}
151
b8488fbe
HD
152static int omap_cpu_exit(struct cpufreq_policy *policy)
153{
4e37c10d 154 clk_exit_cpufreq_table(&freq_table);
b8488fbe
HD
155 clk_put(mpu_clk);
156 return 0;
157}
158
aeec2990
KH
159static struct freq_attr *omap_cpufreq_attr[] = {
160 &cpufreq_freq_attr_scaling_available_freqs,
161 NULL,
162};
163
ec6bced6
TL
164static struct cpufreq_driver omap_driver = {
165 .flags = CPUFREQ_STICKY,
166 .verify = omap_verify_speed,
167 .target = omap_target,
168 .get = omap_getspeed,
169 .init = omap_cpu_init,
b8488fbe 170 .exit = omap_cpu_exit,
ec6bced6 171 .name = "omap",
aeec2990 172 .attr = omap_cpufreq_attr,
ec6bced6
TL
173};
174
175static int __init omap_cpufreq_init(void)
176{
177 return cpufreq_register_driver(&omap_driver);
178}
179
731e0cc6
SS
180static void __exit omap_cpufreq_exit(void)
181{
182 cpufreq_unregister_driver(&omap_driver);
183}
aeec2990 184
731e0cc6
SS
185MODULE_DESCRIPTION("cpufreq driver for OMAP SoCs");
186MODULE_LICENSE("GPL");
187module_init(omap_cpufreq_init);
188module_exit(omap_cpufreq_exit);