blob: 87c504771975c98d818f1d2aca95d8744969a560 [file] [log] [blame]
Stephen Boydaefb8de2012-01-05 19:05:01 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#define pr_fmt(fmt) "%s: " fmt, __func__
14
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/io.h>
18#include <linux/delay.h>
19#include <linux/mutex.h>
20#include <linux/err.h>
21#include <linux/errno.h>
22#include <linux/cpufreq.h>
23#include <linux/cpu.h>
24#include <linux/regulator/consumer.h>
25
26#include <asm/mach-types.h>
27#include <asm/cpu.h>
28
29#include <mach/board.h>
30#include <mach/msm_iomap.h>
31#include <mach/rpm-regulator.h>
32#include <mach/msm_bus.h>
33#include <mach/msm_bus_board.h>
34#include <mach/socinfo.h>
Stephen Boyd469ed3e2011-09-29 16:41:19 -070035#include <mach/msm-krait-l2-accessors.h>
Matt Wagantallcb12c392011-10-19 10:32:07 -070036#include <mach/rpm-regulator.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38#include "acpuclock.h"
39
40/*
41 * Source IDs.
42 * These must be negative to not overlap with the source IDs
43 * used by the 8x60 local clock driver.
44 */
45#define PLL_8 0
46#define HFPLL -1
47#define QSB -2
48
49/* Mux source selects. */
50#define PRI_SRC_SEL_SEC_SRC 0
51#define PRI_SRC_SEL_HFPLL 1
52#define PRI_SRC_SEL_HFPLL_DIV2 2
53#define SEC_SRC_SEL_QSB 0
Matt Wagantall65e5e4b2011-10-27 16:52:10 -070054#define SEC_SRC_SEL_AUX 2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055
56/* HFPLL registers offsets. */
57#define HFPLL_MODE 0x00
58#define HFPLL_CONFIG_CTL 0x04
59#define HFPLL_L_VAL 0x08
60#define HFPLL_M_VAL 0x0C
61#define HFPLL_N_VAL 0x10
62#define HFPLL_DROOP_CTL 0x14
63
64/* CP15 L2 indirect addresses. */
65#define L2CPMR_IADDR 0x500
66#define L2CPUCPMR_IADDR 0x501
67
68#define STBY_KHZ 1
69
70#define HFPLL_NOMINAL_VDD 1050000
Stephen Boyd9d0fab12011-12-08 10:56:06 -080071#define HFPLL_LOW_VDD 850000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
73
74#define SECCLKAGD BIT(4)
75
Matt Wagantalla518f8f2011-10-17 13:24:53 -070076/* PTE EFUSE register. */
77#define QFPROM_PTE_EFUSE_ADDR (MSM_QFPROM_BASE + 0x00C0)
78
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070079enum scalables {
80 CPU0 = 0,
81 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070082 CPU2,
83 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084 L2,
85 NUM_SCALABLES
86};
87
88enum vregs {
89 VREG_CORE,
90 VREG_MEM,
91 VREG_DIG,
Matt Wagantallcb12c392011-10-19 10:32:07 -070092 VREG_HFPLL_A,
93 VREG_HFPLL_B,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094 NUM_VREG
95};
96
97struct vreg {
98 const char name[15];
99 const unsigned int max_vdd;
100 const int rpm_vreg_voter;
101 const int rpm_vreg_id;
102 struct regulator *reg;
103 unsigned int cur_vdd;
104};
105
106struct core_speed {
107 unsigned int khz;
108 int src;
109 unsigned int pri_src_sel;
110 unsigned int sec_src_sel;
111 unsigned int pll_l_val;
112};
113
114struct l2_level {
115 struct core_speed speed;
116 unsigned int vdd_dig;
117 unsigned int vdd_mem;
118 unsigned int bw_level;
119};
120
121struct acpu_level {
122 unsigned int use_for_scaling;
123 struct core_speed speed;
124 struct l2_level *l2_level;
125 unsigned int vdd_core;
126};
127
128struct scalable {
129 void * __iomem const hfpll_base;
130 void * __iomem const aux_clk_sel;
131 const uint32_t l2cpmr_iaddr;
132 struct core_speed *current_speed;
133 struct l2_level *l2_vote;
134 struct vreg vreg[NUM_VREG];
135 bool first_set_call;
136};
137
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700138static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139 [CPU0] = {
140 .hfpll_base = MSM_HFPLL_BASE + 0x200,
141 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
142 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800143 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
145 RPM_VREG_VOTER1,
146 RPM_VREG_ID_PM8921_L24 },
147 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
148 RPM_VREG_VOTER1,
149 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall627f4312011-12-13 13:33:47 -0800150 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700151 RPM_VREG_VOTER1,
152 RPM_VREG_ID_PM8921_S8 },
153 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
154 RPM_VREG_VOTER1,
155 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700156 },
157 [CPU1] = {
158 .hfpll_base = MSM_HFPLL_BASE + 0x300,
159 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
160 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800161 .vreg[VREG_CORE] = { "krait1", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
163 RPM_VREG_VOTER2,
164 RPM_VREG_ID_PM8921_L24 },
165 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
166 RPM_VREG_VOTER2,
167 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall627f4312011-12-13 13:33:47 -0800168 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700169 RPM_VREG_VOTER2,
170 RPM_VREG_ID_PM8921_S8 },
171 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
172 RPM_VREG_VOTER2,
173 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 },
175 [L2] = {
176 .hfpll_base = MSM_HFPLL_BASE + 0x400,
177 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
178 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantall627f4312011-12-13 13:33:47 -0800179 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700180 RPM_VREG_VOTER6,
181 RPM_VREG_ID_PM8921_S8 },
182 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
183 RPM_VREG_VOTER6,
184 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 },
186};
187
Stephen Boyd7ad84752011-08-05 14:04:28 -0700188static DEFINE_MUTEX(driver_lock);
189static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700191static struct scalable scalable_8064[] = {
192 [CPU0] = {
193 .hfpll_base = MSM_HFPLL_BASE + 0x200,
194 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
195 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
196 .vreg[VREG_CORE] = { "krait0", 1150000 },
197 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
198 RPM_VREG_VOTER1,
199 RPM_VREG_ID_PM8921_L24 },
200 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
201 RPM_VREG_VOTER1,
202 RPM_VREG_ID_PM8921_S3 },
203 },
204 [CPU1] = {
205 .hfpll_base = MSM_HFPLL_BASE + 0x240,
206 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
207 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
208 .vreg[VREG_CORE] = { "krait1", 1150000 },
209 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
210 RPM_VREG_VOTER2,
211 RPM_VREG_ID_PM8921_L24 },
212 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
213 RPM_VREG_VOTER2,
214 RPM_VREG_ID_PM8921_S3 },
215 },
216 [CPU2] = {
217 .hfpll_base = MSM_HFPLL_BASE + 0x280,
218 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
219 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
220 .vreg[VREG_CORE] = { "krait2", 1150000 },
221 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
222 RPM_VREG_VOTER4,
223 RPM_VREG_ID_PM8921_L24 },
224 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
225 RPM_VREG_VOTER4,
226 RPM_VREG_ID_PM8921_S3 },
227 },
228 [CPU3] = {
229 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
230 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
231 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
232 .vreg[VREG_CORE] = { "krait3", 1150000 },
233 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
234 RPM_VREG_VOTER5,
235 RPM_VREG_ID_PM8921_L24 },
236 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
237 RPM_VREG_VOTER5,
238 RPM_VREG_ID_PM8921_S3 },
239 },
240 [L2] = {
241 .hfpll_base = MSM_HFPLL_BASE + 0x300,
242 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
243 .l2cpmr_iaddr = L2CPMR_IADDR,
244 },
245};
246
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800247/*TODO: Update the rpm vreg id when the rpm driver is ready */
248static struct scalable scalable_8930[] = {
249 [CPU0] = {
250 .hfpll_base = MSM_HFPLL_BASE + 0x200,
251 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
252 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
253 .vreg[VREG_CORE] = { "krait0", 1300000 },
254 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
255 RPM_VREG_VOTER1,
256 RPM_VREG_ID_PM8921_L24 },
257 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
258 RPM_VREG_VOTER1,
259 RPM_VREG_ID_PM8921_S3 },
260 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
261 RPM_VREG_VOTER1,
262 RPM_VREG_ID_PM8921_S8 },
263 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
264 RPM_VREG_VOTER1,
265 RPM_VREG_ID_PM8921_L23 },
266 },
267 [CPU1] = {
268 .hfpll_base = MSM_HFPLL_BASE + 0x300,
269 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
270 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
271 .vreg[VREG_CORE] = { "krait1", 1300000 },
272 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
273 RPM_VREG_VOTER2,
274 RPM_VREG_ID_PM8921_L24 },
275 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
276 RPM_VREG_VOTER2,
277 RPM_VREG_ID_PM8921_S3 },
278 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
279 RPM_VREG_VOTER2,
280 RPM_VREG_ID_PM8921_S8 },
281 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
282 RPM_VREG_VOTER2,
283 RPM_VREG_ID_PM8921_L23 },
284 },
285 [L2] = {
286 .hfpll_base = MSM_HFPLL_BASE + 0x400,
287 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
288 .l2cpmr_iaddr = L2CPMR_IADDR,
289 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
290 RPM_VREG_VOTER6,
291 RPM_VREG_ID_PM8921_S8 },
292 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
293 RPM_VREG_VOTER6,
294 RPM_VREG_ID_PM8921_L23 },
295 },
296};
297
Tianyi Goue0b34de2011-12-20 11:20:10 -0800298/*TODO: Update the rpm vreg id when the rpm driver is ready */
299static struct scalable scalable_8627[] = {
300 [CPU0] = {
301 .hfpll_base = MSM_HFPLL_BASE + 0x200,
302 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
303 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
304 .vreg[VREG_CORE] = { "krait0", 1300000 },
305 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
306 RPM_VREG_VOTER1,
307 RPM_VREG_ID_PM8921_L24 },
308 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
309 RPM_VREG_VOTER1,
310 RPM_VREG_ID_PM8921_S3 },
311 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
312 RPM_VREG_VOTER1,
313 RPM_VREG_ID_PM8921_S8 },
314 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
315 RPM_VREG_VOTER1,
316 RPM_VREG_ID_PM8921_L23 },
317 },
318 [CPU1] = {
319 .hfpll_base = MSM_HFPLL_BASE + 0x300,
320 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
321 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
322 .vreg[VREG_CORE] = { "krait1", 1300000 },
323 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
324 RPM_VREG_VOTER2,
325 RPM_VREG_ID_PM8921_L24 },
326 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
327 RPM_VREG_VOTER2,
328 RPM_VREG_ID_PM8921_S3 },
329 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
330 RPM_VREG_VOTER2,
331 RPM_VREG_ID_PM8921_S8 },
332 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
333 RPM_VREG_VOTER2,
334 RPM_VREG_ID_PM8921_L23 },
335 },
336 [L2] = {
337 .hfpll_base = MSM_HFPLL_BASE + 0x400,
338 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
339 .l2cpmr_iaddr = L2CPMR_IADDR,
340 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
341 RPM_VREG_VOTER6,
342 RPM_VREG_ID_PM8921_S8 },
343 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
344 RPM_VREG_VOTER6,
345 RPM_VREG_ID_PM8921_L23 },
346 },
347};
348
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700349static struct scalable *scalable;
350static struct l2_level *l2_freq_tbl;
351static struct acpu_level *acpu_freq_tbl;
352static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700353
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700354/* Instantaneous bandwidth requests in MB/s. */
355#define BW_MBPS(_bw) \
356 { \
357 .vectors = (struct msm_bus_vectors[]){ \
358 {\
359 .src = MSM_BUS_MASTER_AMPSS_M0, \
360 .dst = MSM_BUS_SLAVE_EBI_CH0, \
361 .ib = (_bw) * 1000000UL, \
362 .ab = (_bw) * 100000UL, \
363 }, \
364 { \
365 .src = MSM_BUS_MASTER_AMPSS_M1, \
366 .dst = MSM_BUS_SLAVE_EBI_CH0, \
367 .ib = (_bw) * 1000000UL, \
368 .ab = (_bw) * 100000UL, \
369 }, \
370 }, \
371 .num_paths = 2, \
372 }
373static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800374 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
375 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
376 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
377 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
378 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
379 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
380 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700381};
382
383static struct msm_bus_scale_pdata bus_client_pdata = {
384 .usecase = bw_level_tbl,
385 .num_usecases = ARRAY_SIZE(bw_level_tbl),
386 .active_only = 1,
387 .name = "acpuclock",
388};
389
390static uint32_t bus_perf_client;
391
392/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800393#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
394static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700395 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700396 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700397 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
398 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
399 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
400 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
401 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
402 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700403 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
405 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
406 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700407};
408
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800409static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
410 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
411 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
412 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
413 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
414 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
415 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
416 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
417 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
418 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
419 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
420 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
421 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
422 { 0, { 0 } }
423};
424
425static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
426 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
427 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
428 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
429 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
430 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
431 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
432 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
433 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
434 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
435 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
436 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
437 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700438 { 0, { 0 } }
439};
440
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800441#undef L2
442#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
443static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
444 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
445 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800446 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
447 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
448 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800449 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800450 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
451 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
452 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
453 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
454 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
455 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
456 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
457 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
458 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
459 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
460 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800461 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
462 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
463 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800464};
465
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800466static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800467 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
468 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
469 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 975000 },
470 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 975000 },
471 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 1000000 },
472 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
473 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
474 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1025000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800475 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1075000 },
476 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1075000 },
477 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
478 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1100000 },
479 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1125000 },
480 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800481 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
482 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
483 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
484 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1200000 },
485 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1225000 },
486 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1225000 },
487 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1237500 },
488 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1237500 },
489 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800490 { 0, { 0 } }
491};
492
493static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800494 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
495 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
496 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
497 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
498 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 950000 },
499 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 950000 },
500 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 975000 },
501 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 975000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800502 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800503 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1025000 },
504 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1050000 },
505 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1050000 },
506 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1075000 },
507 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800508 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
509 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
510 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
511 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1150000 },
512 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1175000 },
513 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1175000 },
514 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1187500 },
515 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1187500 },
516 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800517 { 0, { 0 } }
518};
519
Stephen Boyd5766f682011-12-27 19:21:08 -0800520static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800521 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
522 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
523 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 875000 },
524 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 875000 },
525 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
526 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 900000 },
527 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
528 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 925000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800529 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 975000 },
530 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 975000 },
531 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1000000 },
532 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1000000 },
533 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1025000 },
534 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1025000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800535 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
536 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
537 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
538 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1100000 },
539 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1125000 },
540 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1125000 },
541 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1137500 },
542 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1137500 },
543 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800544 { 0, { 0 } }
545};
546
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700547/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
548#undef L2
549#define L2(x) (&l2_freq_tbl_8064[(x)])
550static struct l2_level l2_freq_tbl_8064[] = {
551 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
552 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
553 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
554 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
555 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
556 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
557 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
558 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
559 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
560 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
561 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
562 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
563 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
564 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
565 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
566 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
567 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
568 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
569 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
570 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
571 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
572 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
573 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
574 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
575 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
576 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
577};
578
579/* TODO: Update core voltages when data is available. */
580static struct acpu_level acpu_freq_tbl_8064[] = {
581 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
582 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
583 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
584 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
585 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
586 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
587 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
588 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
589 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
590 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
591 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
592 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
593 { 0, { 0 } }
594};
595
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800596/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
597#undef L2
598#define L2(x) (&l2_freq_tbl_8930[(x)])
599static struct l2_level l2_freq_tbl_8930[] = {
600 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
601 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
602 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
603 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
604 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
605 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
606 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
607 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
608 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
609 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
610 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
611 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
612 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
613 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
614 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
615 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
616 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
617};
618
619/* TODO: Update core voltages when data is available. */
620static struct acpu_level acpu_freq_tbl_8930[] = {
621 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
622 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
623 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
624 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
625 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
626 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
627 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
628 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
629 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
630 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
631 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
632 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
633 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
634 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
635 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
636 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
637 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
638 { 0, { 0 } }
639};
640
Tianyi Goue0b34de2011-12-20 11:20:10 -0800641/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
642#undef L2
643#define L2(x) (&l2_freq_tbl_8627[(x)])
644static struct l2_level l2_freq_tbl_8627[] = {
645 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
646 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
647 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
648 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
649 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
650 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
651 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
652 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 3 },
653 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
654 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
655 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
656 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 4 },
657 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 4 },
658};
659
660/* TODO: Update core voltages when data is available. */
661static struct acpu_level acpu_freq_tbl_8627[] = {
662 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
663 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
664 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
665 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
666 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
667 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
668 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
669 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
670 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
671 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
672 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
673 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
674 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
675 { 0, { 0 } }
676};
677
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700678static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700679{
680 return scalable[cpu].current_speed->khz;
681}
682
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700683/* Get the selected source on primary MUX. */
684static int get_pri_clk_src(struct scalable *sc)
685{
686 uint32_t regval;
687
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700688 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700689 return regval & 0x3;
690}
691
692/* Set the selected source on primary MUX. */
693static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
694{
695 uint32_t regval;
696
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700697 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698 regval &= ~0x3;
699 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700700 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700701 /* Wait for switch to complete. */
702 mb();
703 udelay(1);
704}
705
706/* Get the selected source on secondary MUX. */
707static int get_sec_clk_src(struct scalable *sc)
708{
709 uint32_t regval;
710
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700711 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700712 return (regval >> 2) & 0x3;
713}
714
715/* Set the selected source on secondary MUX. */
716static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
717{
718 uint32_t regval;
719
720 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700721 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700722 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700723 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700724
725 /* Program the MUX. */
726 regval &= ~(0x3 << 2);
727 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700728 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700729
730 /* Wait for switch to complete. */
731 mb();
732 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700733
734 /* Re-enable secondary source clock gating. */
735 regval &= ~SECCLKAGD;
736 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700737}
738
739/* Enable an already-configured HFPLL. */
740static void hfpll_enable(struct scalable *sc)
741{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700742 int rc;
743
Tianyi Goue0b34de2011-12-20 11:20:10 -0800744 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm8627()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700745 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
Matt Wagantall627f4312011-12-13 13:33:47 -0800746 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 2100000,
747 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700748 if (rc)
749 pr_err("%s regulator enable failed (%d)\n",
750 sc->vreg[VREG_HFPLL_A].name, rc);
751 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
752 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
Matt Wagantall627f4312011-12-13 13:33:47 -0800753 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700754 if (rc)
755 pr_err("%s regulator enable failed (%d)\n",
756 sc->vreg[VREG_HFPLL_B].name, rc);
757 }
758
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700759 /* Disable PLL bypass mode. */
760 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
761
762 /*
763 * H/W requires a 5us delay between disabling the bypass and
764 * de-asserting the reset. Delay 10us just to be safe.
765 */
766 mb();
767 udelay(10);
768
769 /* De-assert active-low PLL reset. */
770 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
771
772 /* Wait for PLL to lock. */
773 mb();
774 udelay(60);
775
776 /* Enable PLL output. */
777 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
778}
779
780/* Disable a HFPLL for power-savings or while its being reprogrammed. */
781static void hfpll_disable(struct scalable *sc)
782{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700783 int rc;
784
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700785 /*
786 * Disable the PLL output, disable test mode, enable
787 * the bypass mode, and assert the reset.
788 */
789 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700790
Tianyi Goue0b34de2011-12-20 11:20:10 -0800791 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm8627()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700792 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
793 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
794 0, 0);
795 if (rc)
796 pr_err("%s regulator enable failed (%d)\n",
797 sc->vreg[VREG_HFPLL_B].name, rc);
798 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
799 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 0,
800 0, 0);
801 if (rc)
802 pr_err("%s regulator enable failed (%d)\n",
803 sc->vreg[VREG_HFPLL_A].name, rc);
804 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700805}
806
807/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
808static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
809{
810 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
811}
812
813/* Return the L2 speed that should be applied. */
814static struct l2_level *compute_l2_level(struct scalable *sc,
815 struct l2_level *vote_l)
816{
817 struct l2_level *new_l;
818 int cpu;
819
820 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700821 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700822
823 /* Find max L2 speed vote. */
824 sc->l2_vote = vote_l;
825 new_l = l2_freq_tbl;
826 for_each_present_cpu(cpu)
827 new_l = max(new_l, scalable[cpu].l2_vote);
828
829 return new_l;
830}
831
832/* Update the bus bandwidth request. */
833static void set_bus_bw(unsigned int bw)
834{
835 int ret;
836
837 /* Bounds check. */
838 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
839 pr_err("invalid bandwidth request (%d)\n", bw);
840 return;
841 }
842
843 /* Update bandwidth if request has changed. This may sleep. */
844 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
845 if (ret)
846 pr_err("bandwidth request failed (%d)\n", ret);
847}
848
849/* Set the CPU or L2 clock speed. */
850static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
851 enum setrate_reason reason)
852{
853 struct core_speed *strt_s = sc->current_speed;
854
855 if (tgt_s == strt_s)
856 return;
857
858 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700859 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700860 * Move to an always-on source running at a frequency that does
861 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700863 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
865
866 /* Program CPU HFPLL. */
867 hfpll_disable(sc);
868 hfpll_set_rate(sc, tgt_s);
869 hfpll_enable(sc);
870
871 /* Move CPU to HFPLL source. */
872 set_pri_clk_src(sc, tgt_s->pri_src_sel);
873 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 /*
875 * If responding to CPU_DEAD we must be running on another
876 * CPU. Therefore, we can't access the downed CPU's CP15
877 * clock MUX registers from here and can't change clock sources.
878 * Just turn off the PLL- since the CPU is down already, halting
879 * its clock should be safe.
880 */
881 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
882 set_sec_clk_src(sc, tgt_s->sec_src_sel);
883 set_pri_clk_src(sc, tgt_s->pri_src_sel);
884 }
885 hfpll_disable(sc);
886 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
887 hfpll_set_rate(sc, tgt_s);
888 hfpll_enable(sc);
889 /*
890 * If responding to CPU_UP_PREPARE, we can't change CP15
891 * registers for the CPU that's coming up since we're not
892 * running on that CPU. That's okay though, since the MUX
893 * source was not changed on the way down, either.
894 */
895 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
896 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700898 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
899 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700900 }
901
902 sc->current_speed = tgt_s;
903}
904
905/* Apply any per-cpu voltage increases. */
906static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
907 unsigned int vdd_dig, enum setrate_reason reason)
908{
909 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700910 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911
912 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700913 * Increase vdd_mem active-set before vdd_dig.
914 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700915 */
916 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
917 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
918 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
919 sc->vreg[VREG_MEM].max_vdd, 0);
920 if (rc) {
921 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
922 __func__, cpu, rc);
923 return rc;
924 }
925 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
926 }
927
928 /* Increase vdd_dig active-set vote. */
929 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
930 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
931 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
932 sc->vreg[VREG_DIG].max_vdd, 0);
933 if (rc) {
934 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
935 __func__, cpu, rc);
936 return rc;
937 }
938 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
939 }
940
941 /*
942 * Update per-CPU core voltage. Don't do this for the hotplug path for
943 * which it should already be correct. Attempting to set it is bad
944 * because we don't know what CPU we are running on at this point, but
945 * the CPU regulator API requires we call it from the affected CPU.
946 */
947 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
948 && reason != SETRATE_HOTPLUG) {
949 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
950 sc->vreg[VREG_CORE].max_vdd);
951 if (rc) {
952 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
953 __func__, cpu, rc);
954 return rc;
955 }
956 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
957 }
958
959 return rc;
960}
961
962/* Apply any per-cpu voltage decreases. */
963static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
964 unsigned int vdd_dig, enum setrate_reason reason)
965{
966 struct scalable *sc = &scalable[cpu];
967 int ret;
968
969 /*
970 * Update per-CPU core voltage. This must be called on the CPU
971 * that's being affected. Don't do this in the hotplug remove path,
972 * where the rail is off and we're executing on the other CPU.
973 */
974 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
975 && reason != SETRATE_HOTPLUG) {
976 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
977 sc->vreg[VREG_CORE].max_vdd);
978 if (ret) {
979 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
980 __func__, cpu, ret);
981 return;
982 }
983 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
984 }
985
986 /* Decrease vdd_dig active-set vote. */
987 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
988 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
989 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
990 sc->vreg[VREG_DIG].max_vdd, 0);
991 if (ret) {
992 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
993 __func__, cpu, ret);
994 return;
995 }
996 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
997 }
998
999 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001000 * Decrease vdd_mem active-set after vdd_dig.
1001 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001002 */
1003 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1004 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1005 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1006 sc->vreg[VREG_MEM].max_vdd, 0);
1007 if (ret) {
1008 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
1009 __func__, cpu, ret);
1010 return;
1011 }
1012 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1013 }
1014}
1015
1016static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1017{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001018 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001019}
1020
1021static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1022{
1023 unsigned int pll_vdd_dig;
1024
Stephen Boydc76158f2011-12-08 12:42:40 -08001025 if (tgt->l2_level->speed.src != HFPLL)
1026 pll_vdd_dig = 0;
1027 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001028 pll_vdd_dig = HFPLL_NOMINAL_VDD;
1029 else
1030 pll_vdd_dig = HFPLL_LOW_VDD;
1031
1032 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1033}
1034
1035static unsigned int calculate_vdd_core(struct acpu_level *tgt)
1036{
1037 unsigned int pll_vdd_core;
1038
Stephen Boydc76158f2011-12-08 12:42:40 -08001039 if (tgt->speed.src != HFPLL)
1040 pll_vdd_core = 0;
1041 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001042 pll_vdd_core = HFPLL_NOMINAL_VDD;
1043 else
1044 pll_vdd_core = HFPLL_LOW_VDD;
1045
1046 return max(tgt->vdd_core, pll_vdd_core);
1047}
1048
1049/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001050static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1051 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001052{
1053 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1054 struct l2_level *tgt_l2_l;
1055 struct acpu_level *tgt;
1056 unsigned int vdd_mem, vdd_dig, vdd_core;
1057 unsigned long flags;
1058 int rc = 0;
1059
1060 if (cpu > num_possible_cpus()) {
1061 rc = -EINVAL;
1062 goto out;
1063 }
1064
1065 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1066 mutex_lock(&driver_lock);
1067
1068 strt_acpu_s = scalable[cpu].current_speed;
1069
1070 /* Return early if rate didn't change. */
1071 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1072 goto out;
1073
1074 /* Find target frequency. */
1075 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1076 if (tgt->speed.khz == rate) {
1077 tgt_acpu_s = &tgt->speed;
1078 break;
1079 }
1080 }
1081 if (tgt->speed.khz == 0) {
1082 rc = -EINVAL;
1083 goto out;
1084 }
1085
1086 /* Calculate voltage requirements for the current CPU. */
1087 vdd_mem = calculate_vdd_mem(tgt);
1088 vdd_dig = calculate_vdd_dig(tgt);
1089 vdd_core = calculate_vdd_core(tgt);
1090
1091 /* Increase VDD levels if needed. */
1092 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1093 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1094 if (rc)
1095 goto out;
1096 }
1097
1098 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1099 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1100
1101 /* Set the CPU speed. */
1102 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1103
1104 /*
1105 * Update the L2 vote and apply the rate change. A spinlock is
1106 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001107 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001108 * and the driver_lock mutex is not acquired.
1109 */
1110 spin_lock_irqsave(&l2_lock, flags);
1111 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1112 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1113 spin_unlock_irqrestore(&l2_lock, flags);
1114
1115 /* Nothing else to do for power collapse or SWFI. */
1116 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1117 goto out;
1118
1119 /* Update bus bandwith request. */
1120 set_bus_bw(tgt_l2_l->bw_level);
1121
1122 /* Drop VDD levels if we can. */
1123 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1124
1125 scalable[cpu].first_set_call = false;
1126 pr_debug("ACPU%d speed change complete\n", cpu);
1127
1128out:
1129 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1130 mutex_unlock(&driver_lock);
1131 return rc;
1132}
1133
1134/* Initialize a HFPLL at a given rate and enable it. */
1135static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1136{
1137 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1138
1139 /* Disable the PLL for re-programming. */
1140 hfpll_disable(sc);
1141
1142 /* Configure PLL parameters for integer mode. */
1143 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1144 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1145 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1146
1147 /* Program droop controller. */
1148 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1149
1150 /* Set an initial rate and enable the PLL. */
1151 hfpll_set_rate(sc, tgt_s);
1152 hfpll_enable(sc);
1153}
1154
1155/* Voltage regulator initialization. */
1156static void __init regulator_init(void)
1157{
1158 int cpu, ret;
1159 struct scalable *sc;
1160
1161 for_each_possible_cpu(cpu) {
1162 sc = &scalable[cpu];
1163 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1164 sc->vreg[VREG_CORE].name);
1165 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1166 pr_err("regulator_get(%s) failed (%ld)\n",
1167 sc->vreg[VREG_CORE].name,
1168 PTR_ERR(sc->vreg[VREG_CORE].reg));
1169 BUG();
1170 }
1171
1172 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
1173 sc->vreg[VREG_CORE].max_vdd,
1174 sc->vreg[VREG_CORE].max_vdd);
1175 if (ret)
1176 pr_err("regulator_set_voltage(%s) failed"
1177 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1178
1179 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1180 if (ret)
1181 pr_err("regulator_enable(%s) failed (%d)\n",
1182 sc->vreg[VREG_CORE].name, ret);
1183 }
1184}
1185
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001186/* Set initial rate for a given core. */
1187static void __init init_clock_sources(struct scalable *sc,
1188 struct core_speed *tgt_s)
1189{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001190 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001191
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001192 /* Select PLL8 as AUX source input to the secondary MUX. */
1193 writel_relaxed(0x3, sc->aux_clk_sel);
1194
1195 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001196 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001197 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001198 hfpll_init(sc, tgt_s);
1199
1200 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001201 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001202 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001203 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001204
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001205 /* Switch to the target clock source. */
1206 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001207 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1208 sc->current_speed = tgt_s;
1209
1210 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001211 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1212 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001213 */
1214 sc->first_set_call = true;
1215}
1216
Matt Wagantall8e726c72011-08-06 00:49:28 -07001217static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001218{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001219 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001220 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001221
1222 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1223 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001224}
1225
1226/* Register with bus driver. */
1227static void __init bus_init(void)
1228{
1229 int ret;
1230
1231 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1232 if (!bus_perf_client) {
1233 pr_err("unable to register bus client\n");
1234 BUG();
1235 }
1236
1237 ret = msm_bus_scale_client_update_request(bus_perf_client,
1238 (ARRAY_SIZE(bw_level_tbl)-1));
1239 if (ret)
1240 pr_err("initial bandwidth request failed (%d)\n", ret);
1241}
1242
1243#ifdef CONFIG_CPU_FREQ_MSM
1244static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1245
1246static void __init cpufreq_table_init(void)
1247{
1248 int cpu;
1249
1250 for_each_possible_cpu(cpu) {
1251 int i, freq_cnt = 0;
1252 /* Construct the freq_table tables from acpu_freq_tbl. */
1253 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1254 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1255 if (acpu_freq_tbl[i].use_for_scaling) {
1256 freq_table[cpu][freq_cnt].index = freq_cnt;
1257 freq_table[cpu][freq_cnt].frequency
1258 = acpu_freq_tbl[i].speed.khz;
1259 freq_cnt++;
1260 }
1261 }
1262 /* freq_table not big enough to store all usable freqs. */
1263 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1264
1265 freq_table[cpu][freq_cnt].index = freq_cnt;
1266 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1267
1268 pr_info("CPU%d: %d scaling frequencies supported.\n",
1269 cpu, freq_cnt);
1270
1271 /* Register table with CPUFreq. */
1272 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1273 }
1274}
1275#else
1276static void __init cpufreq_table_init(void) {}
1277#endif
1278
1279#define HOT_UNPLUG_KHZ STBY_KHZ
1280static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1281 unsigned long action, void *hcpu)
1282{
1283 static int prev_khz[NR_CPUS];
1284 static int prev_pri_src[NR_CPUS];
1285 static int prev_sec_src[NR_CPUS];
1286 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001287
1288 switch (action) {
1289 case CPU_DYING:
1290 case CPU_DYING_FROZEN:
1291 /*
Matt Wagantall27663842011-08-25 15:11:48 -07001292 * On Krait v1, the primary and secondary muxes must be set
1293 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001294 */
Matt Wagantall27663842011-08-25 15:11:48 -07001295 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001296 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1297 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1298 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1299 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1300 }
1301 break;
1302 case CPU_DEAD:
1303 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001304 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001305 /* Fall through. */
1306 case CPU_UP_CANCELED:
1307 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001308 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001309 break;
1310 case CPU_UP_PREPARE:
1311 case CPU_UP_PREPARE_FROZEN:
1312 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001313 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001314 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001315 break;
1316 case CPU_STARTING:
1317 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001318 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001319 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1320 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1321 }
1322 break;
1323 default:
1324 break;
1325 }
1326
1327 return NOTIFY_OK;
1328}
1329
1330static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1331 .notifier_call = acpuclock_cpu_callback,
1332};
1333
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001334static const int krait_needs_vmin(void)
1335{
1336 switch (read_cpuid_id()) {
1337 case 0x511F04D0:
1338 case 0x511F04D1:
1339 case 0x510F06F0:
1340 return 1;
1341 default:
1342 return 0;
1343 };
1344}
1345
Stephen Boydaefb8de2012-01-05 19:05:01 -08001346static void kraitv2_apply_vmin(struct acpu_level *tbl)
1347{
1348 for (; tbl->speed.khz != 0; tbl++)
1349 if (tbl->vdd_core < 1150000)
1350 tbl->vdd_core = 1150000;
1351}
1352
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001353static struct acpu_level * __init select_freq_plan(void)
1354{
1355 struct acpu_level *l, *max_acpu_level = NULL;
1356
1357 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001358 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001359 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001360 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001361
1362 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1363 pvs = (pte_efuse >> 10) & 0x7;
1364 if (pvs == 0x7)
1365 pvs = (pte_efuse >> 13) & 0x7;
1366
1367 switch (pvs) {
1368 case 0x0:
1369 case 0x7:
1370 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001371 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1372 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001373 break;
1374 case 0x1:
1375 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001376 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001377 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001378 break;
1379 case 0x3:
1380 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001381 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001382 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001383 break;
1384 default:
1385 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001386 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1387 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001388 break;
1389 }
1390
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001391 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001392 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001393 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001394 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1395 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1396 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001397 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001398 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1399 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1400 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001401 } else if (cpu_is_apq8064()) {
1402 scalable = scalable_8064;
1403 acpu_freq_tbl = acpu_freq_tbl_8064;
1404 l2_freq_tbl = l2_freq_tbl_8064;
1405 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001406 } else if (cpu_is_msm8627()) {
1407 scalable = scalable_8627;
1408 acpu_freq_tbl = acpu_freq_tbl_8627;
1409 l2_freq_tbl = l2_freq_tbl_8627;
1410 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001411 } else if (cpu_is_msm8930()) {
1412 scalable = scalable_8930;
1413 acpu_freq_tbl = acpu_freq_tbl_8930;
1414 l2_freq_tbl = l2_freq_tbl_8930;
1415 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001416 } else {
1417 BUG();
1418 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001419 if (krait_needs_vmin())
1420 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001421
1422 /* Find the max supported scaling frequency. */
1423 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1424 if (l->use_for_scaling)
1425 max_acpu_level = l;
1426 BUG_ON(!max_acpu_level);
1427 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1428
1429 return max_acpu_level;
1430}
1431
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001432static struct acpuclk_data acpuclk_8960_data = {
1433 .set_rate = acpuclk_8960_set_rate,
1434 .get_rate = acpuclk_8960_get_rate,
1435 .power_collapse_khz = STBY_KHZ,
1436 .wait_for_irq_khz = STBY_KHZ,
1437};
1438
Matt Wagantallec57f062011-08-16 23:54:46 -07001439static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001440{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001441 struct acpu_level *max_acpu_level = select_freq_plan();
1442 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1443 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001444
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001445 regulator_init();
1446 bus_init();
1447 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001448
1449 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001450 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001451
1452 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001453}
Matt Wagantallec57f062011-08-16 23:54:46 -07001454
1455struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1456 .init = acpuclk_8960_init,
1457};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001458
1459struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1460 .init = acpuclk_8960_init,
1461};