blob: 203e027e5967296e8c82d13a554e339040b7740d [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* arch/arm/mach-msm/acpuclock.c
2 *
3 * MSM architecture clock driver
4 *
5 * Copyright (C) 2007 Google, Inc.
6 * Copyright (c) 2007-2011, Code Aurora Forum. All rights reserved.
7 * Author: San Mehat <san@android.com>
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#include <linux/version.h>
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/errno.h>
24#include <linux/string.h>
25#include <linux/delay.h>
26#include <linux/clk.h>
27#include <linux/cpufreq.h>
28#include <linux/mutex.h>
29#include <linux/io.h>
30#include <linux/sort.h>
31#include <linux/remote_spinlock.h>
32#include <mach/board.h>
33#include <mach/msm_iomap.h>
34#include <asm/mach-types.h>
35#include <mach/socinfo.h>
36
37#include "proc_comm.h"
38#include "smd_private.h"
39#include "acpuclock.h"
40
41#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
42#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
43#define A11S_VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124)
44#define PLLn_MODE(n) (MSM_CLK_CTL_BASE + 0x300 + 28 * (n))
45#define PLLn_L_VAL(n) (MSM_CLK_CTL_BASE + 0x304 + 28 * (n))
46
47#define PLL4_MODE (MSM_CLK_CTL_BASE + 0x374)
48#define PLL4_L_VAL (MSM_CLK_CTL_BASE + 0x378)
49
50/* Max CPU frequency allowed by hardware while in standby waiting for an irq. */
51#define MAX_WAIT_FOR_IRQ_KHZ 128000
52
53enum {
54 ACPU_PLL_TCXO = -1,
55 ACPU_PLL_0 = 0,
56 ACPU_PLL_1,
57 ACPU_PLL_2,
58 ACPU_PLL_3,
59 ACPU_PLL_4,
60 ACPU_PLL_END,
61};
62
63static const struct pll {
64 void __iomem *mod_reg;
65 const uint32_t l_val_mask;
66} soc_pll[ACPU_PLL_END] = {
67 [ACPU_PLL_0] = {PLLn_MODE(ACPU_PLL_0), 0x3f},
68 [ACPU_PLL_1] = {PLLn_MODE(ACPU_PLL_1), 0x3f},
69 [ACPU_PLL_2] = {PLLn_MODE(ACPU_PLL_2), 0x3f},
70 [ACPU_PLL_3] = {PLLn_MODE(ACPU_PLL_3), 0x3f},
71 [ACPU_PLL_4] = {PLL4_MODE, 0x3ff},
72};
73
74struct clock_state {
75 struct clkctl_acpu_speed *current_speed;
76 struct mutex lock;
77 uint32_t acpu_switch_time_us;
78 uint32_t max_speed_delta_khz;
79 uint32_t vdd_switch_time_us;
80 unsigned long max_axi_khz;
81 unsigned long wait_for_irq_khz;
82 struct clk *ebi1_clk;
83};
84
85#define PLL_BASE 7
86
87struct shared_pll_control {
88 uint32_t version;
89 struct {
90 /* Denotes if the PLL is ON. Technically, this can be read
91 * directly from the PLL registers, but this feild is here,
92 * so let's use it.
93 */
94 uint32_t on;
95 /* One bit for each processor core. The application processor
96 * is allocated bit position 1. All other bits should be
97 * considered as votes from other processors.
98 */
99 uint32_t votes;
100 } pll[PLL_BASE + ACPU_PLL_END];
101};
102
103struct clkctl_acpu_speed {
104 unsigned int use_for_scaling;
105 unsigned int a11clk_khz;
106 int pll;
107 unsigned int a11clk_src_sel;
108 unsigned int a11clk_src_div;
109 unsigned int ahbclk_khz;
110 unsigned int ahbclk_div;
111 int vdd;
112 unsigned int axiclk_khz;
113 unsigned long lpj; /* loops_per_jiffy */
114 /* Pointers in acpu_freq_tbl[] for max up/down steppings. */
115 struct clkctl_acpu_speed *down[ACPU_PLL_END];
116 struct clkctl_acpu_speed *up[ACPU_PLL_END];
117};
118
119static remote_spinlock_t pll_lock;
120static struct shared_pll_control *pll_control;
121static struct clock_state drv_state = { 0 };
122static struct clkctl_acpu_speed *acpu_freq_tbl;
123
124static void __init acpuclk_init(void);
125
126/*
127 * ACPU freq tables used for different PLLs frequency combinations. The
128 * correct table is selected during init.
129 *
130 * Table stepping up/down entries are calculated during boot to choose the
131 * largest frequency jump that's less than max_speed_delta_khz on each PLL.
132 */
133
134/* 7x01/7x25 normal with GSM capable modem */
135static struct clkctl_acpu_speed pll0_245_pll1_768_pll2_1056_pll4_0[] = {
136 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
137 { 1, 122880, ACPU_PLL_0, 4, 1, 61440, 1, 3, 61440 },
138 { 0, 128000, ACPU_PLL_1, 1, 5, 64000, 1, 3, 61440 },
139 { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 61440 },
140 { 1, 245760, ACPU_PLL_0, 4, 0, 81920, 2, 4, 61440 },
141 { 1, 256000, ACPU_PLL_1, 1, 2, 128000, 1, 5, 128000 },
142 { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 128000 },
143 { 1, 384000, ACPU_PLL_1, 1, 1, 128000, 2, 6, 128000 },
144 { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 128000 },
145 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
146};
147
148/* 7x01/7x25 normal with CDMA-only modem */
149static struct clkctl_acpu_speed pll0_196_pll1_768_pll2_1056_pll4_0[] = {
150 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
151 { 1, 98304, ACPU_PLL_0, 4, 1, 49152, 1, 3, 24576 },
152 { 0, 128000, ACPU_PLL_1, 1, 5, 64000, 1, 3, 24576 },
153 { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 24576 },
154 { 1, 196608, ACPU_PLL_0, 4, 0, 65536, 2, 4, 24576 },
155 { 1, 256000, ACPU_PLL_1, 1, 2, 128000, 1, 5, 128000 },
156 { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 128000 },
157 { 1, 384000, ACPU_PLL_1, 1, 1, 128000, 2, 6, 128000 },
158 { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 128000 },
159 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
160};
161
162/* 7x01/7x25 turbo with GSM capable modem */
163static struct clkctl_acpu_speed pll0_245_pll1_960_pll2_1056_pll4_0[] = {
164 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
165 { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 61440 },
166 { 1, 122880, ACPU_PLL_0, 4, 1, 61440, 1, 3, 61440 },
167 { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 61440 },
168 { 1, 245760, ACPU_PLL_0, 4, 0, 81920, 2, 4, 61440 },
169 { 1, 320000, ACPU_PLL_1, 1, 2, 107000, 2, 5, 120000 },
170 { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 120000 },
171 { 1, 480000, ACPU_PLL_1, 1, 1, 120000, 3, 6, 120000 },
172 { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 122880 },
173 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
174};
175
176/* 7x01/7x25 turbo with CDMA-only modem */
177static struct clkctl_acpu_speed pll0_196_pll1_960_pll2_1056_pll4_0[] = {
178 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
179 { 1, 98304, ACPU_PLL_0, 4, 1, 49152, 1, 3, 24576 },
180 { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 24576 },
181 { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 24576 },
182 { 1, 196608, ACPU_PLL_0, 4, 0, 65536, 2, 4, 24576 },
183 { 1, 320000, ACPU_PLL_1, 1, 2, 107000, 2, 5, 120000 },
184 { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 120000 },
185 { 1, 480000, ACPU_PLL_1, 1, 1, 120000, 3, 6, 120000 },
186 { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 120000 },
187 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
188};
189
190/* 7x27 normal with GSM capable modem */
191static struct clkctl_acpu_speed pll0_245_pll1_960_pll2_1200_pll4_0[] = {
192 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
193 { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 61440 },
194 { 1, 122880, ACPU_PLL_0, 4, 1, 61440, 1, 3, 61440 },
195 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
196 { 1, 245760, ACPU_PLL_0, 4, 0, 122880, 1, 4, 61440 },
197 { 1, 320000, ACPU_PLL_1, 1, 2, 160000, 1, 5, 122880 },
198 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 122880 },
199 { 1, 480000, ACPU_PLL_1, 1, 1, 160000, 2, 6, 122880 },
200 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 122880 },
201 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
202};
203
204/* 7x27 normal with CDMA-only modem */
205static struct clkctl_acpu_speed pll0_196_pll1_960_pll2_1200_pll4_0[] = {
206 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
207 { 1, 98304, ACPU_PLL_0, 4, 1, 98304, 0, 3, 49152 },
208 { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 49152 },
209 { 1, 196608, ACPU_PLL_0, 4, 0, 65536, 2, 4, 98304 },
210 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
211 { 1, 320000, ACPU_PLL_1, 1, 2, 160000, 1, 5, 120000 },
212 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 120000 },
213 { 1, 480000, ACPU_PLL_1, 1, 1, 160000, 2, 6, 120000 },
214 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 120000 },
215 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
216};
217
218/* 7x27 normal with GSM capable modem - PLL0 and PLL1 swapped */
219static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = {
220 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
221 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
222 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
223 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
224 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
225 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 122880 },
226 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 122880 },
227 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 122880 },
228 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 122880 },
229 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
230};
231
232/* 7x27 normal with CDMA-only modem - PLL0 and PLL1 swapped */
233static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = {
234 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
235 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
236 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
237 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
238 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
239 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 120000 },
240 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 120000 },
241 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 120000 },
242 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 120000 },
243 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
244};
245
246/* 7x27 normal with GSM capable modem - PLL0 and PLL1 swapped and pll2 @ 800 */
247static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = {
248 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
249 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
250 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
251 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 },
252 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
253 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 122880 },
254 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 122880 },
255 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 122880 },
256 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 122880 },
257 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
258};
259
260/* 7x27 normal with CDMA-only modem - PLL0 and PLL1 swapped and pll2 @ 800 */
261static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = {
262 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
263 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
264 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
265 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
266 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 },
267 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 120000 },
268 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 120000 },
269 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 120000 },
270 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 120000 },
271 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
272};
273
274/* 7x27a pll2 at 1200mhz with GSM capable modem */
275static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530276 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
277 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
278 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
279 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
280 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
281 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
282 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
283 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
284 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
285 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700286 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
287};
288
289/* 7x27a pll2 at 1200mhz with CDMA only modem */
290static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530291 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
292 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
293 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
294 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
295 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
296 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 160000 },
297 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 160000 },
298 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 160000 },
299 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
300 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700301 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
302};
303
Trilok Sonif597e242011-06-06 12:37:16 +0530304/* 7x27aa pll4 at 1008mhz with GSM capable modem */
305static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = {
306 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
307 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
308 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
309 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
310 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
311 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
312 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
313 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
314 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
315 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
316 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
317};
318
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700319#define PLL_0_MHZ 0
320#define PLL_196_MHZ 10
321#define PLL_245_MHZ 12
322#define PLL_491_MHZ 25
323#define PLL_768_MHZ 40
324#define PLL_800_MHZ 41
325#define PLL_960_MHZ 50
Trilok Sonif597e242011-06-06 12:37:16 +0530326#define PLL_1008_MHZ 52
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700327#define PLL_1056_MHZ 55
328#define PLL_1200_MHZ 62
329
330#define PLL_CONFIG(m0, m1, m2, m4) { \
331 PLL_##m0##_MHZ, PLL_##m1##_MHZ, PLL_##m2##_MHZ, PLL_##m4##_MHZ, \
332 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
333}
334
335struct pll_freq_tbl_map {
336 unsigned int pll0_l;
337 unsigned int pll1_l;
338 unsigned int pll2_l;
339 unsigned int pll4_l;
340 struct clkctl_acpu_speed *tbl;
341};
342
343static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
344 PLL_CONFIG(196, 768, 1056, 0),
345 PLL_CONFIG(245, 768, 1056, 0),
346 PLL_CONFIG(196, 960, 1056, 0),
347 PLL_CONFIG(245, 960, 1056, 0),
348 PLL_CONFIG(196, 960, 1200, 0),
349 PLL_CONFIG(245, 960, 1200, 0),
350 PLL_CONFIG(960, 196, 1200, 0),
351 PLL_CONFIG(960, 245, 1200, 0),
352 PLL_CONFIG(960, 196, 800, 0),
353 PLL_CONFIG(960, 245, 800, 0),
354 PLL_CONFIG(960, 245, 1200, 800),
355 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530356 PLL_CONFIG(960, 245, 1200, 1008),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700357 { 0, 0, 0, 0, 0 }
358};
359
360#ifdef CONFIG_CPU_FREQ_MSM
361static struct cpufreq_frequency_table freq_table[20];
362
363static void __init cpufreq_table_init(void)
364{
365 unsigned int i;
366 unsigned int freq_cnt = 0;
367
368 /* Construct the freq_table table from acpu_freq_tbl since the
369 * freq_table values need to match frequencies specified in
370 * acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init.
371 */
372 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
373 && freq_cnt < ARRAY_SIZE(freq_table)-1; i++) {
374 if (acpu_freq_tbl[i].use_for_scaling) {
375 freq_table[freq_cnt].index = freq_cnt;
376 freq_table[freq_cnt].frequency
377 = acpu_freq_tbl[i].a11clk_khz;
378 freq_cnt++;
379 }
380 }
381
382 /* freq_table not big enough to store all usable freqs. */
383 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
384
385 freq_table[freq_cnt].index = freq_cnt;
386 freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
387
388 pr_info("%d scaling frequencies supported.\n", freq_cnt);
389}
390#endif
391
392static void pll_enable(void __iomem *addr, unsigned on)
393{
394 if (on) {
395 writel_relaxed(2, addr);
396 mb();
397 udelay(5);
398 writel_relaxed(6, addr);
399 mb();
400 udelay(50);
401 writel_relaxed(7, addr);
402 } else {
403 writel_relaxed(0, addr);
404 }
405}
406
407static int pc_pll_request(unsigned id, unsigned on)
408{
409 int res = 0;
410 on = !!on;
411
412 if (on)
413 pr_debug("Enabling PLL %d\n", id);
414 else
415 pr_debug("Disabling PLL %d\n", id);
416
417 if (id >= ACPU_PLL_END)
418 return -EINVAL;
419
420 if (pll_control) {
421 remote_spin_lock(&pll_lock);
422 if (on) {
423 pll_control->pll[PLL_BASE + id].votes |= 2;
424 if (!pll_control->pll[PLL_BASE + id].on) {
425 pll_enable(soc_pll[id].mod_reg, 1);
426 pll_control->pll[PLL_BASE + id].on = 1;
427 }
428 } else {
429 pll_control->pll[PLL_BASE + id].votes &= ~2;
430 if (pll_control->pll[PLL_BASE + id].on
431 && !pll_control->pll[PLL_BASE + id].votes) {
432 pll_enable(soc_pll[id].mod_reg, 0);
433 pll_control->pll[PLL_BASE + id].on = 0;
434 }
435 }
436 remote_spin_unlock(&pll_lock);
437 } else {
438 res = msm_proc_comm(PCOM_CLKCTL_RPC_PLL_REQUEST, &id, &on);
439 if (res < 0)
440 return res;
441 else if ((int) id < 0)
442 return -EINVAL;
443 }
444
445 if (on)
446 pr_debug("PLL enabled\n");
447 else
448 pr_debug("PLL disabled\n");
449
450 return res;
451}
452
453
454/*----------------------------------------------------------------------------
455 * ARM11 'owned' clock control
456 *---------------------------------------------------------------------------*/
457
458#define POWER_COLLAPSE_KHZ 19200
459unsigned long acpuclk_power_collapse(void)
460{
461 int ret = acpuclk_get_rate(smp_processor_id());
462 acpuclk_set_rate(smp_processor_id(), POWER_COLLAPSE_KHZ, SETRATE_PC);
463 return ret;
464}
465
466unsigned long acpuclk_wait_for_irq(void)
467{
468 int rate = acpuclk_get_rate(smp_processor_id());
469 if (rate > MAX_WAIT_FOR_IRQ_KHZ)
470 acpuclk_set_rate(smp_processor_id(), drv_state.wait_for_irq_khz,
471 SETRATE_SWFI);
472 return rate;
473}
474
475static int acpuclk_set_vdd_level(int vdd)
476{
477 uint32_t current_vdd;
478
479 /*
480 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
481 * VDD switching support.
482 */
483 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
484 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
485 return 0;
486
487 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
488
489 pr_debug("Switching VDD from %u mV -> %d mV\n",
490 current_vdd, vdd);
491
492 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
493 mb();
494 udelay(drv_state.vdd_switch_time_us);
495 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
496 pr_err("VDD set failed\n");
497 return -EIO;
498 }
499
500 pr_debug("VDD switched\n");
501
502 return 0;
503}
504
505/* Set proper dividers for the given clock speed. */
506static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
507{
508 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
509
510 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
511
512 /* AHB_CLK_DIV */
513 clk_div = (reg_clksel >> 1) & 0x03;
514 /* CLK_SEL_SRC1NO */
515 src_sel = reg_clksel & 1;
516
517 /*
518 * If the new clock divider is higher than the previous, then
519 * program the divider before switching the clock
520 */
521 if (hunt_s->ahbclk_div > clk_div) {
522 reg_clksel &= ~(0x3 << 1);
523 reg_clksel |= (hunt_s->ahbclk_div << 1);
524 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
525 }
526
527 /* Program clock source and divider */
528 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
529 reg_clkctl &= ~(0xFF << (8 * src_sel));
530 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
531 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
532 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
533
534 /* Program clock source selection */
535 reg_clksel ^= 1;
536 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
537
538 /*
539 * If the new clock divider is lower than the previous, then
540 * program the divider after switching the clock
541 */
542 if (hunt_s->ahbclk_div < clk_div) {
543 reg_clksel &= ~(0x3 << 1);
544 reg_clksel |= (hunt_s->ahbclk_div << 1);
545 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
546 }
547}
548
549int acpuclk_set_rate(int cpu, unsigned long rate, enum setrate_reason reason)
550{
551 uint32_t reg_clkctl;
552 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
553 int res, rc = 0;
554 unsigned int plls_enabled = 0, pll;
555
556 if (reason == SETRATE_CPUFREQ)
557 mutex_lock(&drv_state.lock);
558
559 strt_s = cur_s = drv_state.current_speed;
560
561 WARN_ONCE(cur_s == NULL, "acpuclk_set_rate: not initialized\n");
562 if (cur_s == NULL) {
563 rc = -ENOENT;
564 goto out;
565 }
566
567 if (rate == cur_s->a11clk_khz)
568 goto out;
569
570 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
571 if (tgt_s->a11clk_khz == rate)
572 break;
573 }
574
575 if (tgt_s->a11clk_khz == 0) {
576 rc = -EINVAL;
577 goto out;
578 }
579
580 /* Choose the highest speed at or below 'rate' with same PLL. */
581 if (reason != SETRATE_CPUFREQ
582 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
583 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
584 tgt_s--;
585 }
586
587 if (strt_s->pll != ACPU_PLL_TCXO)
588 plls_enabled |= 1 << strt_s->pll;
589
590 if (reason == SETRATE_CPUFREQ) {
591 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
592 rc = pc_pll_request(tgt_s->pll, 1);
593 if (rc < 0) {
594 pr_err("PLL%d enable failed (%d)\n",
595 tgt_s->pll, rc);
596 goto out;
597 }
598 plls_enabled |= 1 << tgt_s->pll;
599 }
600 }
601 /* Need to do this when coming out of power collapse since some modem
602 * firmwares reset the VDD when the application processor enters power
603 * collapse. */
604 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
605 /* Increase VDD if needed. */
606 if (tgt_s->vdd > cur_s->vdd) {
607 rc = acpuclk_set_vdd_level(tgt_s->vdd);
608 if (rc < 0) {
609 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
610 goto out;
611 }
612 }
613 }
614
615 /* Set wait states for CPU inbetween frequency changes */
616 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
617 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
618 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
619
620 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
621 strt_s->a11clk_khz, tgt_s->a11clk_khz);
622
623 while (cur_s != tgt_s) {
624 /*
625 * Always jump to target freq if within 256mhz, regulardless of
626 * PLL. If differnece is greater, use the predefinied
627 * steppings in the table.
628 */
629 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
630 if (d > drv_state.max_speed_delta_khz) {
631
632 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
633 /* Step up: jump to target PLL as early as
634 * possible so indexing using TCXO (up[-1])
635 * never occurs. */
636 if (likely(cur_s->up[tgt_s->pll]))
637 cur_s = cur_s->up[tgt_s->pll];
638 else
639 cur_s = cur_s->up[cur_s->pll];
640 } else {
641 /* Step down: stay on current PLL as long as
642 * possible so indexing using TCXO (down[-1])
643 * never occurs. */
644 if (likely(cur_s->down[cur_s->pll]))
645 cur_s = cur_s->down[cur_s->pll];
646 else
647 cur_s = cur_s->down[tgt_s->pll];
648 }
649
650 if (cur_s == NULL) { /* This should not happen. */
651 pr_err("No stepping frequencies found. "
652 "strt_s:%u tgt_s:%u\n",
653 strt_s->a11clk_khz, tgt_s->a11clk_khz);
654 rc = -EINVAL;
655 goto out;
656 }
657
658 } else {
659 cur_s = tgt_s;
660 }
661
662 pr_debug("STEP khz = %u, pll = %d\n",
663 cur_s->a11clk_khz, cur_s->pll);
664
665 if (cur_s->pll != ACPU_PLL_TCXO
666 && !(plls_enabled & (1 << cur_s->pll))) {
667 rc = pc_pll_request(cur_s->pll, 1);
668 if (rc < 0) {
669 pr_err("PLL%d enable failed (%d)\n",
670 cur_s->pll, rc);
671 goto out;
672 }
673 plls_enabled |= 1 << cur_s->pll;
674 }
675
676 acpuclk_set_div(cur_s);
677 drv_state.current_speed = cur_s;
678 /* Re-adjust lpj for the new clock speed. */
679 loops_per_jiffy = cur_s->lpj;
680 mb();
681 udelay(drv_state.acpu_switch_time_us);
682 }
683
684 /* Nothing else to do for SWFI. */
685 if (reason == SETRATE_SWFI)
686 goto out;
687
688 /* Change the AXI bus frequency if we can. */
689 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
690 res = clk_set_rate(drv_state.ebi1_clk,
691 tgt_s->axiclk_khz * 1000);
692 if (res < 0)
693 pr_warning("Setting AXI min rate failed (%d)\n", res);
694 }
695
696 /* Disable PLLs we are not using anymore. */
697 if (tgt_s->pll != ACPU_PLL_TCXO)
698 plls_enabled &= ~(1 << tgt_s->pll);
699 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
700 if (plls_enabled & (1 << pll)) {
701 res = pc_pll_request(pll, 0);
702 if (res < 0)
703 pr_warning("PLL%d disable failed (%d)\n",
704 pll, res);
705 }
706
707 /* Nothing else to do for power collapse. */
708 if (reason == SETRATE_PC)
709 goto out;
710
711 /* Drop VDD level if we can. */
712 if (tgt_s->vdd < strt_s->vdd) {
713 res = acpuclk_set_vdd_level(tgt_s->vdd);
714 if (res < 0)
715 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
716 }
717
718 pr_debug("ACPU speed change complete\n");
719out:
720 if (reason == SETRATE_CPUFREQ)
721 mutex_unlock(&drv_state.lock);
722 return rc;
723}
724
725static void __init acpuclk_init(void)
726{
727 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530728 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700729 int res;
730
731 /*
732 * Determine the rate of ACPU clock
733 */
734
735 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
736 /* CLK_SRC0_SEL */
737 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
738 /* CLK_SRC0_DIV */
739 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
740 } else {
741 /* CLK_SRC1_SEL */
742 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
743 /* CLK_SRC1_DIV */
744 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
745 }
746
747 /* Accomodate bootloaders that might not be implementing the
748 * workaround for the h/w bug in 7x25. */
749 if (cpu_is_msm7x25() && sel == 2)
750 sel = 3;
751
752 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
753 if (speed->a11clk_src_sel == sel
754 && (speed->a11clk_src_div == div))
755 break;
756 }
757 if (speed->a11clk_khz == 0) {
758 pr_err("Error - ACPU clock reports invalid speed\n");
759 return;
760 }
761
762 drv_state.current_speed = speed;
763 if (speed->pll != ACPU_PLL_TCXO)
764 if (pc_pll_request(speed->pll, 1))
765 pr_warning("Failed to vote for boot PLL\n");
766
Trilok Soni7d6c8652011-07-14 15:35:07 +0530767 /* Fix div2 to 2 for 7x27/5a(aa) targets */
768 if (!cpu_is_msm7x27()) {
769 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
770 reg_clksel &= ~(0x3 << 14);
771 reg_clksel |= (0x1 << 14);
772 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
773 }
774
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700775 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
776 if (res < 0)
777 pr_warning("Setting AXI min rate failed (%d)\n", res);
778 res = clk_enable(drv_state.ebi1_clk);
779 if (res < 0)
780 pr_warning("Enabling AXI clock failed (%d)\n", res);
781
782 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
783}
784
785unsigned long acpuclk_get_rate(int cpu)
786{
787 WARN_ONCE(drv_state.current_speed == NULL,
788 "acpuclk_get_rate: not initialized\n");
789 if (drv_state.current_speed)
790 return drv_state.current_speed->a11clk_khz;
791 else
792 return 0;
793}
794
795uint32_t acpuclk_get_switch_time(void)
796{
797 return drv_state.acpu_switch_time_us;
798}
799
800/*----------------------------------------------------------------------------
801 * Clock driver initialization
802 *---------------------------------------------------------------------------*/
803
804#define DIV2REG(n) ((n)-1)
805#define REG2DIV(n) ((n)+1)
806#define SLOWER_BY(div, factor) div = DIV2REG(REG2DIV(div) * factor)
807
808static void __init acpu_freq_tbl_fixup(void)
809{
810 unsigned long pll0_l, pll1_l, pll2_l, pll4_l;
811 int axi_160mhz = 0, axi_200mhz = 0;
812 struct pll_freq_tbl_map *lst;
813 struct clkctl_acpu_speed *t;
814 unsigned int pll0_needs_fixup = 0;
815
816 /* Wait for the PLLs to be initialized and then read their frequency.
817 */
818 do {
819 pll0_l = readl_relaxed(PLLn_L_VAL(0)) &
820 soc_pll[ACPU_PLL_0].l_val_mask;
821 cpu_relax();
822 udelay(50);
823 } while (pll0_l == 0);
824 do {
825 pll1_l = readl_relaxed(PLLn_L_VAL(1)) &
826 soc_pll[ACPU_PLL_1].l_val_mask;
827 cpu_relax();
828 udelay(50);
829 } while (pll1_l == 0);
830 do {
831 pll2_l = readl_relaxed(PLLn_L_VAL(2)) &
832 soc_pll[ACPU_PLL_2].l_val_mask;
833 cpu_relax();
834 udelay(50);
835 } while (pll2_l == 0);
836
837 pr_info("L val: PLL0: %d, PLL1: %d, PLL2: %d\n",
838 (int)pll0_l, (int)pll1_l, (int)pll2_l);
839
840 if (!cpu_is_msm7x27() && !cpu_is_msm7x25a()) {
841 do {
842 pll4_l = readl_relaxed(PLL4_L_VAL) &
843 soc_pll[ACPU_PLL_4].l_val_mask;
844 cpu_relax();
845 udelay(50);
846 } while (pll4_l == 0);
847 pr_info("L val: PLL4: %d\n", (int)pll4_l);
848 } else {
849 pll4_l = 0;
850 }
851
852 /* Some configurations run PLL0 twice as fast. Instead of having
853 * separate tables for this case, we simply fix up the ACPU clock
854 * source divider since it's a simple fix up.
855 */
856 if (pll0_l == PLL_491_MHZ) {
857 pll0_l = PLL_245_MHZ;
858 pll0_needs_fixup = 1;
859 }
860
861 /* Select the right table to use. */
862 for (lst = acpu_freq_tbl_list; lst->tbl != 0; lst++) {
863 if (lst->pll0_l == pll0_l && lst->pll1_l == pll1_l
864 && lst->pll2_l == pll2_l
865 && lst->pll4_l == pll4_l) {
866 acpu_freq_tbl = lst->tbl;
867 break;
868 }
869 }
870
871 if (acpu_freq_tbl == NULL) {
872 pr_crit("Unknown PLL configuration!\n");
873 BUG();
874 }
875
876 /* Fix up PLL0 source divider if necessary. Also, fix up the AXI to
877 * the max that's supported by the board (RAM used in board).
878 */
879 axi_160mhz = (pll0_l == PLL_960_MHZ || pll1_l == PLL_960_MHZ);
880 axi_200mhz = (pll2_l == PLL_1200_MHZ || pll2_l == PLL_800_MHZ);
881 for (t = &acpu_freq_tbl[0]; t->a11clk_khz != 0; t++) {
882
883 if (pll0_needs_fixup && t->pll == ACPU_PLL_0)
884 SLOWER_BY(t->a11clk_src_div, 2);
885 if (axi_160mhz && drv_state.max_axi_khz >= 160000
886 && t->ahbclk_khz > 128000)
887 t->axiclk_khz = 160000;
888 if (axi_200mhz && drv_state.max_axi_khz >= 200000
889 && t->ahbclk_khz > 160000)
890 t->axiclk_khz = 200000;
891 }
892
893 t--;
894 drv_state.max_axi_khz = t->axiclk_khz;
895
896 /* The default 7x27 ACPU clock plan supports running the AXI bus at
897 * 200 MHz. So we don't classify it as Turbo mode.
898 */
899 if (cpu_is_msm7x27())
900 return;
901
902 if (!axi_160mhz)
903 pr_info("Turbo mode not supported.\n");
904 else if (t->axiclk_khz == 160000)
905 pr_info("Turbo mode supported and enabled.\n");
906 else
907 pr_info("Turbo mode supported but not enabled.\n");
908}
909
910/*
911 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
912 * before entering a wait for irq low-power mode. Find a suitable rate.
913 */
914static unsigned long __init find_wait_for_irq_khz(void)
915{
916 unsigned long found_khz = 0;
917 int i;
918
919 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
920 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
921 found_khz = acpu_freq_tbl[i].a11clk_khz;
922
923 return found_khz;
924}
925
926/* Initalize the lpj field in the acpu_freq_tbl. */
927static void __init lpj_init(void)
928{
929 int i;
930 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
931 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
932 acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy,
933 base_clk->a11clk_khz,
934 acpu_freq_tbl[i].a11clk_khz);
935 }
936}
937
938static void __init precompute_stepping(void)
939{
940 int i, step_idx;
941
942#define cur_freq acpu_freq_tbl[i].a11clk_khz
943#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
944#define cur_pll acpu_freq_tbl[i].pll
945#define step_pll acpu_freq_tbl[step_idx].pll
946
947 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
948
949 /* Calculate max "up" step for each destination PLL */
950 step_idx = i + 1;
951 while (step_freq && (step_freq - cur_freq)
952 <= drv_state.max_speed_delta_khz) {
953 acpu_freq_tbl[i].up[step_pll] =
954 &acpu_freq_tbl[step_idx];
955 step_idx++;
956 }
957 if (step_idx == (i + 1) && step_freq) {
958 pr_crit("Delta between freqs %u KHz and %u KHz is"
959 " too high!\n", cur_freq, step_freq);
960 BUG();
961 }
962
963 /* Calculate max "down" step for each destination PLL */
964 step_idx = i - 1;
965 while (step_idx >= 0 && (cur_freq - step_freq)
966 <= drv_state.max_speed_delta_khz) {
967 acpu_freq_tbl[i].down[step_pll] =
968 &acpu_freq_tbl[step_idx];
969 step_idx--;
970 }
971 if (step_idx == (i - 1) && i > 0) {
972 pr_crit("Delta between freqs %u KHz and %u KHz is"
973 " too high!\n", cur_freq, step_freq);
974 BUG();
975 }
976 }
977}
978
979static void __init print_acpu_freq_tbl(void)
980{
981 struct clkctl_acpu_speed *t;
982 short down_idx[ACPU_PLL_END];
983 short up_idx[ACPU_PLL_END];
984 int i, j;
985
986#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
987 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
988 "D0 D1 D2 D4 U0 U1 U2 U4\n");
989
990 t = &acpu_freq_tbl[0];
991 for (i = 0; t->a11clk_khz != 0; i++) {
992
993 for (j = 0; j < ACPU_PLL_END; j++) {
994 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
995 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
996 }
997
998 pr_info("%2d %7d %3d %3d %7d %4d %7d "
999 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
1000 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
1001 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
1002 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
1003 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
1004
1005 t++;
1006 }
1007}
1008
1009static void msm7x25_acpu_pll_hw_bug_fix(void)
1010{
1011 unsigned int n;
1012
1013 /* The 7625 has a hardware bug and in order to select PLL2 we
1014 * must program PLL3. Use the same table, and just fix up the
1015 * numbers on this target. */
1016 for (n = 0; acpu_freq_tbl[n].a11clk_khz != 0; n++)
1017 if (acpu_freq_tbl[n].pll == ACPU_PLL_2)
1018 acpu_freq_tbl[n].a11clk_src_sel = 3;
1019}
1020
1021static void shared_pll_control_init(void)
1022{
1023#define PLL_REMOTE_SPINLOCK_ID "S:7"
1024 unsigned smem_size;
1025 remote_spin_lock_init(&pll_lock, PLL_REMOTE_SPINLOCK_ID);
1026 pll_control = smem_get_entry(SMEM_CLKREGIM_SOURCES, &smem_size);
1027
1028 if (!pll_control)
1029 pr_warning("Can't find shared PLL control data structure!\n");
1030 /* There might be more PLLs than what the application processor knows
1031 * about. But the index used for each PLL is guaranteed to remain the
1032 * same. */
1033 else if (smem_size < sizeof(struct shared_pll_control))
1034 pr_warning("Shared PLL control data structure too small!\n");
1035 else if (pll_control->version != 0xCCEE0001)
1036 pr_warning("Shared PLL control version mismatch!\n");
1037 else {
1038 pr_info("Shared PLL control available.\n");
1039 return;
1040 }
1041
1042 pll_control = NULL;
1043 pr_warning("Falling back to proc_comm PLL control.\n");
1044}
1045
1046void __init msm_acpu_clock_init(struct msm_acpu_clock_platform_data *clkdata)
1047{
1048 pr_info("acpu_clock_init()\n");
1049
1050 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
1051 BUG_ON(IS_ERR(drv_state.ebi1_clk));
1052
1053 mutex_init(&drv_state.lock);
1054 shared_pll_control_init();
1055 drv_state.acpu_switch_time_us = clkdata->acpu_switch_time_us;
1056 drv_state.max_speed_delta_khz = clkdata->max_speed_delta_khz;
1057 drv_state.vdd_switch_time_us = clkdata->vdd_switch_time_us;
1058 drv_state.max_axi_khz = clkdata->max_axi_khz;
1059 acpu_freq_tbl_fixup();
1060 drv_state.wait_for_irq_khz = find_wait_for_irq_khz();
1061 precompute_stepping();
1062 if (cpu_is_msm7x25())
1063 msm7x25_acpu_pll_hw_bug_fix();
1064 acpuclk_init();
1065 lpj_init();
1066 print_acpu_freq_tbl();
1067#ifdef CONFIG_CPU_FREQ_MSM
1068 cpufreq_table_init();
1069 cpufreq_frequency_table_get_attr(freq_table, smp_processor_id());
1070#endif
1071}