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