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