blob: 408f77bdcb2598f1dfc06edd51dd461babd79c6f [file] [log] [blame]
Stephen Boydaefb8de2012-01-05 19:05:01 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#define pr_fmt(fmt) "%s: " fmt, __func__
14
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/io.h>
18#include <linux/delay.h>
19#include <linux/mutex.h>
20#include <linux/err.h>
21#include <linux/errno.h>
22#include <linux/cpufreq.h>
23#include <linux/cpu.h>
24#include <linux/regulator/consumer.h>
25
26#include <asm/mach-types.h>
27#include <asm/cpu.h>
28
29#include <mach/board.h>
30#include <mach/msm_iomap.h>
31#include <mach/rpm-regulator.h>
32#include <mach/msm_bus.h>
33#include <mach/msm_bus_board.h>
34#include <mach/socinfo.h>
Stephen Boyd469ed3e2011-09-29 16:41:19 -070035#include <mach/msm-krait-l2-accessors.h>
Matt Wagantallcb12c392011-10-19 10:32:07 -070036#include <mach/rpm-regulator.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38#include "acpuclock.h"
39
40/*
41 * Source IDs.
42 * These must be negative to not overlap with the source IDs
43 * used by the 8x60 local clock driver.
44 */
45#define PLL_8 0
46#define HFPLL -1
47#define QSB -2
48
49/* Mux source selects. */
50#define PRI_SRC_SEL_SEC_SRC 0
51#define PRI_SRC_SEL_HFPLL 1
52#define PRI_SRC_SEL_HFPLL_DIV2 2
53#define SEC_SRC_SEL_QSB 0
Matt Wagantall65e5e4b2011-10-27 16:52:10 -070054#define SEC_SRC_SEL_AUX 2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055
56/* HFPLL registers offsets. */
57#define HFPLL_MODE 0x00
58#define HFPLL_CONFIG_CTL 0x04
59#define HFPLL_L_VAL 0x08
60#define HFPLL_M_VAL 0x0C
61#define HFPLL_N_VAL 0x10
62#define HFPLL_DROOP_CTL 0x14
63
64/* CP15 L2 indirect addresses. */
65#define L2CPMR_IADDR 0x500
66#define L2CPUCPMR_IADDR 0x501
67
68#define STBY_KHZ 1
69
70#define HFPLL_NOMINAL_VDD 1050000
Tianyi Goufff00402012-01-23 14:36:20 -080071#define HFPLL_LOW_VDD_8960 850000
72#define HFPLL_LOW_VDD 945000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070073#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
74
75#define SECCLKAGD BIT(4)
76
Matt Wagantalla518f8f2011-10-17 13:24:53 -070077/* PTE EFUSE register. */
78#define QFPROM_PTE_EFUSE_ADDR (MSM_QFPROM_BASE + 0x00C0)
79
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080enum scalables {
81 CPU0 = 0,
82 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070083 CPU2,
84 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085 L2,
86 NUM_SCALABLES
87};
88
89enum vregs {
90 VREG_CORE,
91 VREG_MEM,
92 VREG_DIG,
Matt Wagantallcb12c392011-10-19 10:32:07 -070093 VREG_HFPLL_A,
94 VREG_HFPLL_B,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095 NUM_VREG
96};
97
98struct vreg {
99 const char name[15];
100 const unsigned int max_vdd;
101 const int rpm_vreg_voter;
102 const int rpm_vreg_id;
103 struct regulator *reg;
104 unsigned int cur_vdd;
105};
106
107struct core_speed {
108 unsigned int khz;
109 int src;
110 unsigned int pri_src_sel;
111 unsigned int sec_src_sel;
112 unsigned int pll_l_val;
113};
114
115struct l2_level {
116 struct core_speed speed;
117 unsigned int vdd_dig;
118 unsigned int vdd_mem;
119 unsigned int bw_level;
120};
121
122struct acpu_level {
123 unsigned int use_for_scaling;
124 struct core_speed speed;
125 struct l2_level *l2_level;
126 unsigned int vdd_core;
127};
128
129struct scalable {
130 void * __iomem const hfpll_base;
131 void * __iomem const aux_clk_sel;
132 const uint32_t l2cpmr_iaddr;
133 struct core_speed *current_speed;
134 struct l2_level *l2_vote;
135 struct vreg vreg[NUM_VREG];
136 bool first_set_call;
137};
138
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700139static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140 [CPU0] = {
141 .hfpll_base = MSM_HFPLL_BASE + 0x200,
142 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
143 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800144 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700145 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
146 RPM_VREG_VOTER1,
147 RPM_VREG_ID_PM8921_L24 },
148 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
149 RPM_VREG_VOTER1,
150 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall627f4312011-12-13 13:33:47 -0800151 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700152 RPM_VREG_VOTER1,
153 RPM_VREG_ID_PM8921_S8 },
154 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
155 RPM_VREG_VOTER1,
156 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700157 },
158 [CPU1] = {
159 .hfpll_base = MSM_HFPLL_BASE + 0x300,
160 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
161 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800162 .vreg[VREG_CORE] = { "krait1", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
164 RPM_VREG_VOTER2,
165 RPM_VREG_ID_PM8921_L24 },
166 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
167 RPM_VREG_VOTER2,
168 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall627f4312011-12-13 13:33:47 -0800169 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700170 RPM_VREG_VOTER2,
171 RPM_VREG_ID_PM8921_S8 },
172 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
173 RPM_VREG_VOTER2,
174 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175 },
176 [L2] = {
177 .hfpll_base = MSM_HFPLL_BASE + 0x400,
178 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
179 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantall627f4312011-12-13 13:33:47 -0800180 .vreg[VREG_HFPLL_A] = { "hfpll", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700181 RPM_VREG_VOTER6,
182 RPM_VREG_ID_PM8921_S8 },
183 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
184 RPM_VREG_VOTER6,
185 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186 },
187};
188
Stephen Boyd7ad84752011-08-05 14:04:28 -0700189static DEFINE_MUTEX(driver_lock);
190static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700192static struct scalable scalable_8064[] = {
193 [CPU0] = {
194 .hfpll_base = MSM_HFPLL_BASE + 0x200,
195 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
196 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
197 .vreg[VREG_CORE] = { "krait0", 1150000 },
198 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
199 RPM_VREG_VOTER1,
200 RPM_VREG_ID_PM8921_L24 },
201 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
202 RPM_VREG_VOTER1,
203 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800204 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
205 RPM_VREG_VOTER1,
206 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700207 },
208 [CPU1] = {
209 .hfpll_base = MSM_HFPLL_BASE + 0x240,
210 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
211 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
212 .vreg[VREG_CORE] = { "krait1", 1150000 },
213 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
214 RPM_VREG_VOTER2,
215 RPM_VREG_ID_PM8921_L24 },
216 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
217 RPM_VREG_VOTER2,
218 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800219 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
220 RPM_VREG_VOTER2,
221 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700222 },
223 [CPU2] = {
224 .hfpll_base = MSM_HFPLL_BASE + 0x280,
225 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
226 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
227 .vreg[VREG_CORE] = { "krait2", 1150000 },
228 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
229 RPM_VREG_VOTER4,
230 RPM_VREG_ID_PM8921_L24 },
231 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
232 RPM_VREG_VOTER4,
233 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800234 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
235 RPM_VREG_VOTER4,
236 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700237 },
238 [CPU3] = {
239 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
240 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
241 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
242 .vreg[VREG_CORE] = { "krait3", 1150000 },
243 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
244 RPM_VREG_VOTER5,
245 RPM_VREG_ID_PM8921_L24 },
246 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
247 RPM_VREG_VOTER5,
248 RPM_VREG_ID_PM8921_S3 },
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800249 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
250 RPM_VREG_VOTER5,
251 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700252 },
253 [L2] = {
254 .hfpll_base = MSM_HFPLL_BASE + 0x300,
255 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
256 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800257 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
258 RPM_VREG_VOTER6,
259 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700260 },
261};
262
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800263static struct scalable scalable_8930[] = {
264 [CPU0] = {
265 .hfpll_base = MSM_HFPLL_BASE + 0x200,
266 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
267 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
268 .vreg[VREG_CORE] = { "krait0", 1300000 },
269 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
270 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800271 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800272 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
273 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800274 RPM_VREG_ID_PM8038_S1 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800275 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
276 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800277 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800278 },
279 [CPU1] = {
280 .hfpll_base = MSM_HFPLL_BASE + 0x300,
281 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
282 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
283 .vreg[VREG_CORE] = { "krait1", 1300000 },
284 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
285 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800286 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800287 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
288 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800289 RPM_VREG_ID_PM8038_S1 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800290 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
291 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800292 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800293 },
294 [L2] = {
295 .hfpll_base = MSM_HFPLL_BASE + 0x400,
296 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
297 .l2cpmr_iaddr = L2CPMR_IADDR,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800298 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
299 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800300 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800301 },
302};
303
Tianyi Goue0b34de2011-12-20 11:20:10 -0800304/*TODO: Update the rpm vreg id when the rpm driver is ready */
305static struct scalable scalable_8627[] = {
306 [CPU0] = {
307 .hfpll_base = MSM_HFPLL_BASE + 0x200,
308 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
309 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
310 .vreg[VREG_CORE] = { "krait0", 1300000 },
311 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
312 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800313 RPM_VREG_ID_PM8038_L24 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800314 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
315 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800316 RPM_VREG_ID_PM8038_S1 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800317 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
318 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800319 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800320 },
321 [CPU1] = {
322 .hfpll_base = MSM_HFPLL_BASE + 0x300,
323 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
324 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
325 .vreg[VREG_CORE] = { "krait1", 1300000 },
326 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
327 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800328 RPM_VREG_ID_PM8038_L24 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800329 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
330 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800331 RPM_VREG_ID_PM8038_S1 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800332 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
333 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800334 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800335 },
336 [L2] = {
337 .hfpll_base = MSM_HFPLL_BASE + 0x400,
338 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
339 .l2cpmr_iaddr = L2CPMR_IADDR,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800340 .vreg[VREG_HFPLL_B] = { "hfpll", 1800000,
341 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800342 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800343 },
344};
345
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700346static struct scalable *scalable;
347static struct l2_level *l2_freq_tbl;
348static struct acpu_level *acpu_freq_tbl;
349static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700350
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700351/* Instantaneous bandwidth requests in MB/s. */
352#define BW_MBPS(_bw) \
353 { \
354 .vectors = (struct msm_bus_vectors[]){ \
355 {\
356 .src = MSM_BUS_MASTER_AMPSS_M0, \
357 .dst = MSM_BUS_SLAVE_EBI_CH0, \
358 .ib = (_bw) * 1000000UL, \
359 .ab = (_bw) * 100000UL, \
360 }, \
361 { \
362 .src = MSM_BUS_MASTER_AMPSS_M1, \
363 .dst = MSM_BUS_SLAVE_EBI_CH0, \
364 .ib = (_bw) * 1000000UL, \
365 .ab = (_bw) * 100000UL, \
366 }, \
367 }, \
368 .num_paths = 2, \
369 }
370static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800371 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
372 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
373 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
374 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
375 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
376 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
377 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700378};
379
380static struct msm_bus_scale_pdata bus_client_pdata = {
381 .usecase = bw_level_tbl,
382 .num_usecases = ARRAY_SIZE(bw_level_tbl),
383 .active_only = 1,
384 .name = "acpuclock",
385};
386
387static uint32_t bus_perf_client;
388
389/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800390#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
391static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700392 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700393 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700394 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
395 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
396 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
397 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
398 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
399 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700400 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700401 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
402 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
403 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404};
405
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800406static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
407 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
408 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
409 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
410 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
411 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
412 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
413 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
414 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
415 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
416 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
417 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
418 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
419 { 0, { 0 } }
420};
421
422static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
423 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
424 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
425 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
426 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
427 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
428 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
429 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
430 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
431 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
432 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
433 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
434 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700435 { 0, { 0 } }
436};
437
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800438#undef L2
439#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
440static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
441 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
442 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800443 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
444 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
445 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800446 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800447 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
448 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
449 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
450 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
451 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
452 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
453 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
454 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
455 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
456 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
457 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800458 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
459 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
460 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800461};
462
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800463static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800464 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
465 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
466 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 975000 },
467 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 975000 },
468 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 1000000 },
469 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
470 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
471 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1025000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800472 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1075000 },
473 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1075000 },
474 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
475 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1100000 },
476 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1125000 },
477 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800478 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
479 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
480 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
481 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1200000 },
482 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1225000 },
483 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1225000 },
484 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1237500 },
485 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1237500 },
486 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800487 { 0, { 0 } }
488};
489
490static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800491 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
492 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
493 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
494 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
495 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 950000 },
496 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 950000 },
497 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 975000 },
498 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 975000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800499 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800500 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1025000 },
501 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1050000 },
502 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1050000 },
503 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1075000 },
504 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800505 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
506 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
507 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
508 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1150000 },
509 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1175000 },
510 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1175000 },
511 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1187500 },
512 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1187500 },
513 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800514 { 0, { 0 } }
515};
516
Stephen Boyd5766f682011-12-27 19:21:08 -0800517static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800518 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
519 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
520 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 875000 },
521 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 875000 },
522 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
523 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 900000 },
524 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
525 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 925000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800526 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 975000 },
527 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 975000 },
528 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1000000 },
529 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1000000 },
530 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1025000 },
531 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1025000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800532 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
533 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
534 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
535 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1100000 },
536 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1125000 },
537 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1125000 },
538 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1137500 },
539 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1137500 },
540 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800541 { 0, { 0 } }
542};
543
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700544/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
545#undef L2
546#define L2(x) (&l2_freq_tbl_8064[(x)])
547static struct l2_level l2_freq_tbl_8064[] = {
548 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
549 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 0 },
550 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
551 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
552 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
553 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
554 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
555 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
556 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
557 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
558 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
559 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
560 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
561 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 3 },
562 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
563 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
564 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
565 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 4 },
566 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 4 },
567 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 4 },
568 [20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 4 },
569 [21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
570 [22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
571 [23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
572 [24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
573 [25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
574};
575
576/* TODO: Update core voltages when data is available. */
577static struct acpu_level acpu_freq_tbl_8064[] = {
578 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 1050000 },
579 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 1050000 },
580 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(2), 1050000 },
581 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(3), 1050000 },
582 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(4), 1050000 },
583 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 1050000 },
584 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1050000 },
585 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1050000 },
586 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(8), 1150000 },
587 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1150000 },
588 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(10), 1150000 },
589 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
590 { 0, { 0 } }
591};
592
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800593/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
594#undef L2
595#define L2(x) (&l2_freq_tbl_8930[(x)])
596static struct l2_level l2_freq_tbl_8930[] = {
597 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
598 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
599 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
600 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
601 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
602 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
603 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
604 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
605 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
606 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
607 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
608 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
609 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
610 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
611 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
612 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
613 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
614};
615
616/* TODO: Update core voltages when data is available. */
617static struct acpu_level acpu_freq_tbl_8930[] = {
618 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
619 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
620 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
621 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
622 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
623 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
624 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
625 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
626 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
627 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
628 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
629 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
630 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
631 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
632 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
633 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
634 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
635 { 0, { 0 } }
636};
637
Tianyi Goue0b34de2011-12-20 11:20:10 -0800638/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
639#undef L2
640#define L2(x) (&l2_freq_tbl_8627[(x)])
641static struct l2_level l2_freq_tbl_8627[] = {
642 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
643 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
644 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
645 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
646 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
647 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
648 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
649 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 3 },
650 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
651 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
652 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
653 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 4 },
654 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 4 },
655};
656
657/* TODO: Update core voltages when data is available. */
658static struct acpu_level acpu_freq_tbl_8627[] = {
659 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
660 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
661 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
662 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
663 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
664 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
665 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
666 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
667 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
668 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
669 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
670 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
671 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
672 { 0, { 0 } }
673};
674
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700675static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676{
677 return scalable[cpu].current_speed->khz;
678}
679
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700680/* Get the selected source on primary MUX. */
681static int get_pri_clk_src(struct scalable *sc)
682{
683 uint32_t regval;
684
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700685 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686 return regval & 0x3;
687}
688
689/* Set the selected source on primary MUX. */
690static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
691{
692 uint32_t regval;
693
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700694 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700695 regval &= ~0x3;
696 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700697 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698 /* Wait for switch to complete. */
699 mb();
700 udelay(1);
701}
702
703/* Get the selected source on secondary MUX. */
704static int get_sec_clk_src(struct scalable *sc)
705{
706 uint32_t regval;
707
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700708 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700709 return (regval >> 2) & 0x3;
710}
711
712/* Set the selected source on secondary MUX. */
713static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
714{
715 uint32_t regval;
716
717 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700718 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700719 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700720 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721
722 /* Program the MUX. */
723 regval &= ~(0x3 << 2);
724 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700725 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700726
727 /* Wait for switch to complete. */
728 mb();
729 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700730
731 /* Re-enable secondary source clock gating. */
732 regval &= ~SECCLKAGD;
733 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734}
735
736/* Enable an already-configured HFPLL. */
737static void hfpll_enable(struct scalable *sc)
738{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700739 int rc;
740
Tianyi Goufff00402012-01-23 14:36:20 -0800741 if (cpu_is_msm8960()) {
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800742 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
743 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 2100000,
744 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
745 if (rc)
746 pr_err("%s regulator enable failed (%d)\n",
747 sc->vreg[VREG_HFPLL_A].name, rc);
748 }
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -0700749 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
750 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
751 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
752 if (rc)
753 pr_err("%s regulator enable failed (%d)\n",
754 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700755
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 /* Disable PLL bypass mode. */
757 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
758
759 /*
760 * H/W requires a 5us delay between disabling the bypass and
761 * de-asserting the reset. Delay 10us just to be safe.
762 */
763 mb();
764 udelay(10);
765
766 /* De-assert active-low PLL reset. */
767 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
768
769 /* Wait for PLL to lock. */
770 mb();
771 udelay(60);
772
773 /* Enable PLL output. */
774 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
775}
776
777/* Disable a HFPLL for power-savings or while its being reprogrammed. */
778static void hfpll_disable(struct scalable *sc)
779{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700780 int rc;
781
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782 /*
783 * Disable the PLL output, disable test mode, enable
784 * the bypass mode, and assert the reset.
785 */
786 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700787
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -0700788 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
789 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
790 0, 0);
791 if (rc)
792 pr_err("%s regulator enable failed (%d)\n",
793 sc->vreg[VREG_HFPLL_B].name, rc);
Tianyi Goufff00402012-01-23 14:36:20 -0800794
795 if (cpu_is_msm8960()) {
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800796 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
797 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter, 0,
798 0, 0);
799 if (rc)
800 pr_err("%s regulator enable failed (%d)\n",
801 sc->vreg[VREG_HFPLL_A].name, rc);
802 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700803}
804
805/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
806static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
807{
808 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
809}
810
811/* Return the L2 speed that should be applied. */
812static struct l2_level *compute_l2_level(struct scalable *sc,
813 struct l2_level *vote_l)
814{
815 struct l2_level *new_l;
816 int cpu;
817
818 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700819 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700820
821 /* Find max L2 speed vote. */
822 sc->l2_vote = vote_l;
823 new_l = l2_freq_tbl;
824 for_each_present_cpu(cpu)
825 new_l = max(new_l, scalable[cpu].l2_vote);
826
827 return new_l;
828}
829
830/* Update the bus bandwidth request. */
831static void set_bus_bw(unsigned int bw)
832{
833 int ret;
834
835 /* Bounds check. */
836 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
837 pr_err("invalid bandwidth request (%d)\n", bw);
838 return;
839 }
840
841 /* Update bandwidth if request has changed. This may sleep. */
842 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
843 if (ret)
844 pr_err("bandwidth request failed (%d)\n", ret);
845}
846
847/* Set the CPU or L2 clock speed. */
848static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
849 enum setrate_reason reason)
850{
851 struct core_speed *strt_s = sc->current_speed;
852
853 if (tgt_s == strt_s)
854 return;
855
856 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700857 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700858 * Move to an always-on source running at a frequency that does
859 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700861 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
863
864 /* Program CPU HFPLL. */
865 hfpll_disable(sc);
866 hfpll_set_rate(sc, tgt_s);
867 hfpll_enable(sc);
868
869 /* Move CPU to HFPLL source. */
870 set_pri_clk_src(sc, tgt_s->pri_src_sel);
871 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700872 /*
873 * If responding to CPU_DEAD we must be running on another
874 * CPU. Therefore, we can't access the downed CPU's CP15
875 * clock MUX registers from here and can't change clock sources.
876 * Just turn off the PLL- since the CPU is down already, halting
877 * its clock should be safe.
878 */
879 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
880 set_sec_clk_src(sc, tgt_s->sec_src_sel);
881 set_pri_clk_src(sc, tgt_s->pri_src_sel);
882 }
883 hfpll_disable(sc);
884 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
885 hfpll_set_rate(sc, tgt_s);
886 hfpll_enable(sc);
887 /*
888 * If responding to CPU_UP_PREPARE, we can't change CP15
889 * registers for the CPU that's coming up since we're not
890 * running on that CPU. That's okay though, since the MUX
891 * source was not changed on the way down, either.
892 */
893 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
894 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700896 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
897 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700898 }
899
900 sc->current_speed = tgt_s;
901}
902
903/* Apply any per-cpu voltage increases. */
904static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
905 unsigned int vdd_dig, enum setrate_reason reason)
906{
907 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700908 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909
910 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700911 * Increase vdd_mem active-set before vdd_dig.
912 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913 */
914 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
915 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
916 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
917 sc->vreg[VREG_MEM].max_vdd, 0);
918 if (rc) {
919 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
920 __func__, cpu, rc);
921 return rc;
922 }
923 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
924 }
925
926 /* Increase vdd_dig active-set vote. */
927 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
928 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
929 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
930 sc->vreg[VREG_DIG].max_vdd, 0);
931 if (rc) {
932 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
933 __func__, cpu, rc);
934 return rc;
935 }
936 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
937 }
938
939 /*
940 * Update per-CPU core voltage. Don't do this for the hotplug path for
941 * which it should already be correct. Attempting to set it is bad
942 * because we don't know what CPU we are running on at this point, but
943 * the CPU regulator API requires we call it from the affected CPU.
944 */
945 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
946 && reason != SETRATE_HOTPLUG) {
947 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
948 sc->vreg[VREG_CORE].max_vdd);
949 if (rc) {
950 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
951 __func__, cpu, rc);
952 return rc;
953 }
954 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
955 }
956
957 return rc;
958}
959
960/* Apply any per-cpu voltage decreases. */
961static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
962 unsigned int vdd_dig, enum setrate_reason reason)
963{
964 struct scalable *sc = &scalable[cpu];
965 int ret;
966
967 /*
968 * Update per-CPU core voltage. This must be called on the CPU
969 * that's being affected. Don't do this in the hotplug remove path,
970 * where the rail is off and we're executing on the other CPU.
971 */
972 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
973 && reason != SETRATE_HOTPLUG) {
974 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
975 sc->vreg[VREG_CORE].max_vdd);
976 if (ret) {
977 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
978 __func__, cpu, ret);
979 return;
980 }
981 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
982 }
983
984 /* Decrease vdd_dig active-set vote. */
985 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
986 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
987 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
988 sc->vreg[VREG_DIG].max_vdd, 0);
989 if (ret) {
990 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
991 __func__, cpu, ret);
992 return;
993 }
994 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
995 }
996
997 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700998 * Decrease vdd_mem active-set after vdd_dig.
999 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001000 */
1001 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1002 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1003 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1004 sc->vreg[VREG_MEM].max_vdd, 0);
1005 if (ret) {
1006 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
1007 __func__, cpu, ret);
1008 return;
1009 }
1010 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1011 }
1012}
1013
1014static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1015{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001016 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001017}
1018
1019static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1020{
1021 unsigned int pll_vdd_dig;
1022
Stephen Boydc76158f2011-12-08 12:42:40 -08001023 if (tgt->l2_level->speed.src != HFPLL)
1024 pll_vdd_dig = 0;
1025 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001026 pll_vdd_dig = HFPLL_NOMINAL_VDD;
Tianyi Goufff00402012-01-23 14:36:20 -08001027 else {
1028 if (cpu_is_msm8960())
1029 pll_vdd_dig = HFPLL_LOW_VDD_8960;
1030 else
1031 pll_vdd_dig = HFPLL_LOW_VDD;
1032 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001033 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1034}
1035
1036static unsigned int calculate_vdd_core(struct acpu_level *tgt)
1037{
1038 unsigned int pll_vdd_core;
1039
Stephen Boydc76158f2011-12-08 12:42:40 -08001040 if (tgt->speed.src != HFPLL)
1041 pll_vdd_core = 0;
1042 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001043 pll_vdd_core = HFPLL_NOMINAL_VDD;
Tianyi Goufff00402012-01-23 14:36:20 -08001044 else {
1045 if (cpu_is_msm8960())
1046 pll_vdd_core = HFPLL_LOW_VDD_8960;
1047 else
1048 pll_vdd_core = HFPLL_LOW_VDD;
1049 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001050 return max(tgt->vdd_core, pll_vdd_core);
1051}
1052
1053/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001054static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1055 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001056{
1057 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1058 struct l2_level *tgt_l2_l;
1059 struct acpu_level *tgt;
1060 unsigned int vdd_mem, vdd_dig, vdd_core;
1061 unsigned long flags;
1062 int rc = 0;
1063
1064 if (cpu > num_possible_cpus()) {
1065 rc = -EINVAL;
1066 goto out;
1067 }
1068
1069 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1070 mutex_lock(&driver_lock);
1071
1072 strt_acpu_s = scalable[cpu].current_speed;
1073
1074 /* Return early if rate didn't change. */
1075 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1076 goto out;
1077
1078 /* Find target frequency. */
1079 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1080 if (tgt->speed.khz == rate) {
1081 tgt_acpu_s = &tgt->speed;
1082 break;
1083 }
1084 }
1085 if (tgt->speed.khz == 0) {
1086 rc = -EINVAL;
1087 goto out;
1088 }
1089
1090 /* Calculate voltage requirements for the current CPU. */
1091 vdd_mem = calculate_vdd_mem(tgt);
1092 vdd_dig = calculate_vdd_dig(tgt);
1093 vdd_core = calculate_vdd_core(tgt);
1094
1095 /* Increase VDD levels if needed. */
1096 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1097 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1098 if (rc)
1099 goto out;
1100 }
1101
1102 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1103 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1104
1105 /* Set the CPU speed. */
1106 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1107
1108 /*
1109 * Update the L2 vote and apply the rate change. A spinlock is
1110 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001111 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001112 * and the driver_lock mutex is not acquired.
1113 */
1114 spin_lock_irqsave(&l2_lock, flags);
1115 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1116 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1117 spin_unlock_irqrestore(&l2_lock, flags);
1118
1119 /* Nothing else to do for power collapse or SWFI. */
1120 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1121 goto out;
1122
1123 /* Update bus bandwith request. */
1124 set_bus_bw(tgt_l2_l->bw_level);
1125
1126 /* Drop VDD levels if we can. */
1127 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1128
1129 scalable[cpu].first_set_call = false;
1130 pr_debug("ACPU%d speed change complete\n", cpu);
1131
1132out:
1133 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1134 mutex_unlock(&driver_lock);
1135 return rc;
1136}
1137
1138/* Initialize a HFPLL at a given rate and enable it. */
1139static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1140{
1141 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1142
1143 /* Disable the PLL for re-programming. */
1144 hfpll_disable(sc);
1145
1146 /* Configure PLL parameters for integer mode. */
1147 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1148 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1149 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1150
1151 /* Program droop controller. */
1152 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1153
1154 /* Set an initial rate and enable the PLL. */
1155 hfpll_set_rate(sc, tgt_s);
1156 hfpll_enable(sc);
1157}
1158
1159/* Voltage regulator initialization. */
1160static void __init regulator_init(void)
1161{
1162 int cpu, ret;
1163 struct scalable *sc;
1164
1165 for_each_possible_cpu(cpu) {
1166 sc = &scalable[cpu];
1167 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1168 sc->vreg[VREG_CORE].name);
1169 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1170 pr_err("regulator_get(%s) failed (%ld)\n",
1171 sc->vreg[VREG_CORE].name,
1172 PTR_ERR(sc->vreg[VREG_CORE].reg));
1173 BUG();
1174 }
1175
1176 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
1177 sc->vreg[VREG_CORE].max_vdd,
1178 sc->vreg[VREG_CORE].max_vdd);
1179 if (ret)
1180 pr_err("regulator_set_voltage(%s) failed"
1181 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1182
1183 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1184 if (ret)
1185 pr_err("regulator_enable(%s) failed (%d)\n",
1186 sc->vreg[VREG_CORE].name, ret);
1187 }
1188}
1189
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001190/* Set initial rate for a given core. */
1191static void __init init_clock_sources(struct scalable *sc,
1192 struct core_speed *tgt_s)
1193{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001194 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001196 /* Select PLL8 as AUX source input to the secondary MUX. */
1197 writel_relaxed(0x3, sc->aux_clk_sel);
1198
1199 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001200 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001201 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001202 hfpll_init(sc, tgt_s);
1203
1204 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001205 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001207 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001208
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001209 /* Switch to the target clock source. */
1210 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001211 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1212 sc->current_speed = tgt_s;
1213
1214 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001215 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1216 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001217 */
1218 sc->first_set_call = true;
1219}
1220
Matt Wagantall8e726c72011-08-06 00:49:28 -07001221static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001222{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001223 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001224 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001225
1226 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1227 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001228}
1229
1230/* Register with bus driver. */
1231static void __init bus_init(void)
1232{
1233 int ret;
1234
1235 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1236 if (!bus_perf_client) {
1237 pr_err("unable to register bus client\n");
1238 BUG();
1239 }
1240
1241 ret = msm_bus_scale_client_update_request(bus_perf_client,
1242 (ARRAY_SIZE(bw_level_tbl)-1));
1243 if (ret)
1244 pr_err("initial bandwidth request failed (%d)\n", ret);
1245}
1246
1247#ifdef CONFIG_CPU_FREQ_MSM
1248static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1249
1250static void __init cpufreq_table_init(void)
1251{
1252 int cpu;
1253
1254 for_each_possible_cpu(cpu) {
1255 int i, freq_cnt = 0;
1256 /* Construct the freq_table tables from acpu_freq_tbl. */
1257 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1258 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1259 if (acpu_freq_tbl[i].use_for_scaling) {
1260 freq_table[cpu][freq_cnt].index = freq_cnt;
1261 freq_table[cpu][freq_cnt].frequency
1262 = acpu_freq_tbl[i].speed.khz;
1263 freq_cnt++;
1264 }
1265 }
1266 /* freq_table not big enough to store all usable freqs. */
1267 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1268
1269 freq_table[cpu][freq_cnt].index = freq_cnt;
1270 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1271
1272 pr_info("CPU%d: %d scaling frequencies supported.\n",
1273 cpu, freq_cnt);
1274
1275 /* Register table with CPUFreq. */
1276 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1277 }
1278}
1279#else
1280static void __init cpufreq_table_init(void) {}
1281#endif
1282
1283#define HOT_UNPLUG_KHZ STBY_KHZ
1284static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1285 unsigned long action, void *hcpu)
1286{
1287 static int prev_khz[NR_CPUS];
1288 static int prev_pri_src[NR_CPUS];
1289 static int prev_sec_src[NR_CPUS];
1290 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001291
1292 switch (action) {
1293 case CPU_DYING:
1294 case CPU_DYING_FROZEN:
1295 /*
Matt Wagantall27663842011-08-25 15:11:48 -07001296 * On Krait v1, the primary and secondary muxes must be set
1297 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001298 */
Matt Wagantall27663842011-08-25 15:11:48 -07001299 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001300 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1301 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1302 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1303 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1304 }
1305 break;
1306 case CPU_DEAD:
1307 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001308 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001309 /* Fall through. */
1310 case CPU_UP_CANCELED:
1311 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001312 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001313 break;
1314 case CPU_UP_PREPARE:
1315 case CPU_UP_PREPARE_FROZEN:
1316 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001317 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001318 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001319 break;
1320 case CPU_STARTING:
1321 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001322 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001323 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1324 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1325 }
1326 break;
1327 default:
1328 break;
1329 }
1330
1331 return NOTIFY_OK;
1332}
1333
1334static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1335 .notifier_call = acpuclock_cpu_callback,
1336};
1337
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001338static const int krait_needs_vmin(void)
1339{
1340 switch (read_cpuid_id()) {
1341 case 0x511F04D0:
1342 case 0x511F04D1:
1343 case 0x510F06F0:
1344 return 1;
1345 default:
1346 return 0;
1347 };
1348}
1349
Stephen Boydaefb8de2012-01-05 19:05:01 -08001350static void kraitv2_apply_vmin(struct acpu_level *tbl)
1351{
1352 for (; tbl->speed.khz != 0; tbl++)
1353 if (tbl->vdd_core < 1150000)
1354 tbl->vdd_core = 1150000;
1355}
1356
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001357static struct acpu_level * __init select_freq_plan(void)
1358{
1359 struct acpu_level *l, *max_acpu_level = NULL;
1360
1361 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001362 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001363 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001364 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001365
1366 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1367 pvs = (pte_efuse >> 10) & 0x7;
1368 if (pvs == 0x7)
1369 pvs = (pte_efuse >> 13) & 0x7;
1370
1371 switch (pvs) {
1372 case 0x0:
1373 case 0x7:
1374 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001375 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1376 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001377 break;
1378 case 0x1:
1379 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001380 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001381 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001382 break;
1383 case 0x3:
1384 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001385 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001386 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001387 break;
1388 default:
1389 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001390 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1391 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001392 break;
1393 }
1394
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001395 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001396 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001397 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001398 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1399 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1400 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001401 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001402 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1403 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1404 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001405 } else if (cpu_is_apq8064()) {
1406 scalable = scalable_8064;
1407 acpu_freq_tbl = acpu_freq_tbl_8064;
1408 l2_freq_tbl = l2_freq_tbl_8064;
1409 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001410 } else if (cpu_is_msm8627()) {
1411 scalable = scalable_8627;
1412 acpu_freq_tbl = acpu_freq_tbl_8627;
1413 l2_freq_tbl = l2_freq_tbl_8627;
1414 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001415 } else if (cpu_is_msm8930()) {
1416 scalable = scalable_8930;
1417 acpu_freq_tbl = acpu_freq_tbl_8930;
1418 l2_freq_tbl = l2_freq_tbl_8930;
1419 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001420 } else {
1421 BUG();
1422 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001423 if (krait_needs_vmin())
1424 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001425
1426 /* Find the max supported scaling frequency. */
1427 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1428 if (l->use_for_scaling)
1429 max_acpu_level = l;
1430 BUG_ON(!max_acpu_level);
1431 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1432
1433 return max_acpu_level;
1434}
1435
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001436static struct acpuclk_data acpuclk_8960_data = {
1437 .set_rate = acpuclk_8960_set_rate,
1438 .get_rate = acpuclk_8960_get_rate,
1439 .power_collapse_khz = STBY_KHZ,
1440 .wait_for_irq_khz = STBY_KHZ,
1441};
1442
Matt Wagantallec57f062011-08-16 23:54:46 -07001443static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001444{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001445 struct acpu_level *max_acpu_level = select_freq_plan();
1446 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1447 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001448
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001449 regulator_init();
1450 bus_init();
1451 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001452
1453 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001454 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001455
1456 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001457}
Matt Wagantallec57f062011-08-16 23:54:46 -07001458
1459struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1460 .init = acpuclk_8960_init,
1461};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001462
1463struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1464 .init = acpuclk_8960_init,
1465};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001466
1467struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1468 .init = acpuclk_8960_init,
1469};