blob: d74db47a341ae925a1461de3d8a3c1a918eb4f75 [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
Matt Wagantallc5236722011-10-14 17:47:06 -070069#define HFPLL_LOW_VDD 945000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
71
72#define SECCLKAGD BIT(4)
73
Matt Wagantalla518f8f2011-10-17 13:24:53 -070074/* PTE EFUSE register. */
75#define QFPROM_PTE_EFUSE_ADDR (MSM_QFPROM_BASE + 0x00C0)
76
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077enum scalables {
78 CPU0 = 0,
79 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070080 CPU2,
81 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082 L2,
83 NUM_SCALABLES
84};
85
86enum vregs {
87 VREG_CORE,
88 VREG_MEM,
89 VREG_DIG,
90 NUM_VREG
91};
92
93struct vreg {
94 const char name[15];
95 const unsigned int max_vdd;
96 const int rpm_vreg_voter;
97 const int rpm_vreg_id;
98 struct regulator *reg;
99 unsigned int cur_vdd;
100};
101
102struct core_speed {
103 unsigned int khz;
104 int src;
105 unsigned int pri_src_sel;
106 unsigned int sec_src_sel;
107 unsigned int pll_l_val;
108};
109
110struct l2_level {
111 struct core_speed speed;
112 unsigned int vdd_dig;
113 unsigned int vdd_mem;
114 unsigned int bw_level;
115};
116
117struct acpu_level {
118 unsigned int use_for_scaling;
119 struct core_speed speed;
120 struct l2_level *l2_level;
121 unsigned int vdd_core;
122};
123
124struct scalable {
125 void * __iomem const hfpll_base;
126 void * __iomem const aux_clk_sel;
127 const uint32_t l2cpmr_iaddr;
128 struct core_speed *current_speed;
129 struct l2_level *l2_vote;
130 struct vreg vreg[NUM_VREG];
131 bool first_set_call;
132};
133
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700134static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135 [CPU0] = {
136 .hfpll_base = MSM_HFPLL_BASE + 0x200,
137 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
138 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
139 .vreg[VREG_CORE] = { "krait0", 1150000 },
140 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
141 RPM_VREG_VOTER1,
142 RPM_VREG_ID_PM8921_L24 },
143 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
144 RPM_VREG_VOTER1,
145 RPM_VREG_ID_PM8921_S3 },
146 },
147 [CPU1] = {
148 .hfpll_base = MSM_HFPLL_BASE + 0x300,
149 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
150 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
151 .vreg[VREG_CORE] = { "krait1", 1150000 },
152 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
153 RPM_VREG_VOTER2,
154 RPM_VREG_ID_PM8921_L24 },
155 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
156 RPM_VREG_VOTER2,
157 RPM_VREG_ID_PM8921_S3 },
158 },
159 [L2] = {
160 .hfpll_base = MSM_HFPLL_BASE + 0x400,
161 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
162 .l2cpmr_iaddr = L2CPMR_IADDR,
163 },
164};
165
Stephen Boyd7ad84752011-08-05 14:04:28 -0700166static DEFINE_MUTEX(driver_lock);
167static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700169static struct scalable scalable_8064[] = {
170 [CPU0] = {
171 .hfpll_base = MSM_HFPLL_BASE + 0x200,
172 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
173 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
174 .vreg[VREG_CORE] = { "krait0", 1150000 },
175 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
176 RPM_VREG_VOTER1,
177 RPM_VREG_ID_PM8921_L24 },
178 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
179 RPM_VREG_VOTER1,
180 RPM_VREG_ID_PM8921_S3 },
181 },
182 [CPU1] = {
183 .hfpll_base = MSM_HFPLL_BASE + 0x240,
184 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
185 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
186 .vreg[VREG_CORE] = { "krait1", 1150000 },
187 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
188 RPM_VREG_VOTER2,
189 RPM_VREG_ID_PM8921_L24 },
190 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
191 RPM_VREG_VOTER2,
192 RPM_VREG_ID_PM8921_S3 },
193 },
194 [CPU2] = {
195 .hfpll_base = MSM_HFPLL_BASE + 0x280,
196 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
197 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
198 .vreg[VREG_CORE] = { "krait2", 1150000 },
199 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
200 RPM_VREG_VOTER4,
201 RPM_VREG_ID_PM8921_L24 },
202 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
203 RPM_VREG_VOTER4,
204 RPM_VREG_ID_PM8921_S3 },
205 },
206 [CPU3] = {
207 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
208 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
209 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
210 .vreg[VREG_CORE] = { "krait3", 1150000 },
211 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
212 RPM_VREG_VOTER5,
213 RPM_VREG_ID_PM8921_L24 },
214 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
215 RPM_VREG_VOTER5,
216 RPM_VREG_ID_PM8921_S3 },
217 },
218 [L2] = {
219 .hfpll_base = MSM_HFPLL_BASE + 0x300,
220 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
221 .l2cpmr_iaddr = L2CPMR_IADDR,
222 },
223};
224
225static struct scalable *scalable;
226static struct l2_level *l2_freq_tbl;
227static struct acpu_level *acpu_freq_tbl;
228static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700229
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230/* Instantaneous bandwidth requests in MB/s. */
231#define BW_MBPS(_bw) \
232 { \
233 .vectors = (struct msm_bus_vectors[]){ \
234 {\
235 .src = MSM_BUS_MASTER_AMPSS_M0, \
236 .dst = MSM_BUS_SLAVE_EBI_CH0, \
237 .ib = (_bw) * 1000000UL, \
238 .ab = (_bw) * 100000UL, \
239 }, \
240 { \
241 .src = MSM_BUS_MASTER_AMPSS_M1, \
242 .dst = MSM_BUS_SLAVE_EBI_CH0, \
243 .ib = (_bw) * 1000000UL, \
244 .ab = (_bw) * 100000UL, \
245 }, \
246 }, \
247 .num_paths = 2, \
248 }
249static struct msm_bus_paths bw_level_tbl[] = {
250 [0] = BW_MBPS(616), /* At least 77 MHz on bus. */
251 [1] = BW_MBPS(1024), /* At least 128 MHz on bus. */
252 [2] = BW_MBPS(1536), /* At least 192 MHz on bus. */
253 [3] = BW_MBPS(2048), /* At least 256 MHz on bus. */
254 [4] = BW_MBPS(3080), /* At least 385 MHz on bus. */
255 [5] = BW_MBPS(3968), /* At least 496 MHz on bus. */
256};
257
258static struct msm_bus_scale_pdata bus_client_pdata = {
259 .usecase = bw_level_tbl,
260 .num_usecases = ARRAY_SIZE(bw_level_tbl),
261 .active_only = 1,
262 .name = "acpuclock",
263};
264
265static uint32_t bus_perf_client;
266
267/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700268#define L2(x) (&l2_freq_tbl_8960[(x)])
269static struct l2_level l2_freq_tbl_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700271 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
273 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
274 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
275 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
276 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
277 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700278 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700279 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
280 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
281 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700282};
283
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700284static struct acpu_level acpu_freq_tbl_8960[] = {
Matt Wagantallc5236722011-10-14 17:47:06 -0700285 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
286 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
287 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 950000 },
288 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 962500 },
289 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 962500 },
290 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 987500 },
291 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1000000 },
292 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1025000 },
293 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1050000 },
294 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1087500 },
295 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1125000 },
296 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1137500 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700297 { 0, { 0 } }
298};
299
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700300/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
301#undef L2
302#define L2(x) (&l2_freq_tbl_8064[(x)])
303static struct l2_level l2_freq_tbl_8064[] = {
304 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
305 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
306 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
307 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
308 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
309 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
310 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
311 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
312 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
313 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
314 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
315 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
316 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
317 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
318 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
319 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
320 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
321 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
322 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
323 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
324 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
325 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
326 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
327 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
328 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
329 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
330};
331
332/* TODO: Update core voltages when data is available. */
333static struct acpu_level acpu_freq_tbl_8064[] = {
334 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
335 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
336 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
337 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
338 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
339 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
340 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
341 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
342 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
343 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
344 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
345 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
346 { 0, { 0 } }
347};
348
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700349static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700350{
351 return scalable[cpu].current_speed->khz;
352}
353
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700354/* Get the selected source on primary MUX. */
355static int get_pri_clk_src(struct scalable *sc)
356{
357 uint32_t regval;
358
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700359 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700360 return regval & 0x3;
361}
362
363/* Set the selected source on primary MUX. */
364static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
365{
366 uint32_t regval;
367
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700368 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700369 regval &= ~0x3;
370 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700371 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700372 /* Wait for switch to complete. */
373 mb();
374 udelay(1);
375}
376
377/* Get the selected source on secondary MUX. */
378static int get_sec_clk_src(struct scalable *sc)
379{
380 uint32_t regval;
381
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700382 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700383 return (regval >> 2) & 0x3;
384}
385
386/* Set the selected source on secondary MUX. */
387static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
388{
389 uint32_t regval;
390
391 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700392 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700393 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700394 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700395
396 /* Program the MUX. */
397 regval &= ~(0x3 << 2);
398 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700399 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700400
401 /* Wait for switch to complete. */
402 mb();
403 udelay(1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404}
405
406/* Enable an already-configured HFPLL. */
407static void hfpll_enable(struct scalable *sc)
408{
409 /* Disable PLL bypass mode. */
410 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
411
412 /*
413 * H/W requires a 5us delay between disabling the bypass and
414 * de-asserting the reset. Delay 10us just to be safe.
415 */
416 mb();
417 udelay(10);
418
419 /* De-assert active-low PLL reset. */
420 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
421
422 /* Wait for PLL to lock. */
423 mb();
424 udelay(60);
425
426 /* Enable PLL output. */
427 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
428}
429
430/* Disable a HFPLL for power-savings or while its being reprogrammed. */
431static void hfpll_disable(struct scalable *sc)
432{
433 /*
434 * Disable the PLL output, disable test mode, enable
435 * the bypass mode, and assert the reset.
436 */
437 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
438}
439
440/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
441static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
442{
443 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
444}
445
446/* Return the L2 speed that should be applied. */
447static struct l2_level *compute_l2_level(struct scalable *sc,
448 struct l2_level *vote_l)
449{
450 struct l2_level *new_l;
451 int cpu;
452
453 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700454 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700455
456 /* Find max L2 speed vote. */
457 sc->l2_vote = vote_l;
458 new_l = l2_freq_tbl;
459 for_each_present_cpu(cpu)
460 new_l = max(new_l, scalable[cpu].l2_vote);
461
462 return new_l;
463}
464
465/* Update the bus bandwidth request. */
466static void set_bus_bw(unsigned int bw)
467{
468 int ret;
469
470 /* Bounds check. */
471 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
472 pr_err("invalid bandwidth request (%d)\n", bw);
473 return;
474 }
475
476 /* Update bandwidth if request has changed. This may sleep. */
477 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
478 if (ret)
479 pr_err("bandwidth request failed (%d)\n", ret);
480}
481
482/* Set the CPU or L2 clock speed. */
483static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
484 enum setrate_reason reason)
485{
486 struct core_speed *strt_s = sc->current_speed;
487
488 if (tgt_s == strt_s)
489 return;
490
491 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
492 /* Move CPU to QSB source. */
493 /*
494 * TODO: If using QSB here requires elevating voltages,
495 * consider using PLL8 instead.
496 */
497 set_sec_clk_src(sc, SEC_SRC_SEL_QSB);
498 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
499
500 /* Program CPU HFPLL. */
501 hfpll_disable(sc);
502 hfpll_set_rate(sc, tgt_s);
503 hfpll_enable(sc);
504
505 /* Move CPU to HFPLL source. */
506 set_pri_clk_src(sc, tgt_s->pri_src_sel);
507 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
508 /* TODO: Enable source. */
509 /*
510 * If responding to CPU_DEAD we must be running on another
511 * CPU. Therefore, we can't access the downed CPU's CP15
512 * clock MUX registers from here and can't change clock sources.
513 * Just turn off the PLL- since the CPU is down already, halting
514 * its clock should be safe.
515 */
516 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
517 set_sec_clk_src(sc, tgt_s->sec_src_sel);
518 set_pri_clk_src(sc, tgt_s->pri_src_sel);
519 }
520 hfpll_disable(sc);
521 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
522 hfpll_set_rate(sc, tgt_s);
523 hfpll_enable(sc);
524 /*
525 * If responding to CPU_UP_PREPARE, we can't change CP15
526 * registers for the CPU that's coming up since we're not
527 * running on that CPU. That's okay though, since the MUX
528 * source was not changed on the way down, either.
529 */
530 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
531 set_pri_clk_src(sc, tgt_s->pri_src_sel);
532 /* TODO: Disable source. */
533 } else {
534 /* TODO: Enable source. */
535 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
536 set_sec_clk_src(sc, tgt_s->sec_src_sel);
537 /* TODO: Disable source. */
538 }
539
540 sc->current_speed = tgt_s;
541}
542
543/* Apply any per-cpu voltage increases. */
544static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
545 unsigned int vdd_dig, enum setrate_reason reason)
546{
547 struct scalable *sc = &scalable[cpu];
548 int rc;
549
550 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700551 * Increase vdd_mem active-set before vdd_dig.
552 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700553 */
554 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
555 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
556 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
557 sc->vreg[VREG_MEM].max_vdd, 0);
558 if (rc) {
559 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
560 __func__, cpu, rc);
561 return rc;
562 }
563 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
564 }
565
566 /* Increase vdd_dig active-set vote. */
567 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
568 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
569 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
570 sc->vreg[VREG_DIG].max_vdd, 0);
571 if (rc) {
572 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
573 __func__, cpu, rc);
574 return rc;
575 }
576 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
577 }
578
579 /*
580 * Update per-CPU core voltage. Don't do this for the hotplug path for
581 * which it should already be correct. Attempting to set it is bad
582 * because we don't know what CPU we are running on at this point, but
583 * the CPU regulator API requires we call it from the affected CPU.
584 */
585 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
586 && reason != SETRATE_HOTPLUG) {
587 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
588 sc->vreg[VREG_CORE].max_vdd);
589 if (rc) {
590 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
591 __func__, cpu, rc);
592 return rc;
593 }
594 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
595 }
596
597 return rc;
598}
599
600/* Apply any per-cpu voltage decreases. */
601static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
602 unsigned int vdd_dig, enum setrate_reason reason)
603{
604 struct scalable *sc = &scalable[cpu];
605 int ret;
606
607 /*
608 * Update per-CPU core voltage. This must be called on the CPU
609 * that's being affected. Don't do this in the hotplug remove path,
610 * where the rail is off and we're executing on the other CPU.
611 */
612 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
613 && reason != SETRATE_HOTPLUG) {
614 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
615 sc->vreg[VREG_CORE].max_vdd);
616 if (ret) {
617 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
618 __func__, cpu, ret);
619 return;
620 }
621 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
622 }
623
624 /* Decrease vdd_dig active-set vote. */
625 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
626 ret = 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 (ret) {
630 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
631 __func__, cpu, ret);
632 return;
633 }
634 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
635 }
636
637 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700638 * Decrease vdd_mem active-set after vdd_dig.
639 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700640 */
641 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
642 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
643 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
644 sc->vreg[VREG_MEM].max_vdd, 0);
645 if (ret) {
646 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
647 __func__, cpu, ret);
648 return;
649 }
650 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
651 }
652}
653
654static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
655{
Matt Wagantallabd55f02011-09-12 11:45:54 -0700656 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700657}
658
659static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
660{
661 unsigned int pll_vdd_dig;
662
663 if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
664 pll_vdd_dig = HFPLL_NOMINAL_VDD;
665 else
666 pll_vdd_dig = HFPLL_LOW_VDD;
667
668 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
669}
670
671static unsigned int calculate_vdd_core(struct acpu_level *tgt)
672{
673 unsigned int pll_vdd_core;
674
675 if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
676 pll_vdd_core = HFPLL_NOMINAL_VDD;
677 else
678 pll_vdd_core = HFPLL_LOW_VDD;
679
680 return max(tgt->vdd_core, pll_vdd_core);
681}
682
683/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700684static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
685 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686{
687 struct core_speed *strt_acpu_s, *tgt_acpu_s;
688 struct l2_level *tgt_l2_l;
689 struct acpu_level *tgt;
690 unsigned int vdd_mem, vdd_dig, vdd_core;
691 unsigned long flags;
692 int rc = 0;
693
694 if (cpu > num_possible_cpus()) {
695 rc = -EINVAL;
696 goto out;
697 }
698
699 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
700 mutex_lock(&driver_lock);
701
702 strt_acpu_s = scalable[cpu].current_speed;
703
704 /* Return early if rate didn't change. */
705 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
706 goto out;
707
708 /* Find target frequency. */
709 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
710 if (tgt->speed.khz == rate) {
711 tgt_acpu_s = &tgt->speed;
712 break;
713 }
714 }
715 if (tgt->speed.khz == 0) {
716 rc = -EINVAL;
717 goto out;
718 }
719
720 /* Calculate voltage requirements for the current CPU. */
721 vdd_mem = calculate_vdd_mem(tgt);
722 vdd_dig = calculate_vdd_dig(tgt);
723 vdd_core = calculate_vdd_core(tgt);
724
725 /* Increase VDD levels if needed. */
726 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
727 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
728 if (rc)
729 goto out;
730 }
731
732 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
733 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
734
735 /* Set the CPU speed. */
736 set_speed(&scalable[cpu], tgt_acpu_s, reason);
737
738 /*
739 * Update the L2 vote and apply the rate change. A spinlock is
740 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700741 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700742 * and the driver_lock mutex is not acquired.
743 */
744 spin_lock_irqsave(&l2_lock, flags);
745 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
746 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
747 spin_unlock_irqrestore(&l2_lock, flags);
748
749 /* Nothing else to do for power collapse or SWFI. */
750 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
751 goto out;
752
753 /* Update bus bandwith request. */
754 set_bus_bw(tgt_l2_l->bw_level);
755
756 /* Drop VDD levels if we can. */
757 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
758
759 scalable[cpu].first_set_call = false;
760 pr_debug("ACPU%d speed change complete\n", cpu);
761
762out:
763 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
764 mutex_unlock(&driver_lock);
765 return rc;
766}
767
768/* Initialize a HFPLL at a given rate and enable it. */
769static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
770{
771 pr_debug("Initializing HFPLL%d\n", sc - scalable);
772
773 /* Disable the PLL for re-programming. */
774 hfpll_disable(sc);
775
776 /* Configure PLL parameters for integer mode. */
777 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
778 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
779 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
780
781 /* Program droop controller. */
782 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
783
784 /* Set an initial rate and enable the PLL. */
785 hfpll_set_rate(sc, tgt_s);
786 hfpll_enable(sc);
787}
788
789/* Voltage regulator initialization. */
790static void __init regulator_init(void)
791{
792 int cpu, ret;
793 struct scalable *sc;
794
795 for_each_possible_cpu(cpu) {
796 sc = &scalable[cpu];
797 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
798 sc->vreg[VREG_CORE].name);
799 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
800 pr_err("regulator_get(%s) failed (%ld)\n",
801 sc->vreg[VREG_CORE].name,
802 PTR_ERR(sc->vreg[VREG_CORE].reg));
803 BUG();
804 }
805
806 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
807 sc->vreg[VREG_CORE].max_vdd,
808 sc->vreg[VREG_CORE].max_vdd);
809 if (ret)
810 pr_err("regulator_set_voltage(%s) failed"
811 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
812
813 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
814 if (ret)
815 pr_err("regulator_enable(%s) failed (%d)\n",
816 sc->vreg[VREG_CORE].name, ret);
817 }
818}
819
820#define INIT_QSB_ID 0
821#define INIT_HFPLL_ID 1
822/* Set initial rate for a given core. */
823static void __init init_clock_sources(struct scalable *sc,
824 struct core_speed *tgt_s)
825{
826 uint32_t pri_src, regval;
827
828 /*
829 * If the HFPLL is in use, program AUX source for QSB, switch to it,
830 * re-initialize the HFPLL, and switch back to the HFPLL. Otherwise,
831 * the HFPLL is not in use, so we can switch directly to it.
832 */
833 pri_src = get_pri_clk_src(scalable);
834 if (pri_src == PRI_SRC_SEL_HFPLL || pri_src == PRI_SRC_SEL_HFPLL_DIV2) {
835 set_sec_clk_src(sc, SEC_SRC_SEL_QSB);
836 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
837 }
838 hfpll_init(sc, tgt_s);
839
840 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700841 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700842 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700843 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844
845 /* Select PLL8 as AUX source input to the secondary MUX. */
846 writel_relaxed(0x3, sc->aux_clk_sel);
847
848 set_pri_clk_src(sc, tgt_s->pri_src_sel);
849 sc->current_speed = tgt_s;
850
851 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700852 * Set this flag so that the first call to acpuclk_8960_set_rate() can
853 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700854 */
855 sc->first_set_call = true;
856}
857
Matt Wagantall8e726c72011-08-06 00:49:28 -0700858static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700859{
Matt Wagantall6b013ca2011-10-12 14:15:45 -0700860 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -0700861 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -0700862
863 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
864 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700865}
866
867/* Register with bus driver. */
868static void __init bus_init(void)
869{
870 int ret;
871
872 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
873 if (!bus_perf_client) {
874 pr_err("unable to register bus client\n");
875 BUG();
876 }
877
878 ret = msm_bus_scale_client_update_request(bus_perf_client,
879 (ARRAY_SIZE(bw_level_tbl)-1));
880 if (ret)
881 pr_err("initial bandwidth request failed (%d)\n", ret);
882}
883
884#ifdef CONFIG_CPU_FREQ_MSM
885static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
886
887static void __init cpufreq_table_init(void)
888{
889 int cpu;
890
891 for_each_possible_cpu(cpu) {
892 int i, freq_cnt = 0;
893 /* Construct the freq_table tables from acpu_freq_tbl. */
894 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
895 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
896 if (acpu_freq_tbl[i].use_for_scaling) {
897 freq_table[cpu][freq_cnt].index = freq_cnt;
898 freq_table[cpu][freq_cnt].frequency
899 = acpu_freq_tbl[i].speed.khz;
900 freq_cnt++;
901 }
902 }
903 /* freq_table not big enough to store all usable freqs. */
904 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
905
906 freq_table[cpu][freq_cnt].index = freq_cnt;
907 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
908
909 pr_info("CPU%d: %d scaling frequencies supported.\n",
910 cpu, freq_cnt);
911
912 /* Register table with CPUFreq. */
913 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
914 }
915}
916#else
917static void __init cpufreq_table_init(void) {}
918#endif
919
920#define HOT_UNPLUG_KHZ STBY_KHZ
921static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
922 unsigned long action, void *hcpu)
923{
924 static int prev_khz[NR_CPUS];
925 static int prev_pri_src[NR_CPUS];
926 static int prev_sec_src[NR_CPUS];
927 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928
929 switch (action) {
930 case CPU_DYING:
931 case CPU_DYING_FROZEN:
932 /*
Matt Wagantall27663842011-08-25 15:11:48 -0700933 * On Krait v1, the primary and secondary muxes must be set
934 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700935 */
Matt Wagantall27663842011-08-25 15:11:48 -0700936 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700937 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
938 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
939 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
940 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
941 }
942 break;
943 case CPU_DEAD:
944 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700945 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700946 /* Fall through. */
947 case CPU_UP_CANCELED:
948 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700949 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950 break;
951 case CPU_UP_PREPARE:
952 case CPU_UP_PREPARE_FROZEN:
953 if (WARN_ON(!prev_khz[cpu]))
954 prev_khz[cpu] = acpu_freq_tbl->speed.khz;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700955 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700956 break;
957 case CPU_STARTING:
958 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -0700959 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700960 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
961 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
962 }
963 break;
964 default:
965 break;
966 }
967
968 return NOTIFY_OK;
969}
970
971static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
972 .notifier_call = acpuclock_cpu_callback,
973};
974
Matt Wagantall6b013ca2011-10-12 14:15:45 -0700975static struct acpu_level * __init select_freq_plan(void)
976{
977 struct acpu_level *l, *max_acpu_level = NULL;
978
979 /* Select frequency tables. */
980 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -0700981 uint32_t pte_efuse, pvs;
982
983 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
984 pvs = (pte_efuse >> 10) & 0x7;
985 if (pvs == 0x7)
986 pvs = (pte_efuse >> 13) & 0x7;
987
988 switch (pvs) {
989 case 0x0:
990 case 0x7:
991 pr_info("ACPU PVS: Slow\n");
992 break;
993 case 0x1:
994 pr_info("ACPU PVS: Nominal\n");
995 break;
996 case 0x3:
997 pr_info("ACPU PVS: Fast\n");
998 break;
999 default:
1000 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
1001 break;
1002 }
1003
1004 /* TODO: Select tables based on PVS data. */
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001005 scalable = scalable_8960;
1006 acpu_freq_tbl = acpu_freq_tbl_8960;
1007 l2_freq_tbl = l2_freq_tbl_8960;
1008 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960);
1009 } else if (cpu_is_apq8064()) {
1010 scalable = scalable_8064;
1011 acpu_freq_tbl = acpu_freq_tbl_8064;
1012 l2_freq_tbl = l2_freq_tbl_8064;
1013 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
1014 } else {
1015 BUG();
1016 }
1017
1018 /* Find the max supported scaling frequency. */
1019 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1020 if (l->use_for_scaling)
1021 max_acpu_level = l;
1022 BUG_ON(!max_acpu_level);
1023 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1024
1025 return max_acpu_level;
1026}
1027
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001028static struct acpuclk_data acpuclk_8960_data = {
1029 .set_rate = acpuclk_8960_set_rate,
1030 .get_rate = acpuclk_8960_get_rate,
1031 .power_collapse_khz = STBY_KHZ,
1032 .wait_for_irq_khz = STBY_KHZ,
1033};
1034
Matt Wagantallec57f062011-08-16 23:54:46 -07001035static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001036{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001037 struct acpu_level *max_acpu_level = select_freq_plan();
1038 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1039 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001040
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001041 regulator_init();
1042 bus_init();
1043 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001044
1045 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001046 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001047
1048 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001049}
Matt Wagantallec57f062011-08-16 23:54:46 -07001050
1051struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1052 .init = acpuclk_8960_init,
1053};