blob: b00d4a0acf508231404dcea522f09731003526e8 [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 Boyd1be9bf62011-11-21 10:51:46 -0800461};
462
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800463static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd5766f682011-12-27 19:21:08 -0800464 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 975000 },
465 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 975000 },
466 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 1000000 },
467 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 1000000 },
468 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 1025000 },
469 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1025000 },
470 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
471 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1050000 },
472 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1075000 },
473 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1075000 },
474 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
475 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1100000 },
476 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1125000 },
477 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1125000 },
478 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1225000 },
479 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1225000 },
480 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1250000 },
481 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1250000 },
482 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1275000 },
483 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1275000 },
484 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1287500 },
485 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1287500 },
486 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1300000 },
487 { 0, { 0 } }
488};
489
490static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
491 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 925000 },
492 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 925000 },
493 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 950000 },
494 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 950000 },
495 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 975000 },
496 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 975000 },
497 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1000000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800498 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
499 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800500 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1025000 },
501 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1050000 },
502 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1050000 },
503 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1075000 },
504 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1075000 },
505 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
506 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
507 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
508 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
509 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
510 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
511 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
512 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1237500 },
Stephen Boyd2869cfb2011-12-14 09:17:23 -0800513 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800514 { 0, { 0 } }
515};
516
Stephen Boyd5766f682011-12-27 19:21:08 -0800517static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
518 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 875000 },
519 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 875000 },
520 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 900000 },
521 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 900000 },
522 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 925000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800523 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800524 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 950000 },
525 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 950000 },
526 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 975000 },
527 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 975000 },
528 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1000000 },
529 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1000000 },
530 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1025000 },
531 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1025000 },
532 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
533 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
534 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
535 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1150000 },
536 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1175000 },
Stephen Boyd2869cfb2011-12-14 09:17:23 -0800537 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
538 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800539 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1187500 },
540 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1200000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800541 { 0, { 0 } }
542};
543
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700544/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
545#undef L2
546#define L2(x) (&l2_freq_tbl_8064[(x)])
547static struct l2_level l2_freq_tbl_8064[] = {
548 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
549 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
550 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
551 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
552 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
553 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
554 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
555 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
556 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
557 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
558 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
559 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
560 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
561 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
562 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
563 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
564 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
565 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
566 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
567 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
568 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
569 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
570 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
571 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
572 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
573 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
574};
575
576/* TODO: Update core voltages when data is available. */
577static struct acpu_level acpu_freq_tbl_8064[] = {
578 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
579 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
580 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
581 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
582 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
583 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
584 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
585 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
586 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
587 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
588 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
589 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
590 { 0, { 0 } }
591};
592
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800593/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
594#undef L2
595#define L2(x) (&l2_freq_tbl_8930[(x)])
596static struct l2_level l2_freq_tbl_8930[] = {
597 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
598 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
599 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
600 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
601 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
602 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
603 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
604 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
605 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
606 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
607 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
608 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
609 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
610 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
611 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
612 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
613 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
614};
615
616/* TODO: Update core voltages when data is available. */
617static struct acpu_level acpu_freq_tbl_8930[] = {
618 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
619 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
620 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
621 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
622 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
623 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
624 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
625 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
626 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
627 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
628 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
629 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
630 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
631 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
632 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
633 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
634 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
635 { 0, { 0 } }
636};
637
Tianyi Goue0b34de2011-12-20 11:20:10 -0800638/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
639#undef L2
640#define L2(x) (&l2_freq_tbl_8627[(x)])
641static struct l2_level l2_freq_tbl_8627[] = {
642 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
643 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
644 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
645 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
646 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
647 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
648 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
649 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 3 },
650 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
651 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
652 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
653 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 4 },
654 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 4 },
655};
656
657/* TODO: Update core voltages when data is available. */
658static struct acpu_level acpu_freq_tbl_8627[] = {
659 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
660 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
661 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
662 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
663 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
664 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
665 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
666 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
667 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
668 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
669 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
670 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
671 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
672 { 0, { 0 } }
673};
674
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700675static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676{
677 return scalable[cpu].current_speed->khz;
678}
679
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700680/* Get the selected source on primary MUX. */
681static int get_pri_clk_src(struct scalable *sc)
682{
683 uint32_t regval;
684
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700685 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686 return regval & 0x3;
687}
688
689/* Set the selected source on primary MUX. */
690static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
691{
692 uint32_t regval;
693
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700694 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700695 regval &= ~0x3;
696 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700697 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698 /* Wait for switch to complete. */
699 mb();
700 udelay(1);
701}
702
703/* Get the selected source on secondary MUX. */
704static int get_sec_clk_src(struct scalable *sc)
705{
706 uint32_t regval;
707
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700708 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700709 return (regval >> 2) & 0x3;
710}
711
712/* Set the selected source on secondary MUX. */
713static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
714{
715 uint32_t regval;
716
717 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700718 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700719 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700720 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721
722 /* Program the MUX. */
723 regval &= ~(0x3 << 2);
724 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700725 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700726
727 /* Wait for switch to complete. */
728 mb();
729 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700730
731 /* Re-enable secondary source clock gating. */
732 regval &= ~SECCLKAGD;
733 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734}
735
736/* Enable an already-configured HFPLL. */
737static void hfpll_enable(struct scalable *sc)
738{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700739 int rc;
740
Tianyi Goue0b34de2011-12-20 11:20:10 -0800741 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm8627()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700742 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
Matt Wagantall627f4312011-12-13 13:33:47 -0800743 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 2100000,
744 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700745 if (rc)
746 pr_err("%s regulator enable failed (%d)\n",
747 sc->vreg[VREG_HFPLL_A].name, rc);
748 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
749 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
Matt Wagantall627f4312011-12-13 13:33:47 -0800750 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700751 if (rc)
752 pr_err("%s regulator enable failed (%d)\n",
753 sc->vreg[VREG_HFPLL_B].name, rc);
754 }
755
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 /* Disable PLL bypass mode. */
757 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
758
759 /*
760 * H/W requires a 5us delay between disabling the bypass and
761 * de-asserting the reset. Delay 10us just to be safe.
762 */
763 mb();
764 udelay(10);
765
766 /* De-assert active-low PLL reset. */
767 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
768
769 /* Wait for PLL to lock. */
770 mb();
771 udelay(60);
772
773 /* Enable PLL output. */
774 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
775}
776
777/* Disable a HFPLL for power-savings or while its being reprogrammed. */
778static void hfpll_disable(struct scalable *sc)
779{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700780 int rc;
781
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782 /*
783 * Disable the PLL output, disable test mode, enable
784 * the bypass mode, and assert the reset.
785 */
786 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700787
Tianyi Goue0b34de2011-12-20 11:20:10 -0800788 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm8627()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700789 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
790 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
791 0, 0);
792 if (rc)
793 pr_err("%s regulator enable failed (%d)\n",
794 sc->vreg[VREG_HFPLL_B].name, rc);
795 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
796 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 0,
797 0, 0);
798 if (rc)
799 pr_err("%s regulator enable failed (%d)\n",
800 sc->vreg[VREG_HFPLL_A].name, rc);
801 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700802}
803
804/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
805static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
806{
807 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
808}
809
810/* Return the L2 speed that should be applied. */
811static struct l2_level *compute_l2_level(struct scalable *sc,
812 struct l2_level *vote_l)
813{
814 struct l2_level *new_l;
815 int cpu;
816
817 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700818 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700819
820 /* Find max L2 speed vote. */
821 sc->l2_vote = vote_l;
822 new_l = l2_freq_tbl;
823 for_each_present_cpu(cpu)
824 new_l = max(new_l, scalable[cpu].l2_vote);
825
826 return new_l;
827}
828
829/* Update the bus bandwidth request. */
830static void set_bus_bw(unsigned int bw)
831{
832 int ret;
833
834 /* Bounds check. */
835 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
836 pr_err("invalid bandwidth request (%d)\n", bw);
837 return;
838 }
839
840 /* Update bandwidth if request has changed. This may sleep. */
841 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
842 if (ret)
843 pr_err("bandwidth request failed (%d)\n", ret);
844}
845
846/* Set the CPU or L2 clock speed. */
847static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
848 enum setrate_reason reason)
849{
850 struct core_speed *strt_s = sc->current_speed;
851
852 if (tgt_s == strt_s)
853 return;
854
855 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700856 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700857 * Move to an always-on source running at a frequency that does
858 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700859 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700860 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700861 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
862
863 /* Program CPU HFPLL. */
864 hfpll_disable(sc);
865 hfpll_set_rate(sc, tgt_s);
866 hfpll_enable(sc);
867
868 /* Move CPU to HFPLL source. */
869 set_pri_clk_src(sc, tgt_s->pri_src_sel);
870 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700871 /*
872 * If responding to CPU_DEAD we must be running on another
873 * CPU. Therefore, we can't access the downed CPU's CP15
874 * clock MUX registers from here and can't change clock sources.
875 * Just turn off the PLL- since the CPU is down already, halting
876 * its clock should be safe.
877 */
878 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
879 set_sec_clk_src(sc, tgt_s->sec_src_sel);
880 set_pri_clk_src(sc, tgt_s->pri_src_sel);
881 }
882 hfpll_disable(sc);
883 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
884 hfpll_set_rate(sc, tgt_s);
885 hfpll_enable(sc);
886 /*
887 * If responding to CPU_UP_PREPARE, we can't change CP15
888 * registers for the CPU that's coming up since we're not
889 * running on that CPU. That's okay though, since the MUX
890 * source was not changed on the way down, either.
891 */
892 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
893 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700894 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
896 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897 }
898
899 sc->current_speed = tgt_s;
900}
901
902/* Apply any per-cpu voltage increases. */
903static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
904 unsigned int vdd_dig, enum setrate_reason reason)
905{
906 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700907 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700908
909 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700910 * Increase vdd_mem active-set before vdd_dig.
911 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912 */
913 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
914 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
915 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
916 sc->vreg[VREG_MEM].max_vdd, 0);
917 if (rc) {
918 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
919 __func__, cpu, rc);
920 return rc;
921 }
922 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
923 }
924
925 /* Increase vdd_dig active-set vote. */
926 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
927 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
928 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
929 sc->vreg[VREG_DIG].max_vdd, 0);
930 if (rc) {
931 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
932 __func__, cpu, rc);
933 return rc;
934 }
935 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
936 }
937
938 /*
939 * Update per-CPU core voltage. Don't do this for the hotplug path for
940 * which it should already be correct. Attempting to set it is bad
941 * because we don't know what CPU we are running on at this point, but
942 * the CPU regulator API requires we call it from the affected CPU.
943 */
944 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
945 && reason != SETRATE_HOTPLUG) {
946 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
947 sc->vreg[VREG_CORE].max_vdd);
948 if (rc) {
949 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
950 __func__, cpu, rc);
951 return rc;
952 }
953 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
954 }
955
956 return rc;
957}
958
959/* Apply any per-cpu voltage decreases. */
960static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
961 unsigned int vdd_dig, enum setrate_reason reason)
962{
963 struct scalable *sc = &scalable[cpu];
964 int ret;
965
966 /*
967 * Update per-CPU core voltage. This must be called on the CPU
968 * that's being affected. Don't do this in the hotplug remove path,
969 * where the rail is off and we're executing on the other CPU.
970 */
971 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
972 && reason != SETRATE_HOTPLUG) {
973 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
974 sc->vreg[VREG_CORE].max_vdd);
975 if (ret) {
976 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
977 __func__, cpu, ret);
978 return;
979 }
980 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
981 }
982
983 /* Decrease vdd_dig active-set vote. */
984 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
985 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
986 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
987 sc->vreg[VREG_DIG].max_vdd, 0);
988 if (ret) {
989 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
990 __func__, cpu, ret);
991 return;
992 }
993 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
994 }
995
996 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700997 * Decrease vdd_mem active-set after vdd_dig.
998 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700999 */
1000 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1001 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1002 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1003 sc->vreg[VREG_MEM].max_vdd, 0);
1004 if (ret) {
1005 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
1006 __func__, cpu, ret);
1007 return;
1008 }
1009 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1010 }
1011}
1012
1013static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1014{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001015 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001016}
1017
1018static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1019{
1020 unsigned int pll_vdd_dig;
1021
Stephen Boydc76158f2011-12-08 12:42:40 -08001022 if (tgt->l2_level->speed.src != HFPLL)
1023 pll_vdd_dig = 0;
1024 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001025 pll_vdd_dig = HFPLL_NOMINAL_VDD;
1026 else
1027 pll_vdd_dig = HFPLL_LOW_VDD;
1028
1029 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1030}
1031
1032static unsigned int calculate_vdd_core(struct acpu_level *tgt)
1033{
1034 unsigned int pll_vdd_core;
1035
Stephen Boydc76158f2011-12-08 12:42:40 -08001036 if (tgt->speed.src != HFPLL)
1037 pll_vdd_core = 0;
1038 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039 pll_vdd_core = HFPLL_NOMINAL_VDD;
1040 else
1041 pll_vdd_core = HFPLL_LOW_VDD;
1042
1043 return max(tgt->vdd_core, pll_vdd_core);
1044}
1045
1046/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001047static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1048 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001049{
1050 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1051 struct l2_level *tgt_l2_l;
1052 struct acpu_level *tgt;
1053 unsigned int vdd_mem, vdd_dig, vdd_core;
1054 unsigned long flags;
1055 int rc = 0;
1056
1057 if (cpu > num_possible_cpus()) {
1058 rc = -EINVAL;
1059 goto out;
1060 }
1061
1062 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1063 mutex_lock(&driver_lock);
1064
1065 strt_acpu_s = scalable[cpu].current_speed;
1066
1067 /* Return early if rate didn't change. */
1068 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1069 goto out;
1070
1071 /* Find target frequency. */
1072 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1073 if (tgt->speed.khz == rate) {
1074 tgt_acpu_s = &tgt->speed;
1075 break;
1076 }
1077 }
1078 if (tgt->speed.khz == 0) {
1079 rc = -EINVAL;
1080 goto out;
1081 }
1082
1083 /* Calculate voltage requirements for the current CPU. */
1084 vdd_mem = calculate_vdd_mem(tgt);
1085 vdd_dig = calculate_vdd_dig(tgt);
1086 vdd_core = calculate_vdd_core(tgt);
1087
1088 /* Increase VDD levels if needed. */
1089 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1090 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1091 if (rc)
1092 goto out;
1093 }
1094
1095 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1096 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1097
1098 /* Set the CPU speed. */
1099 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1100
1101 /*
1102 * Update the L2 vote and apply the rate change. A spinlock is
1103 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001104 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001105 * and the driver_lock mutex is not acquired.
1106 */
1107 spin_lock_irqsave(&l2_lock, flags);
1108 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1109 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1110 spin_unlock_irqrestore(&l2_lock, flags);
1111
1112 /* Nothing else to do for power collapse or SWFI. */
1113 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1114 goto out;
1115
1116 /* Update bus bandwith request. */
1117 set_bus_bw(tgt_l2_l->bw_level);
1118
1119 /* Drop VDD levels if we can. */
1120 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1121
1122 scalable[cpu].first_set_call = false;
1123 pr_debug("ACPU%d speed change complete\n", cpu);
1124
1125out:
1126 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1127 mutex_unlock(&driver_lock);
1128 return rc;
1129}
1130
1131/* Initialize a HFPLL at a given rate and enable it. */
1132static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1133{
1134 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1135
1136 /* Disable the PLL for re-programming. */
1137 hfpll_disable(sc);
1138
1139 /* Configure PLL parameters for integer mode. */
1140 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1141 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1142 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1143
1144 /* Program droop controller. */
1145 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1146
1147 /* Set an initial rate and enable the PLL. */
1148 hfpll_set_rate(sc, tgt_s);
1149 hfpll_enable(sc);
1150}
1151
1152/* Voltage regulator initialization. */
1153static void __init regulator_init(void)
1154{
1155 int cpu, ret;
1156 struct scalable *sc;
1157
1158 for_each_possible_cpu(cpu) {
1159 sc = &scalable[cpu];
1160 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1161 sc->vreg[VREG_CORE].name);
1162 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1163 pr_err("regulator_get(%s) failed (%ld)\n",
1164 sc->vreg[VREG_CORE].name,
1165 PTR_ERR(sc->vreg[VREG_CORE].reg));
1166 BUG();
1167 }
1168
1169 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
1170 sc->vreg[VREG_CORE].max_vdd,
1171 sc->vreg[VREG_CORE].max_vdd);
1172 if (ret)
1173 pr_err("regulator_set_voltage(%s) failed"
1174 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1175
1176 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1177 if (ret)
1178 pr_err("regulator_enable(%s) failed (%d)\n",
1179 sc->vreg[VREG_CORE].name, ret);
1180 }
1181}
1182
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001183/* Set initial rate for a given core. */
1184static void __init init_clock_sources(struct scalable *sc,
1185 struct core_speed *tgt_s)
1186{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001187 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001188
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001189 /* Select PLL8 as AUX source input to the secondary MUX. */
1190 writel_relaxed(0x3, sc->aux_clk_sel);
1191
1192 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001193 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001194 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195 hfpll_init(sc, tgt_s);
1196
1197 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001198 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001199 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001200 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001201
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001202 /* Switch to the target clock source. */
1203 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001204 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1205 sc->current_speed = tgt_s;
1206
1207 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001208 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1209 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001210 */
1211 sc->first_set_call = true;
1212}
1213
Matt Wagantall8e726c72011-08-06 00:49:28 -07001214static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001215{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001216 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001217 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001218
1219 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1220 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001221}
1222
1223/* Register with bus driver. */
1224static void __init bus_init(void)
1225{
1226 int ret;
1227
1228 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1229 if (!bus_perf_client) {
1230 pr_err("unable to register bus client\n");
1231 BUG();
1232 }
1233
1234 ret = msm_bus_scale_client_update_request(bus_perf_client,
1235 (ARRAY_SIZE(bw_level_tbl)-1));
1236 if (ret)
1237 pr_err("initial bandwidth request failed (%d)\n", ret);
1238}
1239
1240#ifdef CONFIG_CPU_FREQ_MSM
1241static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1242
1243static void __init cpufreq_table_init(void)
1244{
1245 int cpu;
1246
1247 for_each_possible_cpu(cpu) {
1248 int i, freq_cnt = 0;
1249 /* Construct the freq_table tables from acpu_freq_tbl. */
1250 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1251 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1252 if (acpu_freq_tbl[i].use_for_scaling) {
1253 freq_table[cpu][freq_cnt].index = freq_cnt;
1254 freq_table[cpu][freq_cnt].frequency
1255 = acpu_freq_tbl[i].speed.khz;
1256 freq_cnt++;
1257 }
1258 }
1259 /* freq_table not big enough to store all usable freqs. */
1260 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1261
1262 freq_table[cpu][freq_cnt].index = freq_cnt;
1263 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1264
1265 pr_info("CPU%d: %d scaling frequencies supported.\n",
1266 cpu, freq_cnt);
1267
1268 /* Register table with CPUFreq. */
1269 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1270 }
1271}
1272#else
1273static void __init cpufreq_table_init(void) {}
1274#endif
1275
1276#define HOT_UNPLUG_KHZ STBY_KHZ
1277static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1278 unsigned long action, void *hcpu)
1279{
1280 static int prev_khz[NR_CPUS];
1281 static int prev_pri_src[NR_CPUS];
1282 static int prev_sec_src[NR_CPUS];
1283 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001284
1285 switch (action) {
1286 case CPU_DYING:
1287 case CPU_DYING_FROZEN:
1288 /*
Matt Wagantall27663842011-08-25 15:11:48 -07001289 * On Krait v1, the primary and secondary muxes must be set
1290 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001291 */
Matt Wagantall27663842011-08-25 15:11:48 -07001292 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001293 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1294 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1295 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1296 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1297 }
1298 break;
1299 case CPU_DEAD:
1300 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001301 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001302 /* Fall through. */
1303 case CPU_UP_CANCELED:
1304 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001305 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001306 break;
1307 case CPU_UP_PREPARE:
1308 case CPU_UP_PREPARE_FROZEN:
1309 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001310 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001311 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001312 break;
1313 case CPU_STARTING:
1314 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001315 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001316 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1317 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1318 }
1319 break;
1320 default:
1321 break;
1322 }
1323
1324 return NOTIFY_OK;
1325}
1326
1327static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1328 .notifier_call = acpuclock_cpu_callback,
1329};
1330
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001331static const int krait_needs_vmin(void)
1332{
1333 switch (read_cpuid_id()) {
1334 case 0x511F04D0:
1335 case 0x511F04D1:
1336 case 0x510F06F0:
1337 return 1;
1338 default:
1339 return 0;
1340 };
1341}
1342
Stephen Boydaefb8de2012-01-05 19:05:01 -08001343static void kraitv2_apply_vmin(struct acpu_level *tbl)
1344{
1345 for (; tbl->speed.khz != 0; tbl++)
1346 if (tbl->vdd_core < 1150000)
1347 tbl->vdd_core = 1150000;
1348}
1349
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001350static struct acpu_level * __init select_freq_plan(void)
1351{
1352 struct acpu_level *l, *max_acpu_level = NULL;
1353
1354 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001355 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001356 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001357 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001358
1359 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1360 pvs = (pte_efuse >> 10) & 0x7;
1361 if (pvs == 0x7)
1362 pvs = (pte_efuse >> 13) & 0x7;
1363
1364 switch (pvs) {
1365 case 0x0:
1366 case 0x7:
1367 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001368 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1369 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001370 break;
1371 case 0x1:
1372 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001373 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001374 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001375 break;
1376 case 0x3:
1377 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001378 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001379 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001380 break;
1381 default:
1382 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001383 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1384 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001385 break;
1386 }
1387
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001388 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001389 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001390 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001391 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1392 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1393 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001394 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001395 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1396 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1397 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001398 } else if (cpu_is_apq8064()) {
1399 scalable = scalable_8064;
1400 acpu_freq_tbl = acpu_freq_tbl_8064;
1401 l2_freq_tbl = l2_freq_tbl_8064;
1402 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001403 } else if (cpu_is_msm8627()) {
1404 scalable = scalable_8627;
1405 acpu_freq_tbl = acpu_freq_tbl_8627;
1406 l2_freq_tbl = l2_freq_tbl_8627;
1407 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001408 } else if (cpu_is_msm8930()) {
1409 scalable = scalable_8930;
1410 acpu_freq_tbl = acpu_freq_tbl_8930;
1411 l2_freq_tbl = l2_freq_tbl_8930;
1412 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001413 } else {
1414 BUG();
1415 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001416 if (krait_needs_vmin())
1417 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001418
1419 /* Find the max supported scaling frequency. */
1420 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1421 if (l->use_for_scaling)
1422 max_acpu_level = l;
1423 BUG_ON(!max_acpu_level);
1424 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1425
1426 return max_acpu_level;
1427}
1428
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001429static struct acpuclk_data acpuclk_8960_data = {
1430 .set_rate = acpuclk_8960_set_rate,
1431 .get_rate = acpuclk_8960_get_rate,
1432 .power_collapse_khz = STBY_KHZ,
1433 .wait_for_irq_khz = STBY_KHZ,
1434};
1435
Matt Wagantallec57f062011-08-16 23:54:46 -07001436static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001437{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001438 struct acpu_level *max_acpu_level = select_freq_plan();
1439 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1440 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001441
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001442 regulator_init();
1443 bus_init();
1444 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001445
1446 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001447 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001448
1449 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001450}
Matt Wagantallec57f062011-08-16 23:54:46 -07001451
1452struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1453 .init = acpuclk_8960_init,
1454};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001455
1456struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1457 .init = acpuclk_8960_init,
1458};