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