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