blob: ed37230081e8225fe3e3df0ad5028036375c95c4 [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>
35
36#include "acpuclock.h"
37
38/*
39 * Source IDs.
40 * These must be negative to not overlap with the source IDs
41 * used by the 8x60 local clock driver.
42 */
43#define PLL_8 0
44#define HFPLL -1
45#define QSB -2
46
47/* Mux source selects. */
48#define PRI_SRC_SEL_SEC_SRC 0
49#define PRI_SRC_SEL_HFPLL 1
50#define PRI_SRC_SEL_HFPLL_DIV2 2
51#define SEC_SRC_SEL_QSB 0
52
53/* HFPLL registers offsets. */
54#define HFPLL_MODE 0x00
55#define HFPLL_CONFIG_CTL 0x04
56#define HFPLL_L_VAL 0x08
57#define HFPLL_M_VAL 0x0C
58#define HFPLL_N_VAL 0x10
59#define HFPLL_DROOP_CTL 0x14
60
61/* CP15 L2 indirect addresses. */
62#define L2CPMR_IADDR 0x500
63#define L2CPUCPMR_IADDR 0x501
64
65#define STBY_KHZ 1
66
67#define HFPLL_NOMINAL_VDD 1050000
68#define HFPLL_LOW_VDD 1050000
69#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
70
71#define SECCLKAGD BIT(4)
72
73enum scalables {
74 CPU0 = 0,
75 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070076 CPU2,
77 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078 L2,
79 NUM_SCALABLES
80};
81
82enum vregs {
83 VREG_CORE,
84 VREG_MEM,
85 VREG_DIG,
86 NUM_VREG
87};
88
89struct vreg {
90 const char name[15];
91 const unsigned int max_vdd;
92 const int rpm_vreg_voter;
93 const int rpm_vreg_id;
94 struct regulator *reg;
95 unsigned int cur_vdd;
96};
97
98struct core_speed {
99 unsigned int khz;
100 int src;
101 unsigned int pri_src_sel;
102 unsigned int sec_src_sel;
103 unsigned int pll_l_val;
104};
105
106struct l2_level {
107 struct core_speed speed;
108 unsigned int vdd_dig;
109 unsigned int vdd_mem;
110 unsigned int bw_level;
111};
112
113struct acpu_level {
114 unsigned int use_for_scaling;
115 struct core_speed speed;
116 struct l2_level *l2_level;
117 unsigned int vdd_core;
118};
119
120struct scalable {
121 void * __iomem const hfpll_base;
122 void * __iomem const aux_clk_sel;
123 const uint32_t l2cpmr_iaddr;
124 struct core_speed *current_speed;
125 struct l2_level *l2_vote;
126 struct vreg vreg[NUM_VREG];
127 bool first_set_call;
128};
129
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700130static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131 [CPU0] = {
132 .hfpll_base = MSM_HFPLL_BASE + 0x200,
133 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
134 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
135 .vreg[VREG_CORE] = { "krait0", 1150000 },
136 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
137 RPM_VREG_VOTER1,
138 RPM_VREG_ID_PM8921_L24 },
139 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
140 RPM_VREG_VOTER1,
141 RPM_VREG_ID_PM8921_S3 },
142 },
143 [CPU1] = {
144 .hfpll_base = MSM_HFPLL_BASE + 0x300,
145 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
146 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
147 .vreg[VREG_CORE] = { "krait1", 1150000 },
148 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
149 RPM_VREG_VOTER2,
150 RPM_VREG_ID_PM8921_L24 },
151 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
152 RPM_VREG_VOTER2,
153 RPM_VREG_ID_PM8921_S3 },
154 },
155 [L2] = {
156 .hfpll_base = MSM_HFPLL_BASE + 0x400,
157 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
158 .l2cpmr_iaddr = L2CPMR_IADDR,
159 },
160};
161
Stephen Boyd7ad84752011-08-05 14:04:28 -0700162static DEFINE_MUTEX(driver_lock);
163static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700165static struct scalable scalable_8064[] = {
166 [CPU0] = {
167 .hfpll_base = MSM_HFPLL_BASE + 0x200,
168 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
169 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
170 .vreg[VREG_CORE] = { "krait0", 1150000 },
171 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
172 RPM_VREG_VOTER1,
173 RPM_VREG_ID_PM8921_L24 },
174 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
175 RPM_VREG_VOTER1,
176 RPM_VREG_ID_PM8921_S3 },
177 },
178 [CPU1] = {
179 .hfpll_base = MSM_HFPLL_BASE + 0x240,
180 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
181 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
182 .vreg[VREG_CORE] = { "krait1", 1150000 },
183 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
184 RPM_VREG_VOTER2,
185 RPM_VREG_ID_PM8921_L24 },
186 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
187 RPM_VREG_VOTER2,
188 RPM_VREG_ID_PM8921_S3 },
189 },
190 [CPU2] = {
191 .hfpll_base = MSM_HFPLL_BASE + 0x280,
192 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
193 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
194 .vreg[VREG_CORE] = { "krait2", 1150000 },
195 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
196 RPM_VREG_VOTER4,
197 RPM_VREG_ID_PM8921_L24 },
198 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
199 RPM_VREG_VOTER4,
200 RPM_VREG_ID_PM8921_S3 },
201 },
202 [CPU3] = {
203 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
204 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
205 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
206 .vreg[VREG_CORE] = { "krait3", 1150000 },
207 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
208 RPM_VREG_VOTER5,
209 RPM_VREG_ID_PM8921_L24 },
210 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
211 RPM_VREG_VOTER5,
212 RPM_VREG_ID_PM8921_S3 },
213 },
214 [L2] = {
215 .hfpll_base = MSM_HFPLL_BASE + 0x300,
216 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
217 .l2cpmr_iaddr = L2CPMR_IADDR,
218 },
219};
220
221static struct scalable *scalable;
222static struct l2_level *l2_freq_tbl;
223static struct acpu_level *acpu_freq_tbl;
224static int l2_freq_tbl_size;
225static int cpu_boot_idx;
226static int l2_boot_idx;
227
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700228/* Instantaneous bandwidth requests in MB/s. */
229#define BW_MBPS(_bw) \
230 { \
231 .vectors = (struct msm_bus_vectors[]){ \
232 {\
233 .src = MSM_BUS_MASTER_AMPSS_M0, \
234 .dst = MSM_BUS_SLAVE_EBI_CH0, \
235 .ib = (_bw) * 1000000UL, \
236 .ab = (_bw) * 100000UL, \
237 }, \
238 { \
239 .src = MSM_BUS_MASTER_AMPSS_M1, \
240 .dst = MSM_BUS_SLAVE_EBI_CH0, \
241 .ib = (_bw) * 1000000UL, \
242 .ab = (_bw) * 100000UL, \
243 }, \
244 }, \
245 .num_paths = 2, \
246 }
247static struct msm_bus_paths bw_level_tbl[] = {
248 [0] = BW_MBPS(616), /* At least 77 MHz on bus. */
249 [1] = BW_MBPS(1024), /* At least 128 MHz on bus. */
250 [2] = BW_MBPS(1536), /* At least 192 MHz on bus. */
251 [3] = BW_MBPS(2048), /* At least 256 MHz on bus. */
252 [4] = BW_MBPS(3080), /* At least 385 MHz on bus. */
253 [5] = BW_MBPS(3968), /* At least 496 MHz on bus. */
254};
255
256static struct msm_bus_scale_pdata bus_client_pdata = {
257 .usecase = bw_level_tbl,
258 .num_usecases = ARRAY_SIZE(bw_level_tbl),
259 .active_only = 1,
260 .name = "acpuclock",
261};
262
263static uint32_t bus_perf_client;
264
265/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700266#define L2(x) (&l2_freq_tbl_8960[(x)])
267static struct l2_level l2_freq_tbl_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700268 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700269 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
271 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
272 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
273 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
274 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
275 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700276 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700277 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
278 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
279 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
280 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700281 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700282 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
283 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
284 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700285 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 5 },
286 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 5 },
287 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 5 },
288 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 5 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700289 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
290 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
291 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
292 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
293 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
294};
295
296/* TODO: Update core voltages when data is available. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700297static struct acpu_level acpu_freq_tbl_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
299 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700300 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 1050000 },
301 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 1050000 },
302 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 1050000 },
303 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1050000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700304 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700305 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1050000 },
306 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(13), 1150000 },
307 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(13), 1150000 },
308 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(13), 1150000 },
309 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(13), 1150000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700310 { 0, { 0 } }
311};
312
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700313/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
314#undef L2
315#define L2(x) (&l2_freq_tbl_8064[(x)])
316static struct l2_level l2_freq_tbl_8064[] = {
317 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
318 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
319 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
320 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
321 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
322 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
323 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
324 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
325 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
326 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
327 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
328 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
329 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
330 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
331 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
332 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
333 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
334 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
335 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
336 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
337 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
338 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
339 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
340 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
341 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
342 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
343};
344
345/* TODO: Update core voltages when data is available. */
346static struct acpu_level acpu_freq_tbl_8064[] = {
347 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
348 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
349 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
350 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
351 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
352 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
353 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
354 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
355 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
356 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
357 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
358 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
359 { 0, { 0 } }
360};
361
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700362static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700363{
364 return scalable[cpu].current_speed->khz;
365}
366
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700367/* Read an 'indirectly' addressed L2 CP15 register. */
368static uint32_t readl_cp15_l2ind(uint32_t addr)
369{
370 uint32_t regval;
371
372 /*
373 * TODO: CP15 registers are not emulated on RUMI3.
374 * Remove this check if/when they are.
375 */
376 if (machine_is_msm8960_rumi3())
377 return 0;
378
379 asm volatile ("mcr p15, 3, %[l2cpsler], c15, c0, 6\n\t"
380 "mrc p15, 3, %[l2cpdr], c15, c0, 7\n\t"
381 : [l2cpdr]"=r" (regval)
382 : [l2cpsler]"r" (addr)
383 : "cc"
384 );
385 return regval;
386}
387
388/* Write an 'indirectly' addressed L2 CP15 register. */
389static void writel_cp15_l2ind(uint32_t regval, uint32_t addr)
390{
391 /*
392 * TODO: CP15 registers are not emulated on RUMI3.
393 * Remove this check if/when they are.
394 */
395 if (machine_is_msm8960_rumi3())
396 return;
397
398 mb();
399 asm volatile ("mcr p15, 3, %[l2cpsler], c15, c0, 6\n\t"
400 "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t"
401 :
402 : [l2cpsler]"r" (addr), [l2cpdr]"r" (regval)
403 : "cc"
404 );
405 isb();
406}
407
408/* Get the selected source on primary MUX. */
409static int get_pri_clk_src(struct scalable *sc)
410{
411 uint32_t regval;
412
413 regval = readl_cp15_l2ind(sc->l2cpmr_iaddr);
414 return regval & 0x3;
415}
416
417/* Set the selected source on primary MUX. */
418static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
419{
420 uint32_t regval;
421
422 regval = readl_cp15_l2ind(sc->l2cpmr_iaddr);
423 regval &= ~0x3;
424 regval |= (pri_src_sel & 0x3);
425 writel_cp15_l2ind(regval, sc->l2cpmr_iaddr);
426 /* Wait for switch to complete. */
427 mb();
428 udelay(1);
429}
430
431/* Get the selected source on secondary MUX. */
432static int get_sec_clk_src(struct scalable *sc)
433{
434 uint32_t regval;
435
436 regval = readl_cp15_l2ind(sc->l2cpmr_iaddr);
437 return (regval >> 2) & 0x3;
438}
439
440/* Set the selected source on secondary MUX. */
441static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
442{
443 uint32_t regval;
444
445 /* Disable secondary source clock gating during switch. */
446 regval = readl_cp15_l2ind(sc->l2cpmr_iaddr);
447 regval |= SECCLKAGD;
448 writel_cp15_l2ind(regval, sc->l2cpmr_iaddr);
449
450 /* Program the MUX. */
451 regval &= ~(0x3 << 2);
452 regval |= ((sec_src_sel & 0x3) << 2);
453 writel_cp15_l2ind(regval, sc->l2cpmr_iaddr);
454
455 /* Wait for switch to complete. */
456 mb();
457 udelay(1);
458
459 /* Re-enable secondary source clock gating. */
460 regval &= ~SECCLKAGD;
461 writel_cp15_l2ind(regval, sc->l2cpmr_iaddr);
462}
463
464/* Enable an already-configured HFPLL. */
465static void hfpll_enable(struct scalable *sc)
466{
467 /* Disable PLL bypass mode. */
468 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
469
470 /*
471 * H/W requires a 5us delay between disabling the bypass and
472 * de-asserting the reset. Delay 10us just to be safe.
473 */
474 mb();
475 udelay(10);
476
477 /* De-assert active-low PLL reset. */
478 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
479
480 /* Wait for PLL to lock. */
481 mb();
482 udelay(60);
483
484 /* Enable PLL output. */
485 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
486}
487
488/* Disable a HFPLL for power-savings or while its being reprogrammed. */
489static void hfpll_disable(struct scalable *sc)
490{
491 /*
492 * Disable the PLL output, disable test mode, enable
493 * the bypass mode, and assert the reset.
494 */
495 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
496}
497
498/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
499static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
500{
501 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
502}
503
504/* Return the L2 speed that should be applied. */
505static struct l2_level *compute_l2_level(struct scalable *sc,
506 struct l2_level *vote_l)
507{
508 struct l2_level *new_l;
509 int cpu;
510
511 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700512 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700513
514 /* Find max L2 speed vote. */
515 sc->l2_vote = vote_l;
516 new_l = l2_freq_tbl;
517 for_each_present_cpu(cpu)
518 new_l = max(new_l, scalable[cpu].l2_vote);
519
520 return new_l;
521}
522
523/* Update the bus bandwidth request. */
524static void set_bus_bw(unsigned int bw)
525{
526 int ret;
527
528 /* Bounds check. */
529 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
530 pr_err("invalid bandwidth request (%d)\n", bw);
531 return;
532 }
533
534 /* Update bandwidth if request has changed. This may sleep. */
535 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
536 if (ret)
537 pr_err("bandwidth request failed (%d)\n", ret);
538}
539
540/* Set the CPU or L2 clock speed. */
541static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
542 enum setrate_reason reason)
543{
544 struct core_speed *strt_s = sc->current_speed;
545
546 if (tgt_s == strt_s)
547 return;
548
549 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
550 /* Move CPU to QSB source. */
551 /*
552 * TODO: If using QSB here requires elevating voltages,
553 * consider using PLL8 instead.
554 */
555 set_sec_clk_src(sc, SEC_SRC_SEL_QSB);
556 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
557
558 /* Program CPU HFPLL. */
559 hfpll_disable(sc);
560 hfpll_set_rate(sc, tgt_s);
561 hfpll_enable(sc);
562
563 /* Move CPU to HFPLL source. */
564 set_pri_clk_src(sc, tgt_s->pri_src_sel);
565 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
566 /* TODO: Enable source. */
567 /*
568 * If responding to CPU_DEAD we must be running on another
569 * CPU. Therefore, we can't access the downed CPU's CP15
570 * clock MUX registers from here and can't change clock sources.
571 * Just turn off the PLL- since the CPU is down already, halting
572 * its clock should be safe.
573 */
574 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
575 set_sec_clk_src(sc, tgt_s->sec_src_sel);
576 set_pri_clk_src(sc, tgt_s->pri_src_sel);
577 }
578 hfpll_disable(sc);
579 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
580 hfpll_set_rate(sc, tgt_s);
581 hfpll_enable(sc);
582 /*
583 * If responding to CPU_UP_PREPARE, we can't change CP15
584 * registers for the CPU that's coming up since we're not
585 * running on that CPU. That's okay though, since the MUX
586 * source was not changed on the way down, either.
587 */
588 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
589 set_pri_clk_src(sc, tgt_s->pri_src_sel);
590 /* TODO: Disable source. */
591 } else {
592 /* TODO: Enable source. */
593 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
594 set_sec_clk_src(sc, tgt_s->sec_src_sel);
595 /* TODO: Disable source. */
596 }
597
598 sc->current_speed = tgt_s;
599}
600
601/* Apply any per-cpu voltage increases. */
602static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
603 unsigned int vdd_dig, enum setrate_reason reason)
604{
605 struct scalable *sc = &scalable[cpu];
606 int rc;
607
608 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700609 * Increase vdd_mem active-set before vdd_dig.
610 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700611 */
612 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
613 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
614 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
615 sc->vreg[VREG_MEM].max_vdd, 0);
616 if (rc) {
617 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
618 __func__, cpu, rc);
619 return rc;
620 }
621 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
622 }
623
624 /* Increase vdd_dig active-set vote. */
625 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
626 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
627 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
628 sc->vreg[VREG_DIG].max_vdd, 0);
629 if (rc) {
630 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
631 __func__, cpu, rc);
632 return rc;
633 }
634 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
635 }
636
637 /*
638 * Update per-CPU core voltage. Don't do this for the hotplug path for
639 * which it should already be correct. Attempting to set it is bad
640 * because we don't know what CPU we are running on at this point, but
641 * the CPU regulator API requires we call it from the affected CPU.
642 */
643 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
644 && reason != SETRATE_HOTPLUG) {
645 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
646 sc->vreg[VREG_CORE].max_vdd);
647 if (rc) {
648 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
649 __func__, cpu, rc);
650 return rc;
651 }
652 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
653 }
654
655 return rc;
656}
657
658/* Apply any per-cpu voltage decreases. */
659static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
660 unsigned int vdd_dig, enum setrate_reason reason)
661{
662 struct scalable *sc = &scalable[cpu];
663 int ret;
664
665 /*
666 * Update per-CPU core voltage. This must be called on the CPU
667 * that's being affected. Don't do this in the hotplug remove path,
668 * where the rail is off and we're executing on the other CPU.
669 */
670 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
671 && reason != SETRATE_HOTPLUG) {
672 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
673 sc->vreg[VREG_CORE].max_vdd);
674 if (ret) {
675 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
676 __func__, cpu, ret);
677 return;
678 }
679 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
680 }
681
682 /* Decrease vdd_dig active-set vote. */
683 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
684 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
685 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
686 sc->vreg[VREG_DIG].max_vdd, 0);
687 if (ret) {
688 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
689 __func__, cpu, ret);
690 return;
691 }
692 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
693 }
694
695 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700696 * Decrease vdd_mem active-set after vdd_dig.
697 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698 */
699 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
700 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
701 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
702 sc->vreg[VREG_MEM].max_vdd, 0);
703 if (ret) {
704 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
705 __func__, cpu, ret);
706 return;
707 }
708 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
709 }
710}
711
712static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
713{
Matt Wagantallabd55f02011-09-12 11:45:54 -0700714 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700715}
716
717static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
718{
719 unsigned int pll_vdd_dig;
720
721 if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
722 pll_vdd_dig = HFPLL_NOMINAL_VDD;
723 else
724 pll_vdd_dig = HFPLL_LOW_VDD;
725
726 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
727}
728
729static unsigned int calculate_vdd_core(struct acpu_level *tgt)
730{
731 unsigned int pll_vdd_core;
732
733 if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
734 pll_vdd_core = HFPLL_NOMINAL_VDD;
735 else
736 pll_vdd_core = HFPLL_LOW_VDD;
737
738 return max(tgt->vdd_core, pll_vdd_core);
739}
740
741/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700742static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
743 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744{
745 struct core_speed *strt_acpu_s, *tgt_acpu_s;
746 struct l2_level *tgt_l2_l;
747 struct acpu_level *tgt;
748 unsigned int vdd_mem, vdd_dig, vdd_core;
749 unsigned long flags;
750 int rc = 0;
751
752 if (cpu > num_possible_cpus()) {
753 rc = -EINVAL;
754 goto out;
755 }
756
757 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
758 mutex_lock(&driver_lock);
759
760 strt_acpu_s = scalable[cpu].current_speed;
761
762 /* Return early if rate didn't change. */
763 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
764 goto out;
765
766 /* Find target frequency. */
767 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
768 if (tgt->speed.khz == rate) {
769 tgt_acpu_s = &tgt->speed;
770 break;
771 }
772 }
773 if (tgt->speed.khz == 0) {
774 rc = -EINVAL;
775 goto out;
776 }
777
778 /* Calculate voltage requirements for the current CPU. */
779 vdd_mem = calculate_vdd_mem(tgt);
780 vdd_dig = calculate_vdd_dig(tgt);
781 vdd_core = calculate_vdd_core(tgt);
782
783 /* Increase VDD levels if needed. */
784 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
785 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
786 if (rc)
787 goto out;
788 }
789
790 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
791 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
792
793 /* Set the CPU speed. */
794 set_speed(&scalable[cpu], tgt_acpu_s, reason);
795
796 /*
797 * Update the L2 vote and apply the rate change. A spinlock is
798 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700799 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800 * and the driver_lock mutex is not acquired.
801 */
802 spin_lock_irqsave(&l2_lock, flags);
803 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
804 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
805 spin_unlock_irqrestore(&l2_lock, flags);
806
807 /* Nothing else to do for power collapse or SWFI. */
808 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
809 goto out;
810
811 /* Update bus bandwith request. */
812 set_bus_bw(tgt_l2_l->bw_level);
813
814 /* Drop VDD levels if we can. */
815 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
816
817 scalable[cpu].first_set_call = false;
818 pr_debug("ACPU%d speed change complete\n", cpu);
819
820out:
821 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
822 mutex_unlock(&driver_lock);
823 return rc;
824}
825
826/* Initialize a HFPLL at a given rate and enable it. */
827static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
828{
829 pr_debug("Initializing HFPLL%d\n", sc - scalable);
830
831 /* Disable the PLL for re-programming. */
832 hfpll_disable(sc);
833
834 /* Configure PLL parameters for integer mode. */
835 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
836 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
837 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
838
839 /* Program droop controller. */
840 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
841
842 /* Set an initial rate and enable the PLL. */
843 hfpll_set_rate(sc, tgt_s);
844 hfpll_enable(sc);
845}
846
847/* Voltage regulator initialization. */
848static void __init regulator_init(void)
849{
850 int cpu, ret;
851 struct scalable *sc;
852
853 for_each_possible_cpu(cpu) {
854 sc = &scalable[cpu];
855 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
856 sc->vreg[VREG_CORE].name);
857 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
858 pr_err("regulator_get(%s) failed (%ld)\n",
859 sc->vreg[VREG_CORE].name,
860 PTR_ERR(sc->vreg[VREG_CORE].reg));
861 BUG();
862 }
863
864 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
865 sc->vreg[VREG_CORE].max_vdd,
866 sc->vreg[VREG_CORE].max_vdd);
867 if (ret)
868 pr_err("regulator_set_voltage(%s) failed"
869 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
870
871 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
872 if (ret)
873 pr_err("regulator_enable(%s) failed (%d)\n",
874 sc->vreg[VREG_CORE].name, ret);
875 }
876}
877
878#define INIT_QSB_ID 0
879#define INIT_HFPLL_ID 1
880/* Set initial rate for a given core. */
881static void __init init_clock_sources(struct scalable *sc,
882 struct core_speed *tgt_s)
883{
884 uint32_t pri_src, regval;
885
886 /*
887 * If the HFPLL is in use, program AUX source for QSB, switch to it,
888 * re-initialize the HFPLL, and switch back to the HFPLL. Otherwise,
889 * the HFPLL is not in use, so we can switch directly to it.
890 */
891 pri_src = get_pri_clk_src(scalable);
892 if (pri_src == PRI_SRC_SEL_HFPLL || pri_src == PRI_SRC_SEL_HFPLL_DIV2) {
893 set_sec_clk_src(sc, SEC_SRC_SEL_QSB);
894 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
895 }
896 hfpll_init(sc, tgt_s);
897
898 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
899 regval = readl_cp15_l2ind(sc->l2cpmr_iaddr);
900 regval &= ~(0x3 << 6);
901 writel_cp15_l2ind(regval, sc->l2cpmr_iaddr);
902
903 /* Select PLL8 as AUX source input to the secondary MUX. */
904 writel_relaxed(0x3, sc->aux_clk_sel);
905
906 set_pri_clk_src(sc, tgt_s->pri_src_sel);
907 sc->current_speed = tgt_s;
908
909 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700910 * Set this flag so that the first call to acpuclk_8960_set_rate() can
911 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912 */
913 sc->first_set_call = true;
914}
915
Matt Wagantall8e726c72011-08-06 00:49:28 -0700916static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700917{
Matt Wagantall8e726c72011-08-06 00:49:28 -0700918 int cpu = smp_processor_id();
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700919 init_clock_sources(&scalable[cpu], &acpu_freq_tbl[cpu_boot_idx].speed);
920 scalable[cpu].l2_vote = &l2_freq_tbl[l2_boot_idx];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700921}
922
923/* Register with bus driver. */
924static void __init bus_init(void)
925{
926 int ret;
927
928 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
929 if (!bus_perf_client) {
930 pr_err("unable to register bus client\n");
931 BUG();
932 }
933
934 ret = msm_bus_scale_client_update_request(bus_perf_client,
935 (ARRAY_SIZE(bw_level_tbl)-1));
936 if (ret)
937 pr_err("initial bandwidth request failed (%d)\n", ret);
938}
939
940#ifdef CONFIG_CPU_FREQ_MSM
941static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
942
943static void __init cpufreq_table_init(void)
944{
945 int cpu;
946
947 for_each_possible_cpu(cpu) {
948 int i, freq_cnt = 0;
949 /* Construct the freq_table tables from acpu_freq_tbl. */
950 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
951 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
952 if (acpu_freq_tbl[i].use_for_scaling) {
953 freq_table[cpu][freq_cnt].index = freq_cnt;
954 freq_table[cpu][freq_cnt].frequency
955 = acpu_freq_tbl[i].speed.khz;
956 freq_cnt++;
957 }
958 }
959 /* freq_table not big enough to store all usable freqs. */
960 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
961
962 freq_table[cpu][freq_cnt].index = freq_cnt;
963 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
964
965 pr_info("CPU%d: %d scaling frequencies supported.\n",
966 cpu, freq_cnt);
967
968 /* Register table with CPUFreq. */
969 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
970 }
971}
972#else
973static void __init cpufreq_table_init(void) {}
974#endif
975
976#define HOT_UNPLUG_KHZ STBY_KHZ
977static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
978 unsigned long action, void *hcpu)
979{
980 static int prev_khz[NR_CPUS];
981 static int prev_pri_src[NR_CPUS];
982 static int prev_sec_src[NR_CPUS];
983 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700984
985 switch (action) {
986 case CPU_DYING:
987 case CPU_DYING_FROZEN:
988 /*
Matt Wagantall27663842011-08-25 15:11:48 -0700989 * On Krait v1, the primary and secondary muxes must be set
990 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700991 */
Matt Wagantall27663842011-08-25 15:11:48 -0700992 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700993 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
994 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
995 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
996 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
997 }
998 break;
999 case CPU_DEAD:
1000 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001001 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001002 /* Fall through. */
1003 case CPU_UP_CANCELED:
1004 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001005 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001006 break;
1007 case CPU_UP_PREPARE:
1008 case CPU_UP_PREPARE_FROZEN:
1009 if (WARN_ON(!prev_khz[cpu]))
1010 prev_khz[cpu] = acpu_freq_tbl->speed.khz;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001011 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001012 break;
1013 case CPU_STARTING:
1014 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001015 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001016 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1017 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1018 }
1019 break;
1020 default:
1021 break;
1022 }
1023
1024 return NOTIFY_OK;
1025}
1026
1027static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1028 .notifier_call = acpuclock_cpu_callback,
1029};
1030
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001031static struct acpuclk_data acpuclk_8960_data = {
1032 .set_rate = acpuclk_8960_set_rate,
1033 .get_rate = acpuclk_8960_get_rate,
1034 .power_collapse_khz = STBY_KHZ,
1035 .wait_for_irq_khz = STBY_KHZ,
1036};
1037
Matt Wagantallec57f062011-08-16 23:54:46 -07001038static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039{
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -07001040 if (cpu_is_msm8960()) {
1041 scalable = scalable_8960;
1042 acpu_freq_tbl = acpu_freq_tbl_8960;
1043 l2_freq_tbl = l2_freq_tbl_8960;
1044 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960);
1045 l2_boot_idx = 11;
1046 cpu_boot_idx = 11;
1047 } else if (cpu_is_apq8064()) {
1048 scalable = scalable_8064;
1049 acpu_freq_tbl = acpu_freq_tbl_8064;
1050 l2_freq_tbl = l2_freq_tbl_8064;
1051 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
1052 l2_boot_idx = 11;
1053 cpu_boot_idx = 11;
1054 }
1055
1056 init_clock_sources(&scalable[L2], &l2_freq_tbl[l2_boot_idx].speed);
Rohit Vaswanice74ba32011-08-15 15:28:36 -07001057 on_each_cpu(per_cpu_init, NULL, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001059 regulator_init();
1060 bus_init();
1061 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001062
1063 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001064 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001065
1066 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001067}
Matt Wagantallec57f062011-08-16 23:54:46 -07001068
1069struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1070 .init = acpuclk_8960_init,
1071};