blob: 2147232e28e20f485cde62082503cde714fa49e7 [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 },
Trilok Soniabb750b2011-07-13 16:47:18 +0530295 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
296 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
297 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
298 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530299 { 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
Trilok Soni54d35c42011-07-14 17:47:50 +0530319/* 7x25a pll2 at 1200mhz with GSM capable modem */
320static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800_25a[] = {
321 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
322 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
323 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
324 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
325 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
326 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
327 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
328 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
329 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
330 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
331};
332
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333#define PLL_0_MHZ 0
334#define PLL_196_MHZ 10
335#define PLL_245_MHZ 12
336#define PLL_491_MHZ 25
337#define PLL_768_MHZ 40
338#define PLL_800_MHZ 41
339#define PLL_960_MHZ 50
Trilok Sonif597e242011-06-06 12:37:16 +0530340#define PLL_1008_MHZ 52
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700341#define PLL_1056_MHZ 55
342#define PLL_1200_MHZ 62
343
344#define PLL_CONFIG(m0, m1, m2, m4) { \
345 PLL_##m0##_MHZ, PLL_##m1##_MHZ, PLL_##m2##_MHZ, PLL_##m4##_MHZ, \
346 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
347}
348
349struct pll_freq_tbl_map {
350 unsigned int pll0_l;
351 unsigned int pll1_l;
352 unsigned int pll2_l;
353 unsigned int pll4_l;
354 struct clkctl_acpu_speed *tbl;
355};
356
357static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
358 PLL_CONFIG(196, 768, 1056, 0),
359 PLL_CONFIG(245, 768, 1056, 0),
360 PLL_CONFIG(196, 960, 1056, 0),
361 PLL_CONFIG(245, 960, 1056, 0),
362 PLL_CONFIG(196, 960, 1200, 0),
363 PLL_CONFIG(245, 960, 1200, 0),
364 PLL_CONFIG(960, 196, 1200, 0),
365 PLL_CONFIG(960, 245, 1200, 0),
366 PLL_CONFIG(960, 196, 800, 0),
367 PLL_CONFIG(960, 245, 800, 0),
368 PLL_CONFIG(960, 245, 1200, 800),
369 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530370 PLL_CONFIG(960, 245, 1200, 1008),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700371 { 0, 0, 0, 0, 0 }
372};
373
374#ifdef CONFIG_CPU_FREQ_MSM
375static struct cpufreq_frequency_table freq_table[20];
376
377static void __init cpufreq_table_init(void)
378{
379 unsigned int i;
380 unsigned int freq_cnt = 0;
381
382 /* Construct the freq_table table from acpu_freq_tbl since the
383 * freq_table values need to match frequencies specified in
384 * acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init.
385 */
386 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
387 && freq_cnt < ARRAY_SIZE(freq_table)-1; i++) {
388 if (acpu_freq_tbl[i].use_for_scaling) {
389 freq_table[freq_cnt].index = freq_cnt;
390 freq_table[freq_cnt].frequency
391 = acpu_freq_tbl[i].a11clk_khz;
392 freq_cnt++;
393 }
394 }
395
396 /* freq_table not big enough to store all usable freqs. */
397 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
398
399 freq_table[freq_cnt].index = freq_cnt;
400 freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
401
402 pr_info("%d scaling frequencies supported.\n", freq_cnt);
403}
404#endif
405
406static void pll_enable(void __iomem *addr, unsigned on)
407{
408 if (on) {
409 writel_relaxed(2, addr);
410 mb();
411 udelay(5);
412 writel_relaxed(6, addr);
413 mb();
414 udelay(50);
415 writel_relaxed(7, addr);
416 } else {
417 writel_relaxed(0, addr);
418 }
419}
420
421static int pc_pll_request(unsigned id, unsigned on)
422{
423 int res = 0;
424 on = !!on;
425
426 if (on)
427 pr_debug("Enabling PLL %d\n", id);
428 else
429 pr_debug("Disabling PLL %d\n", id);
430
431 if (id >= ACPU_PLL_END)
432 return -EINVAL;
433
434 if (pll_control) {
435 remote_spin_lock(&pll_lock);
436 if (on) {
437 pll_control->pll[PLL_BASE + id].votes |= 2;
438 if (!pll_control->pll[PLL_BASE + id].on) {
439 pll_enable(soc_pll[id].mod_reg, 1);
440 pll_control->pll[PLL_BASE + id].on = 1;
441 }
442 } else {
443 pll_control->pll[PLL_BASE + id].votes &= ~2;
444 if (pll_control->pll[PLL_BASE + id].on
445 && !pll_control->pll[PLL_BASE + id].votes) {
446 pll_enable(soc_pll[id].mod_reg, 0);
447 pll_control->pll[PLL_BASE + id].on = 0;
448 }
449 }
450 remote_spin_unlock(&pll_lock);
451 } else {
452 res = msm_proc_comm(PCOM_CLKCTL_RPC_PLL_REQUEST, &id, &on);
453 if (res < 0)
454 return res;
455 else if ((int) id < 0)
456 return -EINVAL;
457 }
458
459 if (on)
460 pr_debug("PLL enabled\n");
461 else
462 pr_debug("PLL disabled\n");
463
464 return res;
465}
466
467
468/*----------------------------------------------------------------------------
469 * ARM11 'owned' clock control
470 *---------------------------------------------------------------------------*/
471
472#define POWER_COLLAPSE_KHZ 19200
473unsigned long acpuclk_power_collapse(void)
474{
475 int ret = acpuclk_get_rate(smp_processor_id());
476 acpuclk_set_rate(smp_processor_id(), POWER_COLLAPSE_KHZ, SETRATE_PC);
477 return ret;
478}
479
480unsigned long acpuclk_wait_for_irq(void)
481{
482 int rate = acpuclk_get_rate(smp_processor_id());
483 if (rate > MAX_WAIT_FOR_IRQ_KHZ)
484 acpuclk_set_rate(smp_processor_id(), drv_state.wait_for_irq_khz,
485 SETRATE_SWFI);
486 return rate;
487}
488
489static int acpuclk_set_vdd_level(int vdd)
490{
491 uint32_t current_vdd;
492
493 /*
494 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
495 * VDD switching support.
496 */
497 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
498 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
499 return 0;
500
501 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
502
503 pr_debug("Switching VDD from %u mV -> %d mV\n",
504 current_vdd, vdd);
505
506 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
507 mb();
508 udelay(drv_state.vdd_switch_time_us);
509 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
510 pr_err("VDD set failed\n");
511 return -EIO;
512 }
513
514 pr_debug("VDD switched\n");
515
516 return 0;
517}
518
519/* Set proper dividers for the given clock speed. */
520static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
521{
522 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
523
524 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
525
526 /* AHB_CLK_DIV */
527 clk_div = (reg_clksel >> 1) & 0x03;
528 /* CLK_SEL_SRC1NO */
529 src_sel = reg_clksel & 1;
530
531 /*
532 * If the new clock divider is higher than the previous, then
533 * program the divider before switching the clock
534 */
535 if (hunt_s->ahbclk_div > clk_div) {
536 reg_clksel &= ~(0x3 << 1);
537 reg_clksel |= (hunt_s->ahbclk_div << 1);
538 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
539 }
540
541 /* Program clock source and divider */
542 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
543 reg_clkctl &= ~(0xFF << (8 * src_sel));
544 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
545 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
546 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
547
548 /* Program clock source selection */
549 reg_clksel ^= 1;
550 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
551
552 /*
553 * If the new clock divider is lower than the previous, then
554 * program the divider after switching the clock
555 */
556 if (hunt_s->ahbclk_div < clk_div) {
557 reg_clksel &= ~(0x3 << 1);
558 reg_clksel |= (hunt_s->ahbclk_div << 1);
559 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
560 }
561}
562
563int acpuclk_set_rate(int cpu, unsigned long rate, enum setrate_reason reason)
564{
565 uint32_t reg_clkctl;
566 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
567 int res, rc = 0;
568 unsigned int plls_enabled = 0, pll;
569
570 if (reason == SETRATE_CPUFREQ)
571 mutex_lock(&drv_state.lock);
572
573 strt_s = cur_s = drv_state.current_speed;
574
575 WARN_ONCE(cur_s == NULL, "acpuclk_set_rate: not initialized\n");
576 if (cur_s == NULL) {
577 rc = -ENOENT;
578 goto out;
579 }
580
581 if (rate == cur_s->a11clk_khz)
582 goto out;
583
584 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
585 if (tgt_s->a11clk_khz == rate)
586 break;
587 }
588
589 if (tgt_s->a11clk_khz == 0) {
590 rc = -EINVAL;
591 goto out;
592 }
593
594 /* Choose the highest speed at or below 'rate' with same PLL. */
595 if (reason != SETRATE_CPUFREQ
596 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
597 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
598 tgt_s--;
599 }
600
601 if (strt_s->pll != ACPU_PLL_TCXO)
602 plls_enabled |= 1 << strt_s->pll;
603
604 if (reason == SETRATE_CPUFREQ) {
605 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
606 rc = pc_pll_request(tgt_s->pll, 1);
607 if (rc < 0) {
608 pr_err("PLL%d enable failed (%d)\n",
609 tgt_s->pll, rc);
610 goto out;
611 }
612 plls_enabled |= 1 << tgt_s->pll;
613 }
614 }
615 /* Need to do this when coming out of power collapse since some modem
616 * firmwares reset the VDD when the application processor enters power
617 * collapse. */
618 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
619 /* Increase VDD if needed. */
620 if (tgt_s->vdd > cur_s->vdd) {
621 rc = acpuclk_set_vdd_level(tgt_s->vdd);
622 if (rc < 0) {
623 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
624 goto out;
625 }
626 }
627 }
628
629 /* Set wait states for CPU inbetween frequency changes */
630 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
631 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
632 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
633
634 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
635 strt_s->a11clk_khz, tgt_s->a11clk_khz);
636
637 while (cur_s != tgt_s) {
638 /*
639 * Always jump to target freq if within 256mhz, regulardless of
640 * PLL. If differnece is greater, use the predefinied
641 * steppings in the table.
642 */
643 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
644 if (d > drv_state.max_speed_delta_khz) {
645
646 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
647 /* Step up: jump to target PLL as early as
648 * possible so indexing using TCXO (up[-1])
649 * never occurs. */
650 if (likely(cur_s->up[tgt_s->pll]))
651 cur_s = cur_s->up[tgt_s->pll];
652 else
653 cur_s = cur_s->up[cur_s->pll];
654 } else {
655 /* Step down: stay on current PLL as long as
656 * possible so indexing using TCXO (down[-1])
657 * never occurs. */
658 if (likely(cur_s->down[cur_s->pll]))
659 cur_s = cur_s->down[cur_s->pll];
660 else
661 cur_s = cur_s->down[tgt_s->pll];
662 }
663
664 if (cur_s == NULL) { /* This should not happen. */
665 pr_err("No stepping frequencies found. "
666 "strt_s:%u tgt_s:%u\n",
667 strt_s->a11clk_khz, tgt_s->a11clk_khz);
668 rc = -EINVAL;
669 goto out;
670 }
671
672 } else {
673 cur_s = tgt_s;
674 }
675
676 pr_debug("STEP khz = %u, pll = %d\n",
677 cur_s->a11clk_khz, cur_s->pll);
678
679 if (cur_s->pll != ACPU_PLL_TCXO
680 && !(plls_enabled & (1 << cur_s->pll))) {
681 rc = pc_pll_request(cur_s->pll, 1);
682 if (rc < 0) {
683 pr_err("PLL%d enable failed (%d)\n",
684 cur_s->pll, rc);
685 goto out;
686 }
687 plls_enabled |= 1 << cur_s->pll;
688 }
689
690 acpuclk_set_div(cur_s);
691 drv_state.current_speed = cur_s;
692 /* Re-adjust lpj for the new clock speed. */
693 loops_per_jiffy = cur_s->lpj;
694 mb();
695 udelay(drv_state.acpu_switch_time_us);
696 }
697
698 /* Nothing else to do for SWFI. */
699 if (reason == SETRATE_SWFI)
700 goto out;
701
702 /* Change the AXI bus frequency if we can. */
703 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
704 res = clk_set_rate(drv_state.ebi1_clk,
705 tgt_s->axiclk_khz * 1000);
706 if (res < 0)
707 pr_warning("Setting AXI min rate failed (%d)\n", res);
708 }
709
710 /* Disable PLLs we are not using anymore. */
711 if (tgt_s->pll != ACPU_PLL_TCXO)
712 plls_enabled &= ~(1 << tgt_s->pll);
713 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
714 if (plls_enabled & (1 << pll)) {
715 res = pc_pll_request(pll, 0);
716 if (res < 0)
717 pr_warning("PLL%d disable failed (%d)\n",
718 pll, res);
719 }
720
721 /* Nothing else to do for power collapse. */
722 if (reason == SETRATE_PC)
723 goto out;
724
725 /* Drop VDD level if we can. */
726 if (tgt_s->vdd < strt_s->vdd) {
727 res = acpuclk_set_vdd_level(tgt_s->vdd);
728 if (res < 0)
729 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
730 }
731
732 pr_debug("ACPU speed change complete\n");
733out:
734 if (reason == SETRATE_CPUFREQ)
735 mutex_unlock(&drv_state.lock);
736 return rc;
737}
738
739static void __init acpuclk_init(void)
740{
741 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530742 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700743 int res;
744
745 /*
746 * Determine the rate of ACPU clock
747 */
748
749 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
750 /* CLK_SRC0_SEL */
751 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
752 /* CLK_SRC0_DIV */
753 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
754 } else {
755 /* CLK_SRC1_SEL */
756 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
757 /* CLK_SRC1_DIV */
758 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
759 }
760
761 /* Accomodate bootloaders that might not be implementing the
762 * workaround for the h/w bug in 7x25. */
763 if (cpu_is_msm7x25() && sel == 2)
764 sel = 3;
765
766 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
767 if (speed->a11clk_src_sel == sel
768 && (speed->a11clk_src_div == div))
769 break;
770 }
771 if (speed->a11clk_khz == 0) {
772 pr_err("Error - ACPU clock reports invalid speed\n");
773 return;
774 }
775
776 drv_state.current_speed = speed;
777 if (speed->pll != ACPU_PLL_TCXO)
778 if (pc_pll_request(speed->pll, 1))
779 pr_warning("Failed to vote for boot PLL\n");
780
Trilok Soni7d6c8652011-07-14 15:35:07 +0530781 /* Fix div2 to 2 for 7x27/5a(aa) targets */
782 if (!cpu_is_msm7x27()) {
783 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
784 reg_clksel &= ~(0x3 << 14);
785 reg_clksel |= (0x1 << 14);
786 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
787 }
788
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700789 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
790 if (res < 0)
791 pr_warning("Setting AXI min rate failed (%d)\n", res);
792 res = clk_enable(drv_state.ebi1_clk);
793 if (res < 0)
794 pr_warning("Enabling AXI clock failed (%d)\n", res);
795
796 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
797}
798
799unsigned long acpuclk_get_rate(int cpu)
800{
801 WARN_ONCE(drv_state.current_speed == NULL,
802 "acpuclk_get_rate: not initialized\n");
803 if (drv_state.current_speed)
804 return drv_state.current_speed->a11clk_khz;
805 else
806 return 0;
807}
808
809uint32_t acpuclk_get_switch_time(void)
810{
811 return drv_state.acpu_switch_time_us;
812}
813
814/*----------------------------------------------------------------------------
815 * Clock driver initialization
816 *---------------------------------------------------------------------------*/
817
818#define DIV2REG(n) ((n)-1)
819#define REG2DIV(n) ((n)+1)
820#define SLOWER_BY(div, factor) div = DIV2REG(REG2DIV(div) * factor)
821
822static void __init acpu_freq_tbl_fixup(void)
823{
824 unsigned long pll0_l, pll1_l, pll2_l, pll4_l;
825 int axi_160mhz = 0, axi_200mhz = 0;
826 struct pll_freq_tbl_map *lst;
827 struct clkctl_acpu_speed *t;
828 unsigned int pll0_needs_fixup = 0;
829
830 /* Wait for the PLLs to be initialized and then read their frequency.
831 */
832 do {
833 pll0_l = readl_relaxed(PLLn_L_VAL(0)) &
834 soc_pll[ACPU_PLL_0].l_val_mask;
835 cpu_relax();
836 udelay(50);
837 } while (pll0_l == 0);
838 do {
839 pll1_l = readl_relaxed(PLLn_L_VAL(1)) &
840 soc_pll[ACPU_PLL_1].l_val_mask;
841 cpu_relax();
842 udelay(50);
843 } while (pll1_l == 0);
844 do {
845 pll2_l = readl_relaxed(PLLn_L_VAL(2)) &
846 soc_pll[ACPU_PLL_2].l_val_mask;
847 cpu_relax();
848 udelay(50);
849 } while (pll2_l == 0);
850
851 pr_info("L val: PLL0: %d, PLL1: %d, PLL2: %d\n",
852 (int)pll0_l, (int)pll1_l, (int)pll2_l);
853
854 if (!cpu_is_msm7x27() && !cpu_is_msm7x25a()) {
855 do {
856 pll4_l = readl_relaxed(PLL4_L_VAL) &
857 soc_pll[ACPU_PLL_4].l_val_mask;
858 cpu_relax();
859 udelay(50);
860 } while (pll4_l == 0);
861 pr_info("L val: PLL4: %d\n", (int)pll4_l);
862 } else {
863 pll4_l = 0;
864 }
865
866 /* Some configurations run PLL0 twice as fast. Instead of having
867 * separate tables for this case, we simply fix up the ACPU clock
868 * source divider since it's a simple fix up.
869 */
870 if (pll0_l == PLL_491_MHZ) {
871 pll0_l = PLL_245_MHZ;
872 pll0_needs_fixup = 1;
873 }
874
Trilok Soni54d35c42011-07-14 17:47:50 +0530875 /* Fix the tables for 7x25a variant to not conflict with 7x27 ones */
876 if (cpu_is_msm7x25a()) {
877 if (pll1_l == PLL_245_MHZ) {
878 acpu_freq_tbl =
879 pll0_960_pll1_245_pll2_1200_pll4_800_25a;
880 }
881 } else {
882 /* Select the right table to use. */
883 for (lst = acpu_freq_tbl_list; lst->tbl != 0; lst++) {
884 if (lst->pll0_l == pll0_l && lst->pll1_l == pll1_l
885 && lst->pll2_l == pll2_l
886 && lst->pll4_l == pll4_l) {
887 acpu_freq_tbl = lst->tbl;
888 break;
889 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700890 }
891 }
892
893 if (acpu_freq_tbl == NULL) {
894 pr_crit("Unknown PLL configuration!\n");
895 BUG();
896 }
897
898 /* Fix up PLL0 source divider if necessary. Also, fix up the AXI to
899 * the max that's supported by the board (RAM used in board).
900 */
901 axi_160mhz = (pll0_l == PLL_960_MHZ || pll1_l == PLL_960_MHZ);
902 axi_200mhz = (pll2_l == PLL_1200_MHZ || pll2_l == PLL_800_MHZ);
903 for (t = &acpu_freq_tbl[0]; t->a11clk_khz != 0; t++) {
904
905 if (pll0_needs_fixup && t->pll == ACPU_PLL_0)
906 SLOWER_BY(t->a11clk_src_div, 2);
907 if (axi_160mhz && drv_state.max_axi_khz >= 160000
908 && t->ahbclk_khz > 128000)
909 t->axiclk_khz = 160000;
910 if (axi_200mhz && drv_state.max_axi_khz >= 200000
911 && t->ahbclk_khz > 160000)
912 t->axiclk_khz = 200000;
913 }
914
915 t--;
916 drv_state.max_axi_khz = t->axiclk_khz;
917
918 /* The default 7x27 ACPU clock plan supports running the AXI bus at
919 * 200 MHz. So we don't classify it as Turbo mode.
920 */
921 if (cpu_is_msm7x27())
922 return;
923
924 if (!axi_160mhz)
925 pr_info("Turbo mode not supported.\n");
926 else if (t->axiclk_khz == 160000)
927 pr_info("Turbo mode supported and enabled.\n");
928 else
929 pr_info("Turbo mode supported but not enabled.\n");
930}
931
932/*
933 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
934 * before entering a wait for irq low-power mode. Find a suitable rate.
935 */
936static unsigned long __init find_wait_for_irq_khz(void)
937{
938 unsigned long found_khz = 0;
939 int i;
940
941 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
942 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
943 found_khz = acpu_freq_tbl[i].a11clk_khz;
944
945 return found_khz;
946}
947
948/* Initalize the lpj field in the acpu_freq_tbl. */
949static void __init lpj_init(void)
950{
951 int i;
952 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
953 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
954 acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy,
955 base_clk->a11clk_khz,
956 acpu_freq_tbl[i].a11clk_khz);
957 }
958}
959
960static void __init precompute_stepping(void)
961{
962 int i, step_idx;
963
964#define cur_freq acpu_freq_tbl[i].a11clk_khz
965#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
966#define cur_pll acpu_freq_tbl[i].pll
967#define step_pll acpu_freq_tbl[step_idx].pll
968
969 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
970
971 /* Calculate max "up" step for each destination PLL */
972 step_idx = i + 1;
973 while (step_freq && (step_freq - cur_freq)
974 <= drv_state.max_speed_delta_khz) {
975 acpu_freq_tbl[i].up[step_pll] =
976 &acpu_freq_tbl[step_idx];
977 step_idx++;
978 }
979 if (step_idx == (i + 1) && step_freq) {
980 pr_crit("Delta between freqs %u KHz and %u KHz is"
981 " too high!\n", cur_freq, step_freq);
982 BUG();
983 }
984
985 /* Calculate max "down" step for each destination PLL */
986 step_idx = i - 1;
987 while (step_idx >= 0 && (cur_freq - step_freq)
988 <= drv_state.max_speed_delta_khz) {
989 acpu_freq_tbl[i].down[step_pll] =
990 &acpu_freq_tbl[step_idx];
991 step_idx--;
992 }
993 if (step_idx == (i - 1) && i > 0) {
994 pr_crit("Delta between freqs %u KHz and %u KHz is"
995 " too high!\n", cur_freq, step_freq);
996 BUG();
997 }
998 }
999}
1000
1001static void __init print_acpu_freq_tbl(void)
1002{
1003 struct clkctl_acpu_speed *t;
1004 short down_idx[ACPU_PLL_END];
1005 short up_idx[ACPU_PLL_END];
1006 int i, j;
1007
1008#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
1009 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
1010 "D0 D1 D2 D4 U0 U1 U2 U4\n");
1011
1012 t = &acpu_freq_tbl[0];
1013 for (i = 0; t->a11clk_khz != 0; i++) {
1014
1015 for (j = 0; j < ACPU_PLL_END; j++) {
1016 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
1017 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
1018 }
1019
1020 pr_info("%2d %7d %3d %3d %7d %4d %7d "
1021 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
1022 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
1023 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
1024 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
1025 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
1026
1027 t++;
1028 }
1029}
1030
1031static void msm7x25_acpu_pll_hw_bug_fix(void)
1032{
1033 unsigned int n;
1034
1035 /* The 7625 has a hardware bug and in order to select PLL2 we
1036 * must program PLL3. Use the same table, and just fix up the
1037 * numbers on this target. */
1038 for (n = 0; acpu_freq_tbl[n].a11clk_khz != 0; n++)
1039 if (acpu_freq_tbl[n].pll == ACPU_PLL_2)
1040 acpu_freq_tbl[n].a11clk_src_sel = 3;
1041}
1042
1043static void shared_pll_control_init(void)
1044{
1045#define PLL_REMOTE_SPINLOCK_ID "S:7"
1046 unsigned smem_size;
1047 remote_spin_lock_init(&pll_lock, PLL_REMOTE_SPINLOCK_ID);
1048 pll_control = smem_get_entry(SMEM_CLKREGIM_SOURCES, &smem_size);
1049
1050 if (!pll_control)
1051 pr_warning("Can't find shared PLL control data structure!\n");
1052 /* There might be more PLLs than what the application processor knows
1053 * about. But the index used for each PLL is guaranteed to remain the
1054 * same. */
1055 else if (smem_size < sizeof(struct shared_pll_control))
1056 pr_warning("Shared PLL control data structure too small!\n");
1057 else if (pll_control->version != 0xCCEE0001)
1058 pr_warning("Shared PLL control version mismatch!\n");
1059 else {
1060 pr_info("Shared PLL control available.\n");
1061 return;
1062 }
1063
1064 pll_control = NULL;
1065 pr_warning("Falling back to proc_comm PLL control.\n");
1066}
1067
1068void __init msm_acpu_clock_init(struct msm_acpu_clock_platform_data *clkdata)
1069{
1070 pr_info("acpu_clock_init()\n");
1071
1072 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
1073 BUG_ON(IS_ERR(drv_state.ebi1_clk));
1074
1075 mutex_init(&drv_state.lock);
1076 shared_pll_control_init();
1077 drv_state.acpu_switch_time_us = clkdata->acpu_switch_time_us;
1078 drv_state.max_speed_delta_khz = clkdata->max_speed_delta_khz;
1079 drv_state.vdd_switch_time_us = clkdata->vdd_switch_time_us;
1080 drv_state.max_axi_khz = clkdata->max_axi_khz;
1081 acpu_freq_tbl_fixup();
1082 drv_state.wait_for_irq_khz = find_wait_for_irq_khz();
1083 precompute_stepping();
1084 if (cpu_is_msm7x25())
1085 msm7x25_acpu_pll_hw_bug_fix();
1086 acpuclk_init();
1087 lpj_init();
1088 print_acpu_freq_tbl();
1089#ifdef CONFIG_CPU_FREQ_MSM
1090 cpufreq_table_init();
1091 cpufreq_frequency_table_get_attr(freq_table, smp_processor_id());
1092#endif
1093}