blob: 4cf75b600a3de427e855385f90719fd71101253a [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
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[] = {
464 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
465 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
466 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
467 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
468 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
469 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
470 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
471 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
472 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
473 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
474 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
475 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
Stephen Boyd2869cfb2011-12-14 09:17:23 -0800476 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
477 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
478 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
479 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
480 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
481 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1137500 },
482 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1150000 },
483 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
484 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
485 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1225000 },
486 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800487 { 0, { 0 } }
488};
489
490static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom_fast[] = {
491 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
492 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
493 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
494 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
495 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
496 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
497 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
498 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
499 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
500 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
501 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
502 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Stephen Boyd2869cfb2011-12-14 09:17:23 -0800503 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
504 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
505 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
506 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
507 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
508 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1137500 },
509 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1150000 },
510 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
511 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
512 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1225000 },
513 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800514 { 0, { 0 } }
515};
516
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700517/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
518#undef L2
519#define L2(x) (&l2_freq_tbl_8064[(x)])
520static struct l2_level l2_freq_tbl_8064[] = {
521 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
522 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
523 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
524 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
525 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
526 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
527 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
528 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
529 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
530 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
531 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
532 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
533 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
534 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
535 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
536 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
537 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
538 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
539 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
540 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
541 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
542 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
543 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
544 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
545 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
546 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
547};
548
549/* TODO: Update core voltages when data is available. */
550static struct acpu_level acpu_freq_tbl_8064[] = {
551 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
552 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
553 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
554 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
555 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
556 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
557 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
558 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
559 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
560 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
561 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
562 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
563 { 0, { 0 } }
564};
565
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800566/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
567#undef L2
568#define L2(x) (&l2_freq_tbl_8930[(x)])
569static struct l2_level l2_freq_tbl_8930[] = {
570 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
571 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
572 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
573 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
574 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
575 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
576 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
577 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
578 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
579 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
580 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
581 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
582 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
583 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
584 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
585 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
586 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
587};
588
589/* TODO: Update core voltages when data is available. */
590static struct acpu_level acpu_freq_tbl_8930[] = {
591 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
592 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
593 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
594 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
595 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
596 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
597 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
598 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
599 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
600 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
601 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
602 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
603 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
604 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
605 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
606 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
607 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
608 { 0, { 0 } }
609};
610
Tianyi Goue0b34de2011-12-20 11:20:10 -0800611/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
612#undef L2
613#define L2(x) (&l2_freq_tbl_8627[(x)])
614static struct l2_level l2_freq_tbl_8627[] = {
615 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
616 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
617 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
618 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
619 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
620 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
621 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
622 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 3 },
623 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
624 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
625 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
626 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 4 },
627 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 4 },
628};
629
630/* TODO: Update core voltages when data is available. */
631static struct acpu_level acpu_freq_tbl_8627[] = {
632 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
633 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
634 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
635 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
636 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
637 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
638 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
639 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
640 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
641 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
642 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
643 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
644 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
645 { 0, { 0 } }
646};
647
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700648static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649{
650 return scalable[cpu].current_speed->khz;
651}
652
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700653/* Get the selected source on primary MUX. */
654static int get_pri_clk_src(struct scalable *sc)
655{
656 uint32_t regval;
657
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700658 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700659 return regval & 0x3;
660}
661
662/* Set the selected source on primary MUX. */
663static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
664{
665 uint32_t regval;
666
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700667 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700668 regval &= ~0x3;
669 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700670 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700671 /* Wait for switch to complete. */
672 mb();
673 udelay(1);
674}
675
676/* Get the selected source on secondary MUX. */
677static int get_sec_clk_src(struct scalable *sc)
678{
679 uint32_t regval;
680
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700681 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700682 return (regval >> 2) & 0x3;
683}
684
685/* Set the selected source on secondary MUX. */
686static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
687{
688 uint32_t regval;
689
690 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700691 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700692 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700693 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700694
695 /* Program the MUX. */
696 regval &= ~(0x3 << 2);
697 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700698 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700699
700 /* Wait for switch to complete. */
701 mb();
702 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700703
704 /* Re-enable secondary source clock gating. */
705 regval &= ~SECCLKAGD;
706 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700707}
708
709/* Enable an already-configured HFPLL. */
710static void hfpll_enable(struct scalable *sc)
711{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700712 int rc;
713
Tianyi Goue0b34de2011-12-20 11:20:10 -0800714 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm8627()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700715 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
Matt Wagantall627f4312011-12-13 13:33:47 -0800716 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 2100000,
717 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700718 if (rc)
719 pr_err("%s regulator enable failed (%d)\n",
720 sc->vreg[VREG_HFPLL_A].name, rc);
721 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
722 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
Matt Wagantall627f4312011-12-13 13:33:47 -0800723 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700724 if (rc)
725 pr_err("%s regulator enable failed (%d)\n",
726 sc->vreg[VREG_HFPLL_B].name, rc);
727 }
728
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700729 /* Disable PLL bypass mode. */
730 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
731
732 /*
733 * H/W requires a 5us delay between disabling the bypass and
734 * de-asserting the reset. Delay 10us just to be safe.
735 */
736 mb();
737 udelay(10);
738
739 /* De-assert active-low PLL reset. */
740 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
741
742 /* Wait for PLL to lock. */
743 mb();
744 udelay(60);
745
746 /* Enable PLL output. */
747 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
748}
749
750/* Disable a HFPLL for power-savings or while its being reprogrammed. */
751static void hfpll_disable(struct scalable *sc)
752{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700753 int rc;
754
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700755 /*
756 * Disable the PLL output, disable test mode, enable
757 * the bypass mode, and assert the reset.
758 */
759 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700760
Tianyi Goue0b34de2011-12-20 11:20:10 -0800761 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm8627()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700762 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
763 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
764 0, 0);
765 if (rc)
766 pr_err("%s regulator enable failed (%d)\n",
767 sc->vreg[VREG_HFPLL_B].name, rc);
768 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
769 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 0,
770 0, 0);
771 if (rc)
772 pr_err("%s regulator enable failed (%d)\n",
773 sc->vreg[VREG_HFPLL_A].name, rc);
774 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700775}
776
777/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
778static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
779{
780 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
781}
782
783/* Return the L2 speed that should be applied. */
784static struct l2_level *compute_l2_level(struct scalable *sc,
785 struct l2_level *vote_l)
786{
787 struct l2_level *new_l;
788 int cpu;
789
790 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700791 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700792
793 /* Find max L2 speed vote. */
794 sc->l2_vote = vote_l;
795 new_l = l2_freq_tbl;
796 for_each_present_cpu(cpu)
797 new_l = max(new_l, scalable[cpu].l2_vote);
798
799 return new_l;
800}
801
802/* Update the bus bandwidth request. */
803static void set_bus_bw(unsigned int bw)
804{
805 int ret;
806
807 /* Bounds check. */
808 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
809 pr_err("invalid bandwidth request (%d)\n", bw);
810 return;
811 }
812
813 /* Update bandwidth if request has changed. This may sleep. */
814 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
815 if (ret)
816 pr_err("bandwidth request failed (%d)\n", ret);
817}
818
819/* Set the CPU or L2 clock speed. */
820static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
821 enum setrate_reason reason)
822{
823 struct core_speed *strt_s = sc->current_speed;
824
825 if (tgt_s == strt_s)
826 return;
827
828 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700829 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700830 * Move to an always-on source running at a frequency that does
831 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700832 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700833 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700834 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
835
836 /* Program CPU HFPLL. */
837 hfpll_disable(sc);
838 hfpll_set_rate(sc, tgt_s);
839 hfpll_enable(sc);
840
841 /* Move CPU to HFPLL source. */
842 set_pri_clk_src(sc, tgt_s->pri_src_sel);
843 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844 /*
845 * If responding to CPU_DEAD we must be running on another
846 * CPU. Therefore, we can't access the downed CPU's CP15
847 * clock MUX registers from here and can't change clock sources.
848 * Just turn off the PLL- since the CPU is down already, halting
849 * its clock should be safe.
850 */
851 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
852 set_sec_clk_src(sc, tgt_s->sec_src_sel);
853 set_pri_clk_src(sc, tgt_s->pri_src_sel);
854 }
855 hfpll_disable(sc);
856 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
857 hfpll_set_rate(sc, tgt_s);
858 hfpll_enable(sc);
859 /*
860 * If responding to CPU_UP_PREPARE, we can't change CP15
861 * registers for the CPU that's coming up since we're not
862 * running on that CPU. That's okay though, since the MUX
863 * source was not changed on the way down, either.
864 */
865 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
866 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
869 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700870 }
871
872 sc->current_speed = tgt_s;
873}
874
875/* Apply any per-cpu voltage increases. */
876static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
877 unsigned int vdd_dig, enum setrate_reason reason)
878{
879 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700880 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700881
882 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700883 * Increase vdd_mem active-set before vdd_dig.
884 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700885 */
886 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
887 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
888 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
889 sc->vreg[VREG_MEM].max_vdd, 0);
890 if (rc) {
891 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
892 __func__, cpu, rc);
893 return rc;
894 }
895 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
896 }
897
898 /* Increase vdd_dig active-set vote. */
899 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
900 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
901 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
902 sc->vreg[VREG_DIG].max_vdd, 0);
903 if (rc) {
904 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
905 __func__, cpu, rc);
906 return rc;
907 }
908 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
909 }
910
911 /*
912 * Update per-CPU core voltage. Don't do this for the hotplug path for
913 * which it should already be correct. Attempting to set it is bad
914 * because we don't know what CPU we are running on at this point, but
915 * the CPU regulator API requires we call it from the affected CPU.
916 */
917 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
918 && reason != SETRATE_HOTPLUG) {
919 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
920 sc->vreg[VREG_CORE].max_vdd);
921 if (rc) {
922 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
923 __func__, cpu, rc);
924 return rc;
925 }
926 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
927 }
928
929 return rc;
930}
931
932/* Apply any per-cpu voltage decreases. */
933static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
934 unsigned int vdd_dig, enum setrate_reason reason)
935{
936 struct scalable *sc = &scalable[cpu];
937 int ret;
938
939 /*
940 * Update per-CPU core voltage. This must be called on the CPU
941 * that's being affected. Don't do this in the hotplug remove path,
942 * where the rail is off and we're executing on the other CPU.
943 */
944 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
945 && reason != SETRATE_HOTPLUG) {
946 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
947 sc->vreg[VREG_CORE].max_vdd);
948 if (ret) {
949 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
950 __func__, cpu, ret);
951 return;
952 }
953 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
954 }
955
956 /* Decrease vdd_dig active-set vote. */
957 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
958 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
959 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
960 sc->vreg[VREG_DIG].max_vdd, 0);
961 if (ret) {
962 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
963 __func__, cpu, ret);
964 return;
965 }
966 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
967 }
968
969 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700970 * Decrease vdd_mem active-set after vdd_dig.
971 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700972 */
973 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
974 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
975 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
976 sc->vreg[VREG_MEM].max_vdd, 0);
977 if (ret) {
978 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
979 __func__, cpu, ret);
980 return;
981 }
982 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
983 }
984}
985
986static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
987{
Matt Wagantallabd55f02011-09-12 11:45:54 -0700988 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700989}
990
991static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
992{
993 unsigned int pll_vdd_dig;
994
Stephen Boydc76158f2011-12-08 12:42:40 -0800995 if (tgt->l2_level->speed.src != HFPLL)
996 pll_vdd_dig = 0;
997 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700998 pll_vdd_dig = HFPLL_NOMINAL_VDD;
999 else
1000 pll_vdd_dig = HFPLL_LOW_VDD;
1001
1002 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1003}
1004
1005static unsigned int calculate_vdd_core(struct acpu_level *tgt)
1006{
1007 unsigned int pll_vdd_core;
1008
Stephen Boydc76158f2011-12-08 12:42:40 -08001009 if (tgt->speed.src != HFPLL)
1010 pll_vdd_core = 0;
1011 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001012 pll_vdd_core = HFPLL_NOMINAL_VDD;
1013 else
1014 pll_vdd_core = HFPLL_LOW_VDD;
1015
1016 return max(tgt->vdd_core, pll_vdd_core);
1017}
1018
1019/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001020static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1021 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001022{
1023 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1024 struct l2_level *tgt_l2_l;
1025 struct acpu_level *tgt;
1026 unsigned int vdd_mem, vdd_dig, vdd_core;
1027 unsigned long flags;
1028 int rc = 0;
1029
1030 if (cpu > num_possible_cpus()) {
1031 rc = -EINVAL;
1032 goto out;
1033 }
1034
1035 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1036 mutex_lock(&driver_lock);
1037
1038 strt_acpu_s = scalable[cpu].current_speed;
1039
1040 /* Return early if rate didn't change. */
1041 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1042 goto out;
1043
1044 /* Find target frequency. */
1045 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1046 if (tgt->speed.khz == rate) {
1047 tgt_acpu_s = &tgt->speed;
1048 break;
1049 }
1050 }
1051 if (tgt->speed.khz == 0) {
1052 rc = -EINVAL;
1053 goto out;
1054 }
1055
1056 /* Calculate voltage requirements for the current CPU. */
1057 vdd_mem = calculate_vdd_mem(tgt);
1058 vdd_dig = calculate_vdd_dig(tgt);
1059 vdd_core = calculate_vdd_core(tgt);
1060
1061 /* Increase VDD levels if needed. */
1062 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1063 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1064 if (rc)
1065 goto out;
1066 }
1067
1068 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1069 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1070
1071 /* Set the CPU speed. */
1072 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1073
1074 /*
1075 * Update the L2 vote and apply the rate change. A spinlock is
1076 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001077 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001078 * and the driver_lock mutex is not acquired.
1079 */
1080 spin_lock_irqsave(&l2_lock, flags);
1081 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1082 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1083 spin_unlock_irqrestore(&l2_lock, flags);
1084
1085 /* Nothing else to do for power collapse or SWFI. */
1086 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1087 goto out;
1088
1089 /* Update bus bandwith request. */
1090 set_bus_bw(tgt_l2_l->bw_level);
1091
1092 /* Drop VDD levels if we can. */
1093 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1094
1095 scalable[cpu].first_set_call = false;
1096 pr_debug("ACPU%d speed change complete\n", cpu);
1097
1098out:
1099 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1100 mutex_unlock(&driver_lock);
1101 return rc;
1102}
1103
1104/* Initialize a HFPLL at a given rate and enable it. */
1105static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1106{
1107 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1108
1109 /* Disable the PLL for re-programming. */
1110 hfpll_disable(sc);
1111
1112 /* Configure PLL parameters for integer mode. */
1113 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1114 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1115 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1116
1117 /* Program droop controller. */
1118 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1119
1120 /* Set an initial rate and enable the PLL. */
1121 hfpll_set_rate(sc, tgt_s);
1122 hfpll_enable(sc);
1123}
1124
1125/* Voltage regulator initialization. */
1126static void __init regulator_init(void)
1127{
1128 int cpu, ret;
1129 struct scalable *sc;
1130
1131 for_each_possible_cpu(cpu) {
1132 sc = &scalable[cpu];
1133 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1134 sc->vreg[VREG_CORE].name);
1135 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1136 pr_err("regulator_get(%s) failed (%ld)\n",
1137 sc->vreg[VREG_CORE].name,
1138 PTR_ERR(sc->vreg[VREG_CORE].reg));
1139 BUG();
1140 }
1141
1142 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
1143 sc->vreg[VREG_CORE].max_vdd,
1144 sc->vreg[VREG_CORE].max_vdd);
1145 if (ret)
1146 pr_err("regulator_set_voltage(%s) failed"
1147 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1148
1149 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1150 if (ret)
1151 pr_err("regulator_enable(%s) failed (%d)\n",
1152 sc->vreg[VREG_CORE].name, ret);
1153 }
1154}
1155
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001156/* Set initial rate for a given core. */
1157static void __init init_clock_sources(struct scalable *sc,
1158 struct core_speed *tgt_s)
1159{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001160 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001161
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001162 /* Select PLL8 as AUX source input to the secondary MUX. */
1163 writel_relaxed(0x3, sc->aux_clk_sel);
1164
1165 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001166 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001167 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001168 hfpll_init(sc, tgt_s);
1169
1170 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001171 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001172 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001173 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001174
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001175 /* Switch to the target clock source. */
1176 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1178 sc->current_speed = tgt_s;
1179
1180 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001181 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1182 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001183 */
1184 sc->first_set_call = true;
1185}
1186
Matt Wagantall8e726c72011-08-06 00:49:28 -07001187static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001188{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001189 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001190 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001191
1192 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1193 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001194}
1195
1196/* Register with bus driver. */
1197static void __init bus_init(void)
1198{
1199 int ret;
1200
1201 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1202 if (!bus_perf_client) {
1203 pr_err("unable to register bus client\n");
1204 BUG();
1205 }
1206
1207 ret = msm_bus_scale_client_update_request(bus_perf_client,
1208 (ARRAY_SIZE(bw_level_tbl)-1));
1209 if (ret)
1210 pr_err("initial bandwidth request failed (%d)\n", ret);
1211}
1212
1213#ifdef CONFIG_CPU_FREQ_MSM
1214static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1215
1216static void __init cpufreq_table_init(void)
1217{
1218 int cpu;
1219
1220 for_each_possible_cpu(cpu) {
1221 int i, freq_cnt = 0;
1222 /* Construct the freq_table tables from acpu_freq_tbl. */
1223 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1224 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1225 if (acpu_freq_tbl[i].use_for_scaling) {
1226 freq_table[cpu][freq_cnt].index = freq_cnt;
1227 freq_table[cpu][freq_cnt].frequency
1228 = acpu_freq_tbl[i].speed.khz;
1229 freq_cnt++;
1230 }
1231 }
1232 /* freq_table not big enough to store all usable freqs. */
1233 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1234
1235 freq_table[cpu][freq_cnt].index = freq_cnt;
1236 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1237
1238 pr_info("CPU%d: %d scaling frequencies supported.\n",
1239 cpu, freq_cnt);
1240
1241 /* Register table with CPUFreq. */
1242 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1243 }
1244}
1245#else
1246static void __init cpufreq_table_init(void) {}
1247#endif
1248
1249#define HOT_UNPLUG_KHZ STBY_KHZ
1250static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1251 unsigned long action, void *hcpu)
1252{
1253 static int prev_khz[NR_CPUS];
1254 static int prev_pri_src[NR_CPUS];
1255 static int prev_sec_src[NR_CPUS];
1256 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001257
1258 switch (action) {
1259 case CPU_DYING:
1260 case CPU_DYING_FROZEN:
1261 /*
Matt Wagantall27663842011-08-25 15:11:48 -07001262 * On Krait v1, the primary and secondary muxes must be set
1263 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001264 */
Matt Wagantall27663842011-08-25 15:11:48 -07001265 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001266 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1267 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1268 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1269 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1270 }
1271 break;
1272 case CPU_DEAD:
1273 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001274 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001275 /* Fall through. */
1276 case CPU_UP_CANCELED:
1277 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001278 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001279 break;
1280 case CPU_UP_PREPARE:
1281 case CPU_UP_PREPARE_FROZEN:
1282 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001283 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001284 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001285 break;
1286 case CPU_STARTING:
1287 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001288 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001289 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1290 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1291 }
1292 break;
1293 default:
1294 break;
1295 }
1296
1297 return NOTIFY_OK;
1298}
1299
1300static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1301 .notifier_call = acpuclock_cpu_callback,
1302};
1303
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001304static struct acpu_level * __init select_freq_plan(void)
1305{
1306 struct acpu_level *l, *max_acpu_level = NULL;
1307
1308 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001309 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001310 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001311 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001312
1313 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1314 pvs = (pte_efuse >> 10) & 0x7;
1315 if (pvs == 0x7)
1316 pvs = (pte_efuse >> 13) & 0x7;
1317
1318 switch (pvs) {
1319 case 0x0:
1320 case 0x7:
1321 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001322 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1323 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001324 break;
1325 case 0x1:
1326 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001327 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
1328 v2 = acpu_freq_tbl_8960_kraitv2_nom_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001329 break;
1330 case 0x3:
1331 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001332 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
1333 v2 = acpu_freq_tbl_8960_kraitv2_nom_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001334 break;
1335 default:
1336 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001337 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1338 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001339 break;
1340 }
1341
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001342 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001343 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001344 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001345 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1346 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1347 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001348 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001349 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1350 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1351 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001352 } else if (cpu_is_apq8064()) {
1353 scalable = scalable_8064;
1354 acpu_freq_tbl = acpu_freq_tbl_8064;
1355 l2_freq_tbl = l2_freq_tbl_8064;
1356 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001357 } else if (cpu_is_msm8627()) {
1358 scalable = scalable_8627;
1359 acpu_freq_tbl = acpu_freq_tbl_8627;
1360 l2_freq_tbl = l2_freq_tbl_8627;
1361 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001362 } else if (cpu_is_msm8930()) {
1363 scalable = scalable_8930;
1364 acpu_freq_tbl = acpu_freq_tbl_8930;
1365 l2_freq_tbl = l2_freq_tbl_8930;
1366 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001367 } else {
1368 BUG();
1369 }
1370
1371 /* Find the max supported scaling frequency. */
1372 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1373 if (l->use_for_scaling)
1374 max_acpu_level = l;
1375 BUG_ON(!max_acpu_level);
1376 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1377
1378 return max_acpu_level;
1379}
1380
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001381static struct acpuclk_data acpuclk_8960_data = {
1382 .set_rate = acpuclk_8960_set_rate,
1383 .get_rate = acpuclk_8960_get_rate,
1384 .power_collapse_khz = STBY_KHZ,
1385 .wait_for_irq_khz = STBY_KHZ,
1386};
1387
Matt Wagantallec57f062011-08-16 23:54:46 -07001388static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001389{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001390 struct acpu_level *max_acpu_level = select_freq_plan();
1391 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1392 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001393
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001394 regulator_init();
1395 bus_init();
1396 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001397
1398 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001399 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001400
1401 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001402}
Matt Wagantallec57f062011-08-16 23:54:46 -07001403
1404struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1405 .init = acpuclk_8960_init,
1406};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001407
1408struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1409 .init = acpuclk_8960_init,
1410};