blob: cee4fc596ecb6a8d0310f95f49c4bc57bffaf3ab [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 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800203 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
204 RPM_VREG_VOTER1,
205 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700206 },
207 [CPU1] = {
208 .hfpll_base = MSM_HFPLL_BASE + 0x240,
209 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
210 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
211 .vreg[VREG_CORE] = { "krait1", 1150000 },
212 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
213 RPM_VREG_VOTER2,
214 RPM_VREG_ID_PM8921_L24 },
215 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
216 RPM_VREG_VOTER2,
217 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800218 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
219 RPM_VREG_VOTER2,
220 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700221 },
222 [CPU2] = {
223 .hfpll_base = MSM_HFPLL_BASE + 0x280,
224 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
225 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
226 .vreg[VREG_CORE] = { "krait2", 1150000 },
227 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
228 RPM_VREG_VOTER4,
229 RPM_VREG_ID_PM8921_L24 },
230 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
231 RPM_VREG_VOTER4,
232 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800233 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
234 RPM_VREG_VOTER4,
235 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700236 },
237 [CPU3] = {
238 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
239 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
240 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
241 .vreg[VREG_CORE] = { "krait3", 1150000 },
242 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
243 RPM_VREG_VOTER5,
244 RPM_VREG_ID_PM8921_L24 },
245 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
246 RPM_VREG_VOTER5,
247 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800248 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
249 RPM_VREG_VOTER5,
250 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700251 },
252 [L2] = {
253 .hfpll_base = MSM_HFPLL_BASE + 0x300,
254 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
255 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800256 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
257 RPM_VREG_VOTER6,
258 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700259 },
260};
261
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800262/*TODO: Update the rpm vreg id when the rpm driver is ready */
263static struct scalable scalable_8930[] = {
264 [CPU0] = {
265 .hfpll_base = MSM_HFPLL_BASE + 0x200,
266 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
267 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
268 .vreg[VREG_CORE] = { "krait0", 1300000 },
269 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
270 RPM_VREG_VOTER1,
271 RPM_VREG_ID_PM8921_L24 },
272 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
273 RPM_VREG_VOTER1,
274 RPM_VREG_ID_PM8921_S3 },
275 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
276 RPM_VREG_VOTER1,
277 RPM_VREG_ID_PM8921_S8 },
278 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
279 RPM_VREG_VOTER1,
280 RPM_VREG_ID_PM8921_L23 },
281 },
282 [CPU1] = {
283 .hfpll_base = MSM_HFPLL_BASE + 0x300,
284 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
285 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
286 .vreg[VREG_CORE] = { "krait1", 1300000 },
287 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
288 RPM_VREG_VOTER2,
289 RPM_VREG_ID_PM8921_L24 },
290 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
291 RPM_VREG_VOTER2,
292 RPM_VREG_ID_PM8921_S3 },
293 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
294 RPM_VREG_VOTER2,
295 RPM_VREG_ID_PM8921_S8 },
296 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
297 RPM_VREG_VOTER2,
298 RPM_VREG_ID_PM8921_L23 },
299 },
300 [L2] = {
301 .hfpll_base = MSM_HFPLL_BASE + 0x400,
302 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
303 .l2cpmr_iaddr = L2CPMR_IADDR,
304 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
305 RPM_VREG_VOTER6,
306 RPM_VREG_ID_PM8921_S8 },
307 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
308 RPM_VREG_VOTER6,
309 RPM_VREG_ID_PM8921_L23 },
310 },
311};
312
Tianyi Goue0b34de2011-12-20 11:20:10 -0800313/*TODO: Update the rpm vreg id when the rpm driver is ready */
314static struct scalable scalable_8627[] = {
315 [CPU0] = {
316 .hfpll_base = MSM_HFPLL_BASE + 0x200,
317 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
318 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
319 .vreg[VREG_CORE] = { "krait0", 1300000 },
320 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
321 RPM_VREG_VOTER1,
322 RPM_VREG_ID_PM8921_L24 },
323 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
324 RPM_VREG_VOTER1,
325 RPM_VREG_ID_PM8921_S3 },
326 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
327 RPM_VREG_VOTER1,
328 RPM_VREG_ID_PM8921_S8 },
329 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
330 RPM_VREG_VOTER1,
331 RPM_VREG_ID_PM8921_L23 },
332 },
333 [CPU1] = {
334 .hfpll_base = MSM_HFPLL_BASE + 0x300,
335 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
336 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
337 .vreg[VREG_CORE] = { "krait1", 1300000 },
338 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
339 RPM_VREG_VOTER2,
340 RPM_VREG_ID_PM8921_L24 },
341 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
342 RPM_VREG_VOTER2,
343 RPM_VREG_ID_PM8921_S3 },
344 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
345 RPM_VREG_VOTER2,
346 RPM_VREG_ID_PM8921_S8 },
347 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
348 RPM_VREG_VOTER2,
349 RPM_VREG_ID_PM8921_L23 },
350 },
351 [L2] = {
352 .hfpll_base = MSM_HFPLL_BASE + 0x400,
353 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
354 .l2cpmr_iaddr = L2CPMR_IADDR,
355 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
356 RPM_VREG_VOTER6,
357 RPM_VREG_ID_PM8921_S8 },
358 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
359 RPM_VREG_VOTER6,
360 RPM_VREG_ID_PM8921_L23 },
361 },
362};
363
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700364static struct scalable *scalable;
365static struct l2_level *l2_freq_tbl;
366static struct acpu_level *acpu_freq_tbl;
367static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700368
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700369/* Instantaneous bandwidth requests in MB/s. */
370#define BW_MBPS(_bw) \
371 { \
372 .vectors = (struct msm_bus_vectors[]){ \
373 {\
374 .src = MSM_BUS_MASTER_AMPSS_M0, \
375 .dst = MSM_BUS_SLAVE_EBI_CH0, \
376 .ib = (_bw) * 1000000UL, \
377 .ab = (_bw) * 100000UL, \
378 }, \
379 { \
380 .src = MSM_BUS_MASTER_AMPSS_M1, \
381 .dst = MSM_BUS_SLAVE_EBI_CH0, \
382 .ib = (_bw) * 1000000UL, \
383 .ab = (_bw) * 100000UL, \
384 }, \
385 }, \
386 .num_paths = 2, \
387 }
388static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800389 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
390 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
391 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
392 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
393 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
394 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
395 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396};
397
398static struct msm_bus_scale_pdata bus_client_pdata = {
399 .usecase = bw_level_tbl,
400 .num_usecases = ARRAY_SIZE(bw_level_tbl),
401 .active_only = 1,
402 .name = "acpuclock",
403};
404
405static uint32_t bus_perf_client;
406
407/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800408#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
409static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700410 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700411 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700412 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
413 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
414 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
415 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
416 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
417 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700418 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700419 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
420 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
421 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700422};
423
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800424static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
425 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
426 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
427 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
428 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
429 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
430 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
431 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
432 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
433 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
434 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
435 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
436 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
437 { 0, { 0 } }
438};
439
440static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
441 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
442 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
443 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
444 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
445 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
446 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
447 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
448 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
449 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
450 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
451 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
452 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700453 { 0, { 0 } }
454};
455
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800456#undef L2
457#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
458static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
459 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
460 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800461 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
462 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
463 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800464 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800465 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
466 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
467 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
468 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
469 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
470 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
471 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
472 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
473 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
474 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
475 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800476 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
477 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
478 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800479};
480
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800481static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800482 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
483 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
484 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 975000 },
485 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 975000 },
486 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 1000000 },
487 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
488 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
489 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1025000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800490 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1075000 },
491 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1075000 },
492 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
493 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1100000 },
494 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1125000 },
495 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800496 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
497 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
498 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
499 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1200000 },
500 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1225000 },
501 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1225000 },
502 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1237500 },
503 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1237500 },
504 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800505 { 0, { 0 } }
506};
507
508static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800509 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
510 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
511 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
512 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
513 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 950000 },
514 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 950000 },
515 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 975000 },
516 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 975000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800517 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800518 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1025000 },
519 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1050000 },
520 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1050000 },
521 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1075000 },
522 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800523 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
524 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
525 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
526 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1150000 },
527 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1175000 },
528 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1175000 },
529 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1187500 },
530 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1187500 },
531 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800532 { 0, { 0 } }
533};
534
Stephen Boyd5766f682011-12-27 19:21:08 -0800535static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800536 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
537 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
538 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 875000 },
539 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 875000 },
540 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
541 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 900000 },
542 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
543 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 925000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800544 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 975000 },
545 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 975000 },
546 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1000000 },
547 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1000000 },
548 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1025000 },
549 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1025000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800550 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
551 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
552 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
553 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1100000 },
554 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1125000 },
555 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1125000 },
556 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1137500 },
557 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1137500 },
558 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800559 { 0, { 0 } }
560};
561
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700562/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
563#undef L2
564#define L2(x) (&l2_freq_tbl_8064[(x)])
565static struct l2_level l2_freq_tbl_8064[] = {
566 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
567 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
568 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
569 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
570 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
571 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
572 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
573 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
574 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
575 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
576 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
577 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
578 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
579 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
580 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
581 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
582 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
583 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
584 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
585 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
586 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
587 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
588 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
589 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
590 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
591 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
592};
593
594/* TODO: Update core voltages when data is available. */
595static struct acpu_level acpu_freq_tbl_8064[] = {
596 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
597 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
598 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
599 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
600 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
601 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
602 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
603 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
604 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
605 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
606 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
607 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
608 { 0, { 0 } }
609};
610
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800611/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
612#undef L2
613#define L2(x) (&l2_freq_tbl_8930[(x)])
614static struct l2_level l2_freq_tbl_8930[] = {
615 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
616 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
617 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
618 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
619 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
620 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
621 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
622 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
623 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
624 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
625 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
626 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
627 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
628 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
629 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
630 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
631 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
632};
633
634/* TODO: Update core voltages when data is available. */
635static struct acpu_level acpu_freq_tbl_8930[] = {
636 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
637 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
638 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
639 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
640 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
641 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
642 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
643 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
644 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
645 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
646 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
647 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
648 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
649 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
650 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
651 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
652 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
653 { 0, { 0 } }
654};
655
Tianyi Goue0b34de2011-12-20 11:20:10 -0800656/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
657#undef L2
658#define L2(x) (&l2_freq_tbl_8627[(x)])
659static struct l2_level l2_freq_tbl_8627[] = {
660 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
661 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
662 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
663 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
664 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
665 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
666 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
667 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 3 },
668 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
669 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
670 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
671 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 4 },
672 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 4 },
673};
674
675/* TODO: Update core voltages when data is available. */
676static struct acpu_level acpu_freq_tbl_8627[] = {
677 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
678 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
679 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
680 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
681 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
682 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
683 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
684 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
685 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
686 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
687 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
688 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
689 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
690 { 0, { 0 } }
691};
692
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700693static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700694{
695 return scalable[cpu].current_speed->khz;
696}
697
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698/* Get the selected source on primary MUX. */
699static int get_pri_clk_src(struct scalable *sc)
700{
701 uint32_t regval;
702
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700703 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700704 return regval & 0x3;
705}
706
707/* Set the selected source on primary MUX. */
708static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
709{
710 uint32_t regval;
711
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700712 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700713 regval &= ~0x3;
714 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700715 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716 /* Wait for switch to complete. */
717 mb();
718 udelay(1);
719}
720
721/* Get the selected source on secondary MUX. */
722static int get_sec_clk_src(struct scalable *sc)
723{
724 uint32_t regval;
725
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700726 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700727 return (regval >> 2) & 0x3;
728}
729
730/* Set the selected source on secondary MUX. */
731static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
732{
733 uint32_t regval;
734
735 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700736 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700737 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700738 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700739
740 /* Program the MUX. */
741 regval &= ~(0x3 << 2);
742 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700743 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744
745 /* Wait for switch to complete. */
746 mb();
747 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700748
749 /* Re-enable secondary source clock gating. */
750 regval &= ~SECCLKAGD;
751 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700752}
753
754/* Enable an already-configured HFPLL. */
755static void hfpll_enable(struct scalable *sc)
756{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700757 int rc;
758
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800759 if (!cpu_is_apq8064()) {
760 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
761 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 2100000,
762 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
763 if (rc)
764 pr_err("%s regulator enable failed (%d)\n",
765 sc->vreg[VREG_HFPLL_A].name, rc);
766 }
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -0700767 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
768 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
769 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
770 if (rc)
771 pr_err("%s regulator enable failed (%d)\n",
772 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700773
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700774 /* Disable PLL bypass mode. */
775 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
776
777 /*
778 * H/W requires a 5us delay between disabling the bypass and
779 * de-asserting the reset. Delay 10us just to be safe.
780 */
781 mb();
782 udelay(10);
783
784 /* De-assert active-low PLL reset. */
785 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
786
787 /* Wait for PLL to lock. */
788 mb();
789 udelay(60);
790
791 /* Enable PLL output. */
792 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
793}
794
795/* Disable a HFPLL for power-savings or while its being reprogrammed. */
796static void hfpll_disable(struct scalable *sc)
797{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700798 int rc;
799
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800 /*
801 * Disable the PLL output, disable test mode, enable
802 * the bypass mode, and assert the reset.
803 */
804 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700805
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -0700806 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
807 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
808 0, 0);
809 if (rc)
810 pr_err("%s regulator enable failed (%d)\n",
811 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800812 if (!cpu_is_apq8064()) {
813 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
814 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 0,
815 0, 0);
816 if (rc)
817 pr_err("%s regulator enable failed (%d)\n",
818 sc->vreg[VREG_HFPLL_A].name, rc);
819 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700820}
821
822/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
823static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
824{
825 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
826}
827
828/* Return the L2 speed that should be applied. */
829static struct l2_level *compute_l2_level(struct scalable *sc,
830 struct l2_level *vote_l)
831{
832 struct l2_level *new_l;
833 int cpu;
834
835 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700836 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700837
838 /* Find max L2 speed vote. */
839 sc->l2_vote = vote_l;
840 new_l = l2_freq_tbl;
841 for_each_present_cpu(cpu)
842 new_l = max(new_l, scalable[cpu].l2_vote);
843
844 return new_l;
845}
846
847/* Update the bus bandwidth request. */
848static void set_bus_bw(unsigned int bw)
849{
850 int ret;
851
852 /* Bounds check. */
853 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
854 pr_err("invalid bandwidth request (%d)\n", bw);
855 return;
856 }
857
858 /* Update bandwidth if request has changed. This may sleep. */
859 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
860 if (ret)
861 pr_err("bandwidth request failed (%d)\n", ret);
862}
863
864/* Set the CPU or L2 clock speed. */
865static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
866 enum setrate_reason reason)
867{
868 struct core_speed *strt_s = sc->current_speed;
869
870 if (tgt_s == strt_s)
871 return;
872
873 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700875 * Move to an always-on source running at a frequency that does
876 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700877 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700878 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700879 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
880
881 /* Program CPU HFPLL. */
882 hfpll_disable(sc);
883 hfpll_set_rate(sc, tgt_s);
884 hfpll_enable(sc);
885
886 /* Move CPU to HFPLL source. */
887 set_pri_clk_src(sc, tgt_s->pri_src_sel);
888 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889 /*
890 * If responding to CPU_DEAD we must be running on another
891 * CPU. Therefore, we can't access the downed CPU's CP15
892 * clock MUX registers from here and can't change clock sources.
893 * Just turn off the PLL- since the CPU is down already, halting
894 * its clock should be safe.
895 */
896 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
897 set_sec_clk_src(sc, tgt_s->sec_src_sel);
898 set_pri_clk_src(sc, tgt_s->pri_src_sel);
899 }
900 hfpll_disable(sc);
901 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
902 hfpll_set_rate(sc, tgt_s);
903 hfpll_enable(sc);
904 /*
905 * If responding to CPU_UP_PREPARE, we can't change CP15
906 * registers for the CPU that's coming up since we're not
907 * running on that CPU. That's okay though, since the MUX
908 * source was not changed on the way down, either.
909 */
910 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
911 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
914 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700915 }
916
917 sc->current_speed = tgt_s;
918}
919
920/* Apply any per-cpu voltage increases. */
921static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
922 unsigned int vdd_dig, enum setrate_reason reason)
923{
924 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700925 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926
927 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700928 * Increase vdd_mem active-set before vdd_dig.
929 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 */
931 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
932 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
933 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
934 sc->vreg[VREG_MEM].max_vdd, 0);
935 if (rc) {
936 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
937 __func__, cpu, rc);
938 return rc;
939 }
940 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
941 }
942
943 /* Increase vdd_dig active-set vote. */
944 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
945 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
946 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
947 sc->vreg[VREG_DIG].max_vdd, 0);
948 if (rc) {
949 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
950 __func__, cpu, rc);
951 return rc;
952 }
953 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
954 }
955
956 /*
957 * Update per-CPU core voltage. Don't do this for the hotplug path for
958 * which it should already be correct. Attempting to set it is bad
959 * because we don't know what CPU we are running on at this point, but
960 * the CPU regulator API requires we call it from the affected CPU.
961 */
962 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
963 && reason != SETRATE_HOTPLUG) {
964 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
965 sc->vreg[VREG_CORE].max_vdd);
966 if (rc) {
967 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
968 __func__, cpu, rc);
969 return rc;
970 }
971 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
972 }
973
974 return rc;
975}
976
977/* Apply any per-cpu voltage decreases. */
978static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
979 unsigned int vdd_dig, enum setrate_reason reason)
980{
981 struct scalable *sc = &scalable[cpu];
982 int ret;
983
984 /*
985 * Update per-CPU core voltage. This must be called on the CPU
986 * that's being affected. Don't do this in the hotplug remove path,
987 * where the rail is off and we're executing on the other CPU.
988 */
989 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
990 && reason != SETRATE_HOTPLUG) {
991 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
992 sc->vreg[VREG_CORE].max_vdd);
993 if (ret) {
994 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
995 __func__, cpu, ret);
996 return;
997 }
998 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
999 }
1000
1001 /* Decrease vdd_dig active-set vote. */
1002 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1003 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1004 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1005 sc->vreg[VREG_DIG].max_vdd, 0);
1006 if (ret) {
1007 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
1008 __func__, cpu, ret);
1009 return;
1010 }
1011 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1012 }
1013
1014 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001015 * Decrease vdd_mem active-set after vdd_dig.
1016 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001017 */
1018 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1019 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1020 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1021 sc->vreg[VREG_MEM].max_vdd, 0);
1022 if (ret) {
1023 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
1024 __func__, cpu, ret);
1025 return;
1026 }
1027 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1028 }
1029}
1030
1031static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1032{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001033 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001034}
1035
1036static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1037{
1038 unsigned int pll_vdd_dig;
1039
Stephen Boydc76158f2011-12-08 12:42:40 -08001040 if (tgt->l2_level->speed.src != HFPLL)
1041 pll_vdd_dig = 0;
1042 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001043 pll_vdd_dig = HFPLL_NOMINAL_VDD;
1044 else
1045 pll_vdd_dig = HFPLL_LOW_VDD;
1046
1047 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1048}
1049
1050static unsigned int calculate_vdd_core(struct acpu_level *tgt)
1051{
1052 unsigned int pll_vdd_core;
1053
Stephen Boydc76158f2011-12-08 12:42:40 -08001054 if (tgt->speed.src != HFPLL)
1055 pll_vdd_core = 0;
1056 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001057 pll_vdd_core = HFPLL_NOMINAL_VDD;
1058 else
1059 pll_vdd_core = HFPLL_LOW_VDD;
1060
1061 return max(tgt->vdd_core, pll_vdd_core);
1062}
1063
1064/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001065static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1066 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001067{
1068 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1069 struct l2_level *tgt_l2_l;
1070 struct acpu_level *tgt;
1071 unsigned int vdd_mem, vdd_dig, vdd_core;
1072 unsigned long flags;
1073 int rc = 0;
1074
1075 if (cpu > num_possible_cpus()) {
1076 rc = -EINVAL;
1077 goto out;
1078 }
1079
1080 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1081 mutex_lock(&driver_lock);
1082
1083 strt_acpu_s = scalable[cpu].current_speed;
1084
1085 /* Return early if rate didn't change. */
1086 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1087 goto out;
1088
1089 /* Find target frequency. */
1090 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1091 if (tgt->speed.khz == rate) {
1092 tgt_acpu_s = &tgt->speed;
1093 break;
1094 }
1095 }
1096 if (tgt->speed.khz == 0) {
1097 rc = -EINVAL;
1098 goto out;
1099 }
1100
1101 /* Calculate voltage requirements for the current CPU. */
1102 vdd_mem = calculate_vdd_mem(tgt);
1103 vdd_dig = calculate_vdd_dig(tgt);
1104 vdd_core = calculate_vdd_core(tgt);
1105
1106 /* Increase VDD levels if needed. */
1107 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1108 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1109 if (rc)
1110 goto out;
1111 }
1112
1113 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1114 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1115
1116 /* Set the CPU speed. */
1117 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1118
1119 /*
1120 * Update the L2 vote and apply the rate change. A spinlock is
1121 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001122 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001123 * and the driver_lock mutex is not acquired.
1124 */
1125 spin_lock_irqsave(&l2_lock, flags);
1126 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1127 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1128 spin_unlock_irqrestore(&l2_lock, flags);
1129
1130 /* Nothing else to do for power collapse or SWFI. */
1131 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1132 goto out;
1133
1134 /* Update bus bandwith request. */
1135 set_bus_bw(tgt_l2_l->bw_level);
1136
1137 /* Drop VDD levels if we can. */
1138 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1139
1140 scalable[cpu].first_set_call = false;
1141 pr_debug("ACPU%d speed change complete\n", cpu);
1142
1143out:
1144 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1145 mutex_unlock(&driver_lock);
1146 return rc;
1147}
1148
1149/* Initialize a HFPLL at a given rate and enable it. */
1150static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1151{
1152 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1153
1154 /* Disable the PLL for re-programming. */
1155 hfpll_disable(sc);
1156
1157 /* Configure PLL parameters for integer mode. */
1158 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1159 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1160 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1161
1162 /* Program droop controller. */
1163 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1164
1165 /* Set an initial rate and enable the PLL. */
1166 hfpll_set_rate(sc, tgt_s);
1167 hfpll_enable(sc);
1168}
1169
1170/* Voltage regulator initialization. */
1171static void __init regulator_init(void)
1172{
1173 int cpu, ret;
1174 struct scalable *sc;
1175
1176 for_each_possible_cpu(cpu) {
1177 sc = &scalable[cpu];
1178 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1179 sc->vreg[VREG_CORE].name);
1180 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1181 pr_err("regulator_get(%s) failed (%ld)\n",
1182 sc->vreg[VREG_CORE].name,
1183 PTR_ERR(sc->vreg[VREG_CORE].reg));
1184 BUG();
1185 }
1186
1187 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
1188 sc->vreg[VREG_CORE].max_vdd,
1189 sc->vreg[VREG_CORE].max_vdd);
1190 if (ret)
1191 pr_err("regulator_set_voltage(%s) failed"
1192 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1193
1194 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1195 if (ret)
1196 pr_err("regulator_enable(%s) failed (%d)\n",
1197 sc->vreg[VREG_CORE].name, ret);
1198 }
1199}
1200
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001201/* Set initial rate for a given core. */
1202static void __init init_clock_sources(struct scalable *sc,
1203 struct core_speed *tgt_s)
1204{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001205 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001207 /* Select PLL8 as AUX source input to the secondary MUX. */
1208 writel_relaxed(0x3, sc->aux_clk_sel);
1209
1210 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001211 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001212 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001213 hfpll_init(sc, tgt_s);
1214
1215 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001216 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001217 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001218 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001219
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001220 /* Switch to the target clock source. */
1221 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001222 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1223 sc->current_speed = tgt_s;
1224
1225 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001226 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1227 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001228 */
1229 sc->first_set_call = true;
1230}
1231
Matt Wagantall8e726c72011-08-06 00:49:28 -07001232static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001234 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001235 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001236
1237 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1238 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001239}
1240
1241/* Register with bus driver. */
1242static void __init bus_init(void)
1243{
1244 int ret;
1245
1246 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1247 if (!bus_perf_client) {
1248 pr_err("unable to register bus client\n");
1249 BUG();
1250 }
1251
1252 ret = msm_bus_scale_client_update_request(bus_perf_client,
1253 (ARRAY_SIZE(bw_level_tbl)-1));
1254 if (ret)
1255 pr_err("initial bandwidth request failed (%d)\n", ret);
1256}
1257
1258#ifdef CONFIG_CPU_FREQ_MSM
1259static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1260
1261static void __init cpufreq_table_init(void)
1262{
1263 int cpu;
1264
1265 for_each_possible_cpu(cpu) {
1266 int i, freq_cnt = 0;
1267 /* Construct the freq_table tables from acpu_freq_tbl. */
1268 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1269 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1270 if (acpu_freq_tbl[i].use_for_scaling) {
1271 freq_table[cpu][freq_cnt].index = freq_cnt;
1272 freq_table[cpu][freq_cnt].frequency
1273 = acpu_freq_tbl[i].speed.khz;
1274 freq_cnt++;
1275 }
1276 }
1277 /* freq_table not big enough to store all usable freqs. */
1278 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1279
1280 freq_table[cpu][freq_cnt].index = freq_cnt;
1281 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1282
1283 pr_info("CPU%d: %d scaling frequencies supported.\n",
1284 cpu, freq_cnt);
1285
1286 /* Register table with CPUFreq. */
1287 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1288 }
1289}
1290#else
1291static void __init cpufreq_table_init(void) {}
1292#endif
1293
1294#define HOT_UNPLUG_KHZ STBY_KHZ
1295static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1296 unsigned long action, void *hcpu)
1297{
1298 static int prev_khz[NR_CPUS];
1299 static int prev_pri_src[NR_CPUS];
1300 static int prev_sec_src[NR_CPUS];
1301 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001302
1303 switch (action) {
1304 case CPU_DYING:
1305 case CPU_DYING_FROZEN:
1306 /*
Matt Wagantall27663842011-08-25 15:11:48 -07001307 * On Krait v1, the primary and secondary muxes must be set
1308 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001309 */
Matt Wagantall27663842011-08-25 15:11:48 -07001310 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001311 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1312 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1313 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1314 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1315 }
1316 break;
1317 case CPU_DEAD:
1318 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001319 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001320 /* Fall through. */
1321 case CPU_UP_CANCELED:
1322 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001323 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001324 break;
1325 case CPU_UP_PREPARE:
1326 case CPU_UP_PREPARE_FROZEN:
1327 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001328 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001329 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001330 break;
1331 case CPU_STARTING:
1332 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001333 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001334 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1335 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1336 }
1337 break;
1338 default:
1339 break;
1340 }
1341
1342 return NOTIFY_OK;
1343}
1344
1345static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1346 .notifier_call = acpuclock_cpu_callback,
1347};
1348
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001349static const int krait_needs_vmin(void)
1350{
1351 switch (read_cpuid_id()) {
1352 case 0x511F04D0:
1353 case 0x511F04D1:
1354 case 0x510F06F0:
1355 return 1;
1356 default:
1357 return 0;
1358 };
1359}
1360
Stephen Boydaefb8de2012-01-05 19:05:01 -08001361static void kraitv2_apply_vmin(struct acpu_level *tbl)
1362{
1363 for (; tbl->speed.khz != 0; tbl++)
1364 if (tbl->vdd_core < 1150000)
1365 tbl->vdd_core = 1150000;
1366}
1367
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001368static struct acpu_level * __init select_freq_plan(void)
1369{
1370 struct acpu_level *l, *max_acpu_level = NULL;
1371
1372 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001373 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001374 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001375 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001376
1377 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1378 pvs = (pte_efuse >> 10) & 0x7;
1379 if (pvs == 0x7)
1380 pvs = (pte_efuse >> 13) & 0x7;
1381
1382 switch (pvs) {
1383 case 0x0:
1384 case 0x7:
1385 pr_info("ACPU PVS: 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 case 0x1:
1390 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001391 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001392 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001393 break;
1394 case 0x3:
1395 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001396 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001397 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001398 break;
1399 default:
1400 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001401 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1402 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001403 break;
1404 }
1405
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001406 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001407 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001408 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001409 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1410 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1411 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001412 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001413 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1414 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1415 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001416 } else if (cpu_is_apq8064()) {
1417 scalable = scalable_8064;
1418 acpu_freq_tbl = acpu_freq_tbl_8064;
1419 l2_freq_tbl = l2_freq_tbl_8064;
1420 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001421 } else if (cpu_is_msm8627()) {
1422 scalable = scalable_8627;
1423 acpu_freq_tbl = acpu_freq_tbl_8627;
1424 l2_freq_tbl = l2_freq_tbl_8627;
1425 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001426 } else if (cpu_is_msm8930()) {
1427 scalable = scalable_8930;
1428 acpu_freq_tbl = acpu_freq_tbl_8930;
1429 l2_freq_tbl = l2_freq_tbl_8930;
1430 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001431 } else {
1432 BUG();
1433 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001434 if (krait_needs_vmin())
1435 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001436
1437 /* Find the max supported scaling frequency. */
1438 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1439 if (l->use_for_scaling)
1440 max_acpu_level = l;
1441 BUG_ON(!max_acpu_level);
1442 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1443
1444 return max_acpu_level;
1445}
1446
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001447static struct acpuclk_data acpuclk_8960_data = {
1448 .set_rate = acpuclk_8960_set_rate,
1449 .get_rate = acpuclk_8960_get_rate,
1450 .power_collapse_khz = STBY_KHZ,
1451 .wait_for_irq_khz = STBY_KHZ,
1452};
1453
Matt Wagantallec57f062011-08-16 23:54:46 -07001454static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001455{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001456 struct acpu_level *max_acpu_level = select_freq_plan();
1457 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1458 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001459
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001460 regulator_init();
1461 bus_init();
1462 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001463
1464 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001465 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001466
1467 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001468}
Matt Wagantallec57f062011-08-16 23:54:46 -07001469
1470struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1471 .init = acpuclk_8960_init,
1472};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001473
1474struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1475 .init = acpuclk_8960_init,
1476};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001477
1478struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1479 .init = acpuclk_8960_init,
1480};