blob: 2792e2a03648687c6b13ffc3a94c98cbb6f60533 [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
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700298static struct scalable *scalable;
299static struct l2_level *l2_freq_tbl;
300static struct acpu_level *acpu_freq_tbl;
301static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700302
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700303/* Instantaneous bandwidth requests in MB/s. */
304#define BW_MBPS(_bw) \
305 { \
306 .vectors = (struct msm_bus_vectors[]){ \
307 {\
308 .src = MSM_BUS_MASTER_AMPSS_M0, \
309 .dst = MSM_BUS_SLAVE_EBI_CH0, \
310 .ib = (_bw) * 1000000UL, \
311 .ab = (_bw) * 100000UL, \
312 }, \
313 { \
314 .src = MSM_BUS_MASTER_AMPSS_M1, \
315 .dst = MSM_BUS_SLAVE_EBI_CH0, \
316 .ib = (_bw) * 1000000UL, \
317 .ab = (_bw) * 100000UL, \
318 }, \
319 }, \
320 .num_paths = 2, \
321 }
322static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800323 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
324 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
325 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
326 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
327 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
328 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
329 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700330};
331
332static struct msm_bus_scale_pdata bus_client_pdata = {
333 .usecase = bw_level_tbl,
334 .num_usecases = ARRAY_SIZE(bw_level_tbl),
335 .active_only = 1,
336 .name = "acpuclock",
337};
338
339static uint32_t bus_perf_client;
340
341/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800342#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
343static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700344 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700345 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700346 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
347 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
348 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
349 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
350 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
351 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700352 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700353 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
354 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
355 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700356};
357
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800358static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
359 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
360 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
361 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
362 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
363 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
364 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
365 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
366 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
367 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
368 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
369 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
370 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
371 { 0, { 0 } }
372};
373
374static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
375 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
376 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
377 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
378 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
379 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
380 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
381 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
382 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
383 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
384 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
385 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
386 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700387 { 0, { 0 } }
388};
389
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800390#undef L2
391#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
392static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
393 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
394 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800395 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
396 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
397 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800398 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800399 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
400 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
401 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
402 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
403 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
404 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
405 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
406 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
407 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
408 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
409 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800410};
411
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800412static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
413 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
414 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
415 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
416 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
417 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
418 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
419 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
420 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
421 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
422 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
423 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
424 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
Stephen Boyd2869cfb2011-12-14 09:17:23 -0800425 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
426 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
427 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
428 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
429 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
430 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1137500 },
431 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1150000 },
432 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
433 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
434 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1225000 },
435 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800436 { 0, { 0 } }
437};
438
439static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom_fast[] = {
440 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
441 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
442 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
443 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
444 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
445 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
446 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
447 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
448 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
449 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
450 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
451 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Stephen Boyd2869cfb2011-12-14 09:17:23 -0800452 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
453 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
454 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
455 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
456 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
457 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1137500 },
458 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1150000 },
459 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
460 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
461 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1225000 },
462 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800463 { 0, { 0 } }
464};
465
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700466/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
467#undef L2
468#define L2(x) (&l2_freq_tbl_8064[(x)])
469static struct l2_level l2_freq_tbl_8064[] = {
470 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
471 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
472 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
473 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
474 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
475 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
476 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
477 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
478 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
479 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
480 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
481 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
482 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
483 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
484 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
485 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
486 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
487 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
488 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
489 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
490 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
491 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
492 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
493 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
494 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
495 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
496};
497
498/* TODO: Update core voltages when data is available. */
499static struct acpu_level acpu_freq_tbl_8064[] = {
500 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
501 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
502 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
503 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
504 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
505 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
506 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
507 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
508 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
509 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
510 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
511 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
512 { 0, { 0 } }
513};
514
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800515/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
516#undef L2
517#define L2(x) (&l2_freq_tbl_8930[(x)])
518static struct l2_level l2_freq_tbl_8930[] = {
519 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
520 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
521 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
522 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
523 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
524 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
525 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
526 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
527 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
528 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
529 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
530 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
531 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
532 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
533 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
534 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
535 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
536};
537
538/* TODO: Update core voltages when data is available. */
539static struct acpu_level acpu_freq_tbl_8930[] = {
540 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
541 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
542 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
543 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
544 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
545 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
546 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
547 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
548 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
549 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
550 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
551 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
552 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
553 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
554 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
555 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
556 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
557 { 0, { 0 } }
558};
559
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700560static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700561{
562 return scalable[cpu].current_speed->khz;
563}
564
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565/* Get the selected source on primary MUX. */
566static int get_pri_clk_src(struct scalable *sc)
567{
568 uint32_t regval;
569
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700570 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700571 return regval & 0x3;
572}
573
574/* Set the selected source on primary MUX. */
575static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
576{
577 uint32_t regval;
578
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700579 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700580 regval &= ~0x3;
581 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700582 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583 /* Wait for switch to complete. */
584 mb();
585 udelay(1);
586}
587
588/* Get the selected source on secondary MUX. */
589static int get_sec_clk_src(struct scalable *sc)
590{
591 uint32_t regval;
592
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700593 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594 return (regval >> 2) & 0x3;
595}
596
597/* Set the selected source on secondary MUX. */
598static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
599{
600 uint32_t regval;
601
602 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700603 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700604 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700605 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700606
607 /* Program the MUX. */
608 regval &= ~(0x3 << 2);
609 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700610 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700611
612 /* Wait for switch to complete. */
613 mb();
614 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700615
616 /* Re-enable secondary source clock gating. */
617 regval &= ~SECCLKAGD;
618 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700619}
620
621/* Enable an already-configured HFPLL. */
622static void hfpll_enable(struct scalable *sc)
623{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700624 int rc;
625
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800626 if (cpu_is_msm8960() || cpu_is_msm8930()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700627 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
Matt Wagantall627f4312011-12-13 13:33:47 -0800628 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 2100000,
629 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700630 if (rc)
631 pr_err("%s regulator enable failed (%d)\n",
632 sc->vreg[VREG_HFPLL_A].name, rc);
633 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
634 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
Matt Wagantall627f4312011-12-13 13:33:47 -0800635 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700636 if (rc)
637 pr_err("%s regulator enable failed (%d)\n",
638 sc->vreg[VREG_HFPLL_B].name, rc);
639 }
640
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700641 /* Disable PLL bypass mode. */
642 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
643
644 /*
645 * H/W requires a 5us delay between disabling the bypass and
646 * de-asserting the reset. Delay 10us just to be safe.
647 */
648 mb();
649 udelay(10);
650
651 /* De-assert active-low PLL reset. */
652 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
653
654 /* Wait for PLL to lock. */
655 mb();
656 udelay(60);
657
658 /* Enable PLL output. */
659 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
660}
661
662/* Disable a HFPLL for power-savings or while its being reprogrammed. */
663static void hfpll_disable(struct scalable *sc)
664{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700665 int rc;
666
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700667 /*
668 * Disable the PLL output, disable test mode, enable
669 * the bypass mode, and assert the reset.
670 */
671 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700672
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800673 if (cpu_is_msm8960() || cpu_is_msm8930()) {
Matt Wagantallcb12c392011-10-19 10:32:07 -0700674 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
675 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
676 0, 0);
677 if (rc)
678 pr_err("%s regulator enable failed (%d)\n",
679 sc->vreg[VREG_HFPLL_B].name, rc);
680 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
681 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 0,
682 0, 0);
683 if (rc)
684 pr_err("%s regulator enable failed (%d)\n",
685 sc->vreg[VREG_HFPLL_A].name, rc);
686 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700687}
688
689/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
690static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
691{
692 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
693}
694
695/* Return the L2 speed that should be applied. */
696static struct l2_level *compute_l2_level(struct scalable *sc,
697 struct l2_level *vote_l)
698{
699 struct l2_level *new_l;
700 int cpu;
701
702 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700703 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700704
705 /* Find max L2 speed vote. */
706 sc->l2_vote = vote_l;
707 new_l = l2_freq_tbl;
708 for_each_present_cpu(cpu)
709 new_l = max(new_l, scalable[cpu].l2_vote);
710
711 return new_l;
712}
713
714/* Update the bus bandwidth request. */
715static void set_bus_bw(unsigned int bw)
716{
717 int ret;
718
719 /* Bounds check. */
720 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
721 pr_err("invalid bandwidth request (%d)\n", bw);
722 return;
723 }
724
725 /* Update bandwidth if request has changed. This may sleep. */
726 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
727 if (ret)
728 pr_err("bandwidth request failed (%d)\n", ret);
729}
730
731/* Set the CPU or L2 clock speed. */
732static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
733 enum setrate_reason reason)
734{
735 struct core_speed *strt_s = sc->current_speed;
736
737 if (tgt_s == strt_s)
738 return;
739
740 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700741 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700742 * Move to an always-on source running at a frequency that does
743 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700745 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
747
748 /* Program CPU HFPLL. */
749 hfpll_disable(sc);
750 hfpll_set_rate(sc, tgt_s);
751 hfpll_enable(sc);
752
753 /* Move CPU to HFPLL source. */
754 set_pri_clk_src(sc, tgt_s->pri_src_sel);
755 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 /*
757 * If responding to CPU_DEAD we must be running on another
758 * CPU. Therefore, we can't access the downed CPU's CP15
759 * clock MUX registers from here and can't change clock sources.
760 * Just turn off the PLL- since the CPU is down already, halting
761 * its clock should be safe.
762 */
763 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
764 set_sec_clk_src(sc, tgt_s->sec_src_sel);
765 set_pri_clk_src(sc, tgt_s->pri_src_sel);
766 }
767 hfpll_disable(sc);
768 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
769 hfpll_set_rate(sc, tgt_s);
770 hfpll_enable(sc);
771 /*
772 * If responding to CPU_UP_PREPARE, we can't change CP15
773 * registers for the CPU that's coming up since we're not
774 * running on that CPU. That's okay though, since the MUX
775 * source was not changed on the way down, either.
776 */
777 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
778 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700780 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
781 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782 }
783
784 sc->current_speed = tgt_s;
785}
786
787/* Apply any per-cpu voltage increases. */
788static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
789 unsigned int vdd_dig, enum setrate_reason reason)
790{
791 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700792 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700793
794 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700795 * Increase vdd_mem active-set before vdd_dig.
796 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700797 */
798 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
799 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
800 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
801 sc->vreg[VREG_MEM].max_vdd, 0);
802 if (rc) {
803 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
804 __func__, cpu, rc);
805 return rc;
806 }
807 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
808 }
809
810 /* Increase vdd_dig active-set vote. */
811 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
812 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
813 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
814 sc->vreg[VREG_DIG].max_vdd, 0);
815 if (rc) {
816 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
817 __func__, cpu, rc);
818 return rc;
819 }
820 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
821 }
822
823 /*
824 * Update per-CPU core voltage. Don't do this for the hotplug path for
825 * which it should already be correct. Attempting to set it is bad
826 * because we don't know what CPU we are running on at this point, but
827 * the CPU regulator API requires we call it from the affected CPU.
828 */
829 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
830 && reason != SETRATE_HOTPLUG) {
831 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
832 sc->vreg[VREG_CORE].max_vdd);
833 if (rc) {
834 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
835 __func__, cpu, rc);
836 return rc;
837 }
838 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
839 }
840
841 return rc;
842}
843
844/* Apply any per-cpu voltage decreases. */
845static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
846 unsigned int vdd_dig, enum setrate_reason reason)
847{
848 struct scalable *sc = &scalable[cpu];
849 int ret;
850
851 /*
852 * Update per-CPU core voltage. This must be called on the CPU
853 * that's being affected. Don't do this in the hotplug remove path,
854 * where the rail is off and we're executing on the other CPU.
855 */
856 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
857 && reason != SETRATE_HOTPLUG) {
858 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
859 sc->vreg[VREG_CORE].max_vdd);
860 if (ret) {
861 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
862 __func__, cpu, ret);
863 return;
864 }
865 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
866 }
867
868 /* Decrease vdd_dig active-set vote. */
869 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
870 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
871 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
872 sc->vreg[VREG_DIG].max_vdd, 0);
873 if (ret) {
874 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
875 __func__, cpu, ret);
876 return;
877 }
878 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
879 }
880
881 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700882 * Decrease vdd_mem active-set after vdd_dig.
883 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700884 */
885 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
886 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
887 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
888 sc->vreg[VREG_MEM].max_vdd, 0);
889 if (ret) {
890 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
891 __func__, cpu, ret);
892 return;
893 }
894 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
895 }
896}
897
898static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
899{
Matt Wagantallabd55f02011-09-12 11:45:54 -0700900 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901}
902
903static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
904{
905 unsigned int pll_vdd_dig;
906
Stephen Boydc76158f2011-12-08 12:42:40 -0800907 if (tgt->l2_level->speed.src != HFPLL)
908 pll_vdd_dig = 0;
909 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910 pll_vdd_dig = HFPLL_NOMINAL_VDD;
911 else
912 pll_vdd_dig = HFPLL_LOW_VDD;
913
914 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
915}
916
917static unsigned int calculate_vdd_core(struct acpu_level *tgt)
918{
919 unsigned int pll_vdd_core;
920
Stephen Boydc76158f2011-12-08 12:42:40 -0800921 if (tgt->speed.src != HFPLL)
922 pll_vdd_core = 0;
923 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700924 pll_vdd_core = HFPLL_NOMINAL_VDD;
925 else
926 pll_vdd_core = HFPLL_LOW_VDD;
927
928 return max(tgt->vdd_core, pll_vdd_core);
929}
930
931/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700932static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
933 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700934{
935 struct core_speed *strt_acpu_s, *tgt_acpu_s;
936 struct l2_level *tgt_l2_l;
937 struct acpu_level *tgt;
938 unsigned int vdd_mem, vdd_dig, vdd_core;
939 unsigned long flags;
940 int rc = 0;
941
942 if (cpu > num_possible_cpus()) {
943 rc = -EINVAL;
944 goto out;
945 }
946
947 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
948 mutex_lock(&driver_lock);
949
950 strt_acpu_s = scalable[cpu].current_speed;
951
952 /* Return early if rate didn't change. */
953 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
954 goto out;
955
956 /* Find target frequency. */
957 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
958 if (tgt->speed.khz == rate) {
959 tgt_acpu_s = &tgt->speed;
960 break;
961 }
962 }
963 if (tgt->speed.khz == 0) {
964 rc = -EINVAL;
965 goto out;
966 }
967
968 /* Calculate voltage requirements for the current CPU. */
969 vdd_mem = calculate_vdd_mem(tgt);
970 vdd_dig = calculate_vdd_dig(tgt);
971 vdd_core = calculate_vdd_core(tgt);
972
973 /* Increase VDD levels if needed. */
974 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
975 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
976 if (rc)
977 goto out;
978 }
979
980 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
981 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
982
983 /* Set the CPU speed. */
984 set_speed(&scalable[cpu], tgt_acpu_s, reason);
985
986 /*
987 * Update the L2 vote and apply the rate change. A spinlock is
988 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700989 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700990 * and the driver_lock mutex is not acquired.
991 */
992 spin_lock_irqsave(&l2_lock, flags);
993 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
994 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
995 spin_unlock_irqrestore(&l2_lock, flags);
996
997 /* Nothing else to do for power collapse or SWFI. */
998 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
999 goto out;
1000
1001 /* Update bus bandwith request. */
1002 set_bus_bw(tgt_l2_l->bw_level);
1003
1004 /* Drop VDD levels if we can. */
1005 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1006
1007 scalable[cpu].first_set_call = false;
1008 pr_debug("ACPU%d speed change complete\n", cpu);
1009
1010out:
1011 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1012 mutex_unlock(&driver_lock);
1013 return rc;
1014}
1015
1016/* Initialize a HFPLL at a given rate and enable it. */
1017static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1018{
1019 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1020
1021 /* Disable the PLL for re-programming. */
1022 hfpll_disable(sc);
1023
1024 /* Configure PLL parameters for integer mode. */
1025 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1026 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1027 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1028
1029 /* Program droop controller. */
1030 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1031
1032 /* Set an initial rate and enable the PLL. */
1033 hfpll_set_rate(sc, tgt_s);
1034 hfpll_enable(sc);
1035}
1036
1037/* Voltage regulator initialization. */
1038static void __init regulator_init(void)
1039{
1040 int cpu, ret;
1041 struct scalable *sc;
1042
1043 for_each_possible_cpu(cpu) {
1044 sc = &scalable[cpu];
1045 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1046 sc->vreg[VREG_CORE].name);
1047 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1048 pr_err("regulator_get(%s) failed (%ld)\n",
1049 sc->vreg[VREG_CORE].name,
1050 PTR_ERR(sc->vreg[VREG_CORE].reg));
1051 BUG();
1052 }
1053
1054 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
1055 sc->vreg[VREG_CORE].max_vdd,
1056 sc->vreg[VREG_CORE].max_vdd);
1057 if (ret)
1058 pr_err("regulator_set_voltage(%s) failed"
1059 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1060
1061 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1062 if (ret)
1063 pr_err("regulator_enable(%s) failed (%d)\n",
1064 sc->vreg[VREG_CORE].name, ret);
1065 }
1066}
1067
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001068/* Set initial rate for a given core. */
1069static void __init init_clock_sources(struct scalable *sc,
1070 struct core_speed *tgt_s)
1071{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001072 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001073
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001074 /* Select PLL8 as AUX source input to the secondary MUX. */
1075 writel_relaxed(0x3, sc->aux_clk_sel);
1076
1077 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001078 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001079 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001080 hfpll_init(sc, tgt_s);
1081
1082 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001083 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001084 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001085 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001086
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001087 /* Switch to the target clock source. */
1088 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001089 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1090 sc->current_speed = tgt_s;
1091
1092 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001093 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1094 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001095 */
1096 sc->first_set_call = true;
1097}
1098
Matt Wagantall8e726c72011-08-06 00:49:28 -07001099static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001100{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001101 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001102 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001103
1104 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1105 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001106}
1107
1108/* Register with bus driver. */
1109static void __init bus_init(void)
1110{
1111 int ret;
1112
1113 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1114 if (!bus_perf_client) {
1115 pr_err("unable to register bus client\n");
1116 BUG();
1117 }
1118
1119 ret = msm_bus_scale_client_update_request(bus_perf_client,
1120 (ARRAY_SIZE(bw_level_tbl)-1));
1121 if (ret)
1122 pr_err("initial bandwidth request failed (%d)\n", ret);
1123}
1124
1125#ifdef CONFIG_CPU_FREQ_MSM
1126static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1127
1128static void __init cpufreq_table_init(void)
1129{
1130 int cpu;
1131
1132 for_each_possible_cpu(cpu) {
1133 int i, freq_cnt = 0;
1134 /* Construct the freq_table tables from acpu_freq_tbl. */
1135 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1136 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1137 if (acpu_freq_tbl[i].use_for_scaling) {
1138 freq_table[cpu][freq_cnt].index = freq_cnt;
1139 freq_table[cpu][freq_cnt].frequency
1140 = acpu_freq_tbl[i].speed.khz;
1141 freq_cnt++;
1142 }
1143 }
1144 /* freq_table not big enough to store all usable freqs. */
1145 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1146
1147 freq_table[cpu][freq_cnt].index = freq_cnt;
1148 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1149
1150 pr_info("CPU%d: %d scaling frequencies supported.\n",
1151 cpu, freq_cnt);
1152
1153 /* Register table with CPUFreq. */
1154 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1155 }
1156}
1157#else
1158static void __init cpufreq_table_init(void) {}
1159#endif
1160
1161#define HOT_UNPLUG_KHZ STBY_KHZ
1162static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1163 unsigned long action, void *hcpu)
1164{
1165 static int prev_khz[NR_CPUS];
1166 static int prev_pri_src[NR_CPUS];
1167 static int prev_sec_src[NR_CPUS];
1168 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001169
1170 switch (action) {
1171 case CPU_DYING:
1172 case CPU_DYING_FROZEN:
1173 /*
Matt Wagantall27663842011-08-25 15:11:48 -07001174 * On Krait v1, the primary and secondary muxes must be set
1175 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001176 */
Matt Wagantall27663842011-08-25 15:11:48 -07001177 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001178 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1179 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1180 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1181 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1182 }
1183 break;
1184 case CPU_DEAD:
1185 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001186 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001187 /* Fall through. */
1188 case CPU_UP_CANCELED:
1189 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001190 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001191 break;
1192 case CPU_UP_PREPARE:
1193 case CPU_UP_PREPARE_FROZEN:
1194 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001195 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001196 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001197 break;
1198 case CPU_STARTING:
1199 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001200 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001201 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1202 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1203 }
1204 break;
1205 default:
1206 break;
1207 }
1208
1209 return NOTIFY_OK;
1210}
1211
1212static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1213 .notifier_call = acpuclock_cpu_callback,
1214};
1215
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001216static struct acpu_level * __init select_freq_plan(void)
1217{
1218 struct acpu_level *l, *max_acpu_level = NULL;
1219
1220 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001221 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001222 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001223 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001224
1225 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1226 pvs = (pte_efuse >> 10) & 0x7;
1227 if (pvs == 0x7)
1228 pvs = (pte_efuse >> 13) & 0x7;
1229
1230 switch (pvs) {
1231 case 0x0:
1232 case 0x7:
1233 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001234 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1235 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001236 break;
1237 case 0x1:
1238 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001239 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
1240 v2 = acpu_freq_tbl_8960_kraitv2_nom_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001241 break;
1242 case 0x3:
1243 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001244 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
1245 v2 = acpu_freq_tbl_8960_kraitv2_nom_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001246 break;
1247 default:
1248 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001249 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1250 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001251 break;
1252 }
1253
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001254 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001255 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001256 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001257 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1258 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1259 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001260 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001261 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1262 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1263 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001264 } else if (cpu_is_apq8064()) {
1265 scalable = scalable_8064;
1266 acpu_freq_tbl = acpu_freq_tbl_8064;
1267 l2_freq_tbl = l2_freq_tbl_8064;
1268 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001269 } else if (cpu_is_msm8930()) {
1270 scalable = scalable_8930;
1271 acpu_freq_tbl = acpu_freq_tbl_8930;
1272 l2_freq_tbl = l2_freq_tbl_8930;
1273 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001274 } else {
1275 BUG();
1276 }
1277
1278 /* Find the max supported scaling frequency. */
1279 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1280 if (l->use_for_scaling)
1281 max_acpu_level = l;
1282 BUG_ON(!max_acpu_level);
1283 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1284
1285 return max_acpu_level;
1286}
1287
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001288static struct acpuclk_data acpuclk_8960_data = {
1289 .set_rate = acpuclk_8960_set_rate,
1290 .get_rate = acpuclk_8960_get_rate,
1291 .power_collapse_khz = STBY_KHZ,
1292 .wait_for_irq_khz = STBY_KHZ,
1293};
1294
Matt Wagantallec57f062011-08-16 23:54:46 -07001295static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001296{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001297 struct acpu_level *max_acpu_level = select_freq_plan();
1298 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1299 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001300
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001301 regulator_init();
1302 bus_init();
1303 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001304
1305 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001306 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001307
1308 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001309}
Matt Wagantallec57f062011-08-16 23:54:46 -07001310
1311struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1312 .init = acpuclk_8960_init,
1313};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001314
1315struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1316 .init = acpuclk_8960_init,
1317};