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