blob: cfc7dd05e436b843d3d47a22727ccaa8de595f7a [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);
Stephen Boyd753b5092011-10-17 19:14:12 -0700404
405 /* Re-enable secondary source clock gating. */
406 regval &= ~SECCLKAGD;
407 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700408}
409
410/* Enable an already-configured HFPLL. */
411static void hfpll_enable(struct scalable *sc)
412{
413 /* Disable PLL bypass mode. */
414 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
415
416 /*
417 * H/W requires a 5us delay between disabling the bypass and
418 * de-asserting the reset. Delay 10us just to be safe.
419 */
420 mb();
421 udelay(10);
422
423 /* De-assert active-low PLL reset. */
424 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
425
426 /* Wait for PLL to lock. */
427 mb();
428 udelay(60);
429
430 /* Enable PLL output. */
431 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
432}
433
434/* Disable a HFPLL for power-savings or while its being reprogrammed. */
435static void hfpll_disable(struct scalable *sc)
436{
437 /*
438 * Disable the PLL output, disable test mode, enable
439 * the bypass mode, and assert the reset.
440 */
441 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
442}
443
444/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
445static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
446{
447 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
448}
449
450/* Return the L2 speed that should be applied. */
451static struct l2_level *compute_l2_level(struct scalable *sc,
452 struct l2_level *vote_l)
453{
454 struct l2_level *new_l;
455 int cpu;
456
457 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700458 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700459
460 /* Find max L2 speed vote. */
461 sc->l2_vote = vote_l;
462 new_l = l2_freq_tbl;
463 for_each_present_cpu(cpu)
464 new_l = max(new_l, scalable[cpu].l2_vote);
465
466 return new_l;
467}
468
469/* Update the bus bandwidth request. */
470static void set_bus_bw(unsigned int bw)
471{
472 int ret;
473
474 /* Bounds check. */
475 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
476 pr_err("invalid bandwidth request (%d)\n", bw);
477 return;
478 }
479
480 /* Update bandwidth if request has changed. This may sleep. */
481 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
482 if (ret)
483 pr_err("bandwidth request failed (%d)\n", ret);
484}
485
486/* Set the CPU or L2 clock speed. */
487static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
488 enum setrate_reason reason)
489{
490 struct core_speed *strt_s = sc->current_speed;
491
492 if (tgt_s == strt_s)
493 return;
494
495 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
496 /* Move CPU to QSB source. */
497 /*
498 * TODO: If using QSB here requires elevating voltages,
499 * consider using PLL8 instead.
500 */
501 set_sec_clk_src(sc, SEC_SRC_SEL_QSB);
502 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
503
504 /* Program CPU HFPLL. */
505 hfpll_disable(sc);
506 hfpll_set_rate(sc, tgt_s);
507 hfpll_enable(sc);
508
509 /* Move CPU to HFPLL source. */
510 set_pri_clk_src(sc, tgt_s->pri_src_sel);
511 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
512 /* TODO: Enable source. */
513 /*
514 * If responding to CPU_DEAD we must be running on another
515 * CPU. Therefore, we can't access the downed CPU's CP15
516 * clock MUX registers from here and can't change clock sources.
517 * Just turn off the PLL- since the CPU is down already, halting
518 * its clock should be safe.
519 */
520 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
521 set_sec_clk_src(sc, tgt_s->sec_src_sel);
522 set_pri_clk_src(sc, tgt_s->pri_src_sel);
523 }
524 hfpll_disable(sc);
525 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
526 hfpll_set_rate(sc, tgt_s);
527 hfpll_enable(sc);
528 /*
529 * If responding to CPU_UP_PREPARE, we can't change CP15
530 * registers for the CPU that's coming up since we're not
531 * running on that CPU. That's okay though, since the MUX
532 * source was not changed on the way down, either.
533 */
534 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
535 set_pri_clk_src(sc, tgt_s->pri_src_sel);
536 /* TODO: Disable source. */
537 } else {
538 /* TODO: Enable source. */
539 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
540 set_sec_clk_src(sc, tgt_s->sec_src_sel);
541 /* TODO: Disable source. */
542 }
543
544 sc->current_speed = tgt_s;
545}
546
547/* Apply any per-cpu voltage increases. */
548static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
549 unsigned int vdd_dig, enum setrate_reason reason)
550{
551 struct scalable *sc = &scalable[cpu];
552 int rc;
553
554 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700555 * Increase vdd_mem active-set before vdd_dig.
556 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700557 */
558 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
559 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
560 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
561 sc->vreg[VREG_MEM].max_vdd, 0);
562 if (rc) {
563 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
564 __func__, cpu, rc);
565 return rc;
566 }
567 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
568 }
569
570 /* Increase vdd_dig active-set vote. */
571 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
572 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
573 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
574 sc->vreg[VREG_DIG].max_vdd, 0);
575 if (rc) {
576 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
577 __func__, cpu, rc);
578 return rc;
579 }
580 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
581 }
582
583 /*
584 * Update per-CPU core voltage. Don't do this for the hotplug path for
585 * which it should already be correct. Attempting to set it is bad
586 * because we don't know what CPU we are running on at this point, but
587 * the CPU regulator API requires we call it from the affected CPU.
588 */
589 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
590 && reason != SETRATE_HOTPLUG) {
591 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
592 sc->vreg[VREG_CORE].max_vdd);
593 if (rc) {
594 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
595 __func__, cpu, rc);
596 return rc;
597 }
598 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
599 }
600
601 return rc;
602}
603
604/* Apply any per-cpu voltage decreases. */
605static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
606 unsigned int vdd_dig, enum setrate_reason reason)
607{
608 struct scalable *sc = &scalable[cpu];
609 int ret;
610
611 /*
612 * Update per-CPU core voltage. This must be called on the CPU
613 * that's being affected. Don't do this in the hotplug remove path,
614 * where the rail is off and we're executing on the other CPU.
615 */
616 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
617 && reason != SETRATE_HOTPLUG) {
618 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
619 sc->vreg[VREG_CORE].max_vdd);
620 if (ret) {
621 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
622 __func__, cpu, ret);
623 return;
624 }
625 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
626 }
627
628 /* Decrease vdd_dig active-set vote. */
629 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
630 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
631 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
632 sc->vreg[VREG_DIG].max_vdd, 0);
633 if (ret) {
634 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
635 __func__, cpu, ret);
636 return;
637 }
638 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
639 }
640
641 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700642 * Decrease vdd_mem active-set after vdd_dig.
643 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700644 */
645 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
646 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
647 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
648 sc->vreg[VREG_MEM].max_vdd, 0);
649 if (ret) {
650 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
651 __func__, cpu, ret);
652 return;
653 }
654 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
655 }
656}
657
658static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
659{
Matt Wagantallabd55f02011-09-12 11:45:54 -0700660 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700661}
662
663static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
664{
665 unsigned int pll_vdd_dig;
666
667 if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
668 pll_vdd_dig = HFPLL_NOMINAL_VDD;
669 else
670 pll_vdd_dig = HFPLL_LOW_VDD;
671
672 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
673}
674
675static unsigned int calculate_vdd_core(struct acpu_level *tgt)
676{
677 unsigned int pll_vdd_core;
678
679 if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
680 pll_vdd_core = HFPLL_NOMINAL_VDD;
681 else
682 pll_vdd_core = HFPLL_LOW_VDD;
683
684 return max(tgt->vdd_core, pll_vdd_core);
685}
686
687/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700688static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
689 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690{
691 struct core_speed *strt_acpu_s, *tgt_acpu_s;
692 struct l2_level *tgt_l2_l;
693 struct acpu_level *tgt;
694 unsigned int vdd_mem, vdd_dig, vdd_core;
695 unsigned long flags;
696 int rc = 0;
697
698 if (cpu > num_possible_cpus()) {
699 rc = -EINVAL;
700 goto out;
701 }
702
703 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
704 mutex_lock(&driver_lock);
705
706 strt_acpu_s = scalable[cpu].current_speed;
707
708 /* Return early if rate didn't change. */
709 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
710 goto out;
711
712 /* Find target frequency. */
713 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
714 if (tgt->speed.khz == rate) {
715 tgt_acpu_s = &tgt->speed;
716 break;
717 }
718 }
719 if (tgt->speed.khz == 0) {
720 rc = -EINVAL;
721 goto out;
722 }
723
724 /* Calculate voltage requirements for the current CPU. */
725 vdd_mem = calculate_vdd_mem(tgt);
726 vdd_dig = calculate_vdd_dig(tgt);
727 vdd_core = calculate_vdd_core(tgt);
728
729 /* Increase VDD levels if needed. */
730 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
731 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
732 if (rc)
733 goto out;
734 }
735
736 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
737 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
738
739 /* Set the CPU speed. */
740 set_speed(&scalable[cpu], tgt_acpu_s, reason);
741
742 /*
743 * Update the L2 vote and apply the rate change. A spinlock is
744 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700745 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746 * and the driver_lock mutex is not acquired.
747 */
748 spin_lock_irqsave(&l2_lock, flags);
749 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
750 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
751 spin_unlock_irqrestore(&l2_lock, flags);
752
753 /* Nothing else to do for power collapse or SWFI. */
754 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
755 goto out;
756
757 /* Update bus bandwith request. */
758 set_bus_bw(tgt_l2_l->bw_level);
759
760 /* Drop VDD levels if we can. */
761 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
762
763 scalable[cpu].first_set_call = false;
764 pr_debug("ACPU%d speed change complete\n", cpu);
765
766out:
767 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
768 mutex_unlock(&driver_lock);
769 return rc;
770}
771
772/* Initialize a HFPLL at a given rate and enable it. */
773static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
774{
775 pr_debug("Initializing HFPLL%d\n", sc - scalable);
776
777 /* Disable the PLL for re-programming. */
778 hfpll_disable(sc);
779
780 /* Configure PLL parameters for integer mode. */
781 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
782 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
783 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
784
785 /* Program droop controller. */
786 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
787
788 /* Set an initial rate and enable the PLL. */
789 hfpll_set_rate(sc, tgt_s);
790 hfpll_enable(sc);
791}
792
793/* Voltage regulator initialization. */
794static void __init regulator_init(void)
795{
796 int cpu, ret;
797 struct scalable *sc;
798
799 for_each_possible_cpu(cpu) {
800 sc = &scalable[cpu];
801 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
802 sc->vreg[VREG_CORE].name);
803 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
804 pr_err("regulator_get(%s) failed (%ld)\n",
805 sc->vreg[VREG_CORE].name,
806 PTR_ERR(sc->vreg[VREG_CORE].reg));
807 BUG();
808 }
809
810 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
811 sc->vreg[VREG_CORE].max_vdd,
812 sc->vreg[VREG_CORE].max_vdd);
813 if (ret)
814 pr_err("regulator_set_voltage(%s) failed"
815 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
816
817 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
818 if (ret)
819 pr_err("regulator_enable(%s) failed (%d)\n",
820 sc->vreg[VREG_CORE].name, ret);
821 }
822}
823
824#define INIT_QSB_ID 0
825#define INIT_HFPLL_ID 1
826/* Set initial rate for a given core. */
827static void __init init_clock_sources(struct scalable *sc,
828 struct core_speed *tgt_s)
829{
830 uint32_t pri_src, regval;
831
832 /*
833 * If the HFPLL is in use, program AUX source for QSB, switch to it,
834 * re-initialize the HFPLL, and switch back to the HFPLL. Otherwise,
835 * the HFPLL is not in use, so we can switch directly to it.
836 */
837 pri_src = get_pri_clk_src(scalable);
838 if (pri_src == PRI_SRC_SEL_HFPLL || pri_src == PRI_SRC_SEL_HFPLL_DIV2) {
839 set_sec_clk_src(sc, SEC_SRC_SEL_QSB);
840 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
841 }
842 hfpll_init(sc, tgt_s);
843
844 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700845 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700846 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700847 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700848
849 /* Select PLL8 as AUX source input to the secondary MUX. */
850 writel_relaxed(0x3, sc->aux_clk_sel);
851
852 set_pri_clk_src(sc, tgt_s->pri_src_sel);
853 sc->current_speed = tgt_s;
854
855 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700856 * Set this flag so that the first call to acpuclk_8960_set_rate() can
857 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700858 */
859 sc->first_set_call = true;
860}
861
Matt Wagantall8e726c72011-08-06 00:49:28 -0700862static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863{
Matt Wagantall6b013ca2011-10-12 14:15:45 -0700864 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -0700865 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -0700866
867 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
868 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700869}
870
871/* Register with bus driver. */
872static void __init bus_init(void)
873{
874 int ret;
875
876 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
877 if (!bus_perf_client) {
878 pr_err("unable to register bus client\n");
879 BUG();
880 }
881
882 ret = msm_bus_scale_client_update_request(bus_perf_client,
883 (ARRAY_SIZE(bw_level_tbl)-1));
884 if (ret)
885 pr_err("initial bandwidth request failed (%d)\n", ret);
886}
887
888#ifdef CONFIG_CPU_FREQ_MSM
889static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
890
891static void __init cpufreq_table_init(void)
892{
893 int cpu;
894
895 for_each_possible_cpu(cpu) {
896 int i, freq_cnt = 0;
897 /* Construct the freq_table tables from acpu_freq_tbl. */
898 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
899 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
900 if (acpu_freq_tbl[i].use_for_scaling) {
901 freq_table[cpu][freq_cnt].index = freq_cnt;
902 freq_table[cpu][freq_cnt].frequency
903 = acpu_freq_tbl[i].speed.khz;
904 freq_cnt++;
905 }
906 }
907 /* freq_table not big enough to store all usable freqs. */
908 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
909
910 freq_table[cpu][freq_cnt].index = freq_cnt;
911 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
912
913 pr_info("CPU%d: %d scaling frequencies supported.\n",
914 cpu, freq_cnt);
915
916 /* Register table with CPUFreq. */
917 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
918 }
919}
920#else
921static void __init cpufreq_table_init(void) {}
922#endif
923
924#define HOT_UNPLUG_KHZ STBY_KHZ
925static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
926 unsigned long action, void *hcpu)
927{
928 static int prev_khz[NR_CPUS];
929 static int prev_pri_src[NR_CPUS];
930 static int prev_sec_src[NR_CPUS];
931 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932
933 switch (action) {
934 case CPU_DYING:
935 case CPU_DYING_FROZEN:
936 /*
Matt Wagantall27663842011-08-25 15:11:48 -0700937 * On Krait v1, the primary and secondary muxes must be set
938 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700939 */
Matt Wagantall27663842011-08-25 15:11:48 -0700940 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700941 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
942 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
943 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
944 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
945 }
946 break;
947 case CPU_DEAD:
948 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700949 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950 /* Fall through. */
951 case CPU_UP_CANCELED:
952 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700953 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700954 break;
955 case CPU_UP_PREPARE:
956 case CPU_UP_PREPARE_FROZEN:
957 if (WARN_ON(!prev_khz[cpu]))
958 prev_khz[cpu] = acpu_freq_tbl->speed.khz;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700959 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700960 break;
961 case CPU_STARTING:
962 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -0700963 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
965 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
966 }
967 break;
968 default:
969 break;
970 }
971
972 return NOTIFY_OK;
973}
974
975static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
976 .notifier_call = acpuclock_cpu_callback,
977};
978
Matt Wagantall6b013ca2011-10-12 14:15:45 -0700979static struct acpu_level * __init select_freq_plan(void)
980{
981 struct acpu_level *l, *max_acpu_level = NULL;
982
983 /* Select frequency tables. */
984 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -0700985 uint32_t pte_efuse, pvs;
986
987 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
988 pvs = (pte_efuse >> 10) & 0x7;
989 if (pvs == 0x7)
990 pvs = (pte_efuse >> 13) & 0x7;
991
992 switch (pvs) {
993 case 0x0:
994 case 0x7:
995 pr_info("ACPU PVS: Slow\n");
996 break;
997 case 0x1:
998 pr_info("ACPU PVS: Nominal\n");
999 break;
1000 case 0x3:
1001 pr_info("ACPU PVS: Fast\n");
1002 break;
1003 default:
1004 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
1005 break;
1006 }
1007
1008 /* TODO: Select tables based on PVS data. */
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001009 scalable = scalable_8960;
1010 acpu_freq_tbl = acpu_freq_tbl_8960;
1011 l2_freq_tbl = l2_freq_tbl_8960;
1012 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960);
1013 } else if (cpu_is_apq8064()) {
1014 scalable = scalable_8064;
1015 acpu_freq_tbl = acpu_freq_tbl_8064;
1016 l2_freq_tbl = l2_freq_tbl_8064;
1017 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
1018 } else {
1019 BUG();
1020 }
1021
1022 /* Find the max supported scaling frequency. */
1023 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1024 if (l->use_for_scaling)
1025 max_acpu_level = l;
1026 BUG_ON(!max_acpu_level);
1027 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1028
1029 return max_acpu_level;
1030}
1031
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001032static struct acpuclk_data acpuclk_8960_data = {
1033 .set_rate = acpuclk_8960_set_rate,
1034 .get_rate = acpuclk_8960_get_rate,
1035 .power_collapse_khz = STBY_KHZ,
1036 .wait_for_irq_khz = STBY_KHZ,
1037};
1038
Matt Wagantallec57f062011-08-16 23:54:46 -07001039static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001040{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001041 struct acpu_level *max_acpu_level = select_freq_plan();
1042 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1043 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001044
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001045 regulator_init();
1046 bus_init();
1047 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001048
1049 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001050 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001051
1052 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001053}
Matt Wagantallec57f062011-08-16 23:54:46 -07001054
1055struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1056 .init = acpuclk_8960_init,
1057};