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