blob: 1cc1499e2f6c00859ef3532808c8a7672d3fcb97 [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. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800737static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700738{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700739 int rc;
740
Matt Wagantallc1021762012-01-31 20:02:02 -0800741 if (!skip_regulators) {
742 if (cpu_is_msm8960()) {
743 rc = rpm_vreg_set_voltage(
744 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
745 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
746 2100000,
747 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
748 if (rc)
749 pr_err("%s regulator enable failed (%d)\n",
750 sc->vreg[VREG_HFPLL_A].name, rc);
751 }
752 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
753 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
754 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800755 if (rc)
756 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800757 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800758 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700759 /* Disable PLL bypass mode. */
760 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
761
762 /*
763 * H/W requires a 5us delay between disabling the bypass and
764 * de-asserting the reset. Delay 10us just to be safe.
765 */
766 mb();
767 udelay(10);
768
769 /* De-assert active-low PLL reset. */
770 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
771
772 /* Wait for PLL to lock. */
773 mb();
774 udelay(60);
775
776 /* Enable PLL output. */
777 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
778}
779
780/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800781static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700783 int rc;
784
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700785 /*
786 * Disable the PLL output, disable test mode, enable
787 * the bypass mode, and assert the reset.
788 */
789 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700790
Matt Wagantallc1021762012-01-31 20:02:02 -0800791 if (!skip_regulators) {
792 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
793 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800794 0, 0);
795 if (rc)
796 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800797 sc->vreg[VREG_HFPLL_B].name, rc);
798
799 if (cpu_is_msm8960()) {
800 rc = rpm_vreg_set_voltage(
801 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
802 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
803 0, 0, 0);
804 if (rc)
805 pr_err("%s regulator enable failed (%d)\n",
806 sc->vreg[VREG_HFPLL_A].name, rc);
807 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800808 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809}
810
811/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
812static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
813{
814 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
815}
816
817/* Return the L2 speed that should be applied. */
818static struct l2_level *compute_l2_level(struct scalable *sc,
819 struct l2_level *vote_l)
820{
821 struct l2_level *new_l;
822 int cpu;
823
824 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700825 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700826
827 /* Find max L2 speed vote. */
828 sc->l2_vote = vote_l;
829 new_l = l2_freq_tbl;
830 for_each_present_cpu(cpu)
831 new_l = max(new_l, scalable[cpu].l2_vote);
832
833 return new_l;
834}
835
836/* Update the bus bandwidth request. */
837static void set_bus_bw(unsigned int bw)
838{
839 int ret;
840
841 /* Bounds check. */
842 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
843 pr_err("invalid bandwidth request (%d)\n", bw);
844 return;
845 }
846
847 /* Update bandwidth if request has changed. This may sleep. */
848 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
849 if (ret)
850 pr_err("bandwidth request failed (%d)\n", ret);
851}
852
853/* Set the CPU or L2 clock speed. */
854static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
855 enum setrate_reason reason)
856{
857 struct core_speed *strt_s = sc->current_speed;
858
859 if (tgt_s == strt_s)
860 return;
861
862 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700864 * Move to an always-on source running at a frequency that does
865 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700867 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
869
870 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800871 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700872 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800873 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874
875 /* Move CPU to HFPLL source. */
876 set_pri_clk_src(sc, tgt_s->pri_src_sel);
877 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 /*
879 * If responding to CPU_DEAD we must be running on another
880 * CPU. Therefore, we can't access the downed CPU's CP15
881 * clock MUX registers from here and can't change clock sources.
882 * Just turn off the PLL- since the CPU is down already, halting
883 * its clock should be safe.
884 */
885 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
886 set_sec_clk_src(sc, tgt_s->sec_src_sel);
887 set_pri_clk_src(sc, tgt_s->pri_src_sel);
888 }
Matt Wagantallc1021762012-01-31 20:02:02 -0800889 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700890 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
891 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800892 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700893 /*
894 * If responding to CPU_UP_PREPARE, we can't change CP15
895 * registers for the CPU that's coming up since we're not
896 * running on that CPU. That's okay though, since the MUX
897 * source was not changed on the way down, either.
898 */
899 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
900 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
903 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700904 }
905
906 sc->current_speed = tgt_s;
907}
908
909/* Apply any per-cpu voltage increases. */
910static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
911 unsigned int vdd_dig, enum setrate_reason reason)
912{
913 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700914 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700915
916 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700917 * Increase vdd_mem active-set before vdd_dig.
918 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700919 */
920 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
921 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
922 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
923 sc->vreg[VREG_MEM].max_vdd, 0);
924 if (rc) {
925 pr_err("%s: vdd_mem (cpu%d) increase failed (%d)\n",
926 __func__, cpu, rc);
927 return rc;
928 }
929 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
930 }
931
932 /* Increase vdd_dig active-set vote. */
933 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
934 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
935 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
936 sc->vreg[VREG_DIG].max_vdd, 0);
937 if (rc) {
938 pr_err("%s: vdd_dig (cpu%d) increase failed (%d)\n",
939 __func__, cpu, rc);
940 return rc;
941 }
942 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
943 }
944
945 /*
946 * Update per-CPU core voltage. Don't do this for the hotplug path for
947 * which it should already be correct. Attempting to set it is bad
948 * because we don't know what CPU we are running on at this point, but
949 * the CPU regulator API requires we call it from the affected CPU.
950 */
951 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
952 && reason != SETRATE_HOTPLUG) {
953 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
954 sc->vreg[VREG_CORE].max_vdd);
955 if (rc) {
956 pr_err("%s: vdd_core (cpu%d) increase failed (%d)\n",
957 __func__, cpu, rc);
958 return rc;
959 }
960 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
961 }
962
963 return rc;
964}
965
966/* Apply any per-cpu voltage decreases. */
967static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
968 unsigned int vdd_dig, enum setrate_reason reason)
969{
970 struct scalable *sc = &scalable[cpu];
971 int ret;
972
973 /*
974 * Update per-CPU core voltage. This must be called on the CPU
975 * that's being affected. Don't do this in the hotplug remove path,
976 * where the rail is off and we're executing on the other CPU.
977 */
978 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
979 && reason != SETRATE_HOTPLUG) {
980 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
981 sc->vreg[VREG_CORE].max_vdd);
982 if (ret) {
983 pr_err("%s: vdd_core (cpu%d) decrease failed (%d)\n",
984 __func__, cpu, ret);
985 return;
986 }
987 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
988 }
989
990 /* Decrease vdd_dig active-set vote. */
991 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
992 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
993 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
994 sc->vreg[VREG_DIG].max_vdd, 0);
995 if (ret) {
996 pr_err("%s: vdd_dig (cpu%d) decrease failed (%d)\n",
997 __func__, cpu, ret);
998 return;
999 }
1000 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1001 }
1002
1003 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001004 * Decrease vdd_mem active-set after vdd_dig.
1005 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001006 */
1007 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1008 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1009 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1010 sc->vreg[VREG_MEM].max_vdd, 0);
1011 if (ret) {
1012 pr_err("%s: vdd_mem (cpu%d) decrease failed (%d)\n",
1013 __func__, cpu, ret);
1014 return;
1015 }
1016 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1017 }
1018}
1019
1020static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1021{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001022 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001023}
1024
1025static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1026{
1027 unsigned int pll_vdd_dig;
1028
Stephen Boydc76158f2011-12-08 12:42:40 -08001029 if (tgt->l2_level->speed.src != HFPLL)
1030 pll_vdd_dig = 0;
1031 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001032 pll_vdd_dig = HFPLL_NOMINAL_VDD;
Tianyi Goufff00402012-01-23 14:36:20 -08001033 else {
1034 if (cpu_is_msm8960())
1035 pll_vdd_dig = HFPLL_LOW_VDD_8960;
1036 else
1037 pll_vdd_dig = HFPLL_LOW_VDD;
1038 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1040}
1041
1042static unsigned int calculate_vdd_core(struct acpu_level *tgt)
1043{
1044 unsigned int pll_vdd_core;
1045
Stephen Boydc76158f2011-12-08 12:42:40 -08001046 if (tgt->speed.src != HFPLL)
1047 pll_vdd_core = 0;
1048 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001049 pll_vdd_core = HFPLL_NOMINAL_VDD;
Tianyi Goufff00402012-01-23 14:36:20 -08001050 else {
1051 if (cpu_is_msm8960())
1052 pll_vdd_core = HFPLL_LOW_VDD_8960;
1053 else
1054 pll_vdd_core = HFPLL_LOW_VDD;
1055 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001056 return max(tgt->vdd_core, pll_vdd_core);
1057}
1058
1059/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001060static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1061 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001062{
1063 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1064 struct l2_level *tgt_l2_l;
1065 struct acpu_level *tgt;
1066 unsigned int vdd_mem, vdd_dig, vdd_core;
1067 unsigned long flags;
1068 int rc = 0;
1069
1070 if (cpu > num_possible_cpus()) {
1071 rc = -EINVAL;
1072 goto out;
1073 }
1074
1075 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1076 mutex_lock(&driver_lock);
1077
1078 strt_acpu_s = scalable[cpu].current_speed;
1079
1080 /* Return early if rate didn't change. */
1081 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1082 goto out;
1083
1084 /* Find target frequency. */
1085 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1086 if (tgt->speed.khz == rate) {
1087 tgt_acpu_s = &tgt->speed;
1088 break;
1089 }
1090 }
1091 if (tgt->speed.khz == 0) {
1092 rc = -EINVAL;
1093 goto out;
1094 }
1095
1096 /* Calculate voltage requirements for the current CPU. */
1097 vdd_mem = calculate_vdd_mem(tgt);
1098 vdd_dig = calculate_vdd_dig(tgt);
1099 vdd_core = calculate_vdd_core(tgt);
1100
1101 /* Increase VDD levels if needed. */
1102 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1103 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1104 if (rc)
1105 goto out;
1106 }
1107
1108 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1109 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1110
1111 /* Set the CPU speed. */
1112 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1113
1114 /*
1115 * Update the L2 vote and apply the rate change. A spinlock is
1116 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001117 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001118 * and the driver_lock mutex is not acquired.
1119 */
1120 spin_lock_irqsave(&l2_lock, flags);
1121 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1122 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1123 spin_unlock_irqrestore(&l2_lock, flags);
1124
1125 /* Nothing else to do for power collapse or SWFI. */
1126 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1127 goto out;
1128
1129 /* Update bus bandwith request. */
1130 set_bus_bw(tgt_l2_l->bw_level);
1131
1132 /* Drop VDD levels if we can. */
1133 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1134
1135 scalable[cpu].first_set_call = false;
1136 pr_debug("ACPU%d speed change complete\n", cpu);
1137
1138out:
1139 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1140 mutex_unlock(&driver_lock);
1141 return rc;
1142}
1143
1144/* Initialize a HFPLL at a given rate and enable it. */
1145static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1146{
1147 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1148
1149 /* Disable the PLL for re-programming. */
Matt Wagantallc1021762012-01-31 20:02:02 -08001150 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001151
1152 /* Configure PLL parameters for integer mode. */
1153 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1154 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1155 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1156
1157 /* Program droop controller. */
1158 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1159
1160 /* Set an initial rate and enable the PLL. */
1161 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001162 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001163}
1164
1165/* Voltage regulator initialization. */
1166static void __init regulator_init(void)
1167{
1168 int cpu, ret;
1169 struct scalable *sc;
1170
1171 for_each_possible_cpu(cpu) {
1172 sc = &scalable[cpu];
1173 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1174 sc->vreg[VREG_CORE].name);
1175 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1176 pr_err("regulator_get(%s) failed (%ld)\n",
1177 sc->vreg[VREG_CORE].name,
1178 PTR_ERR(sc->vreg[VREG_CORE].reg));
1179 BUG();
1180 }
1181
1182 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
1183 sc->vreg[VREG_CORE].max_vdd,
1184 sc->vreg[VREG_CORE].max_vdd);
1185 if (ret)
1186 pr_err("regulator_set_voltage(%s) failed"
1187 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1188
1189 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1190 if (ret)
1191 pr_err("regulator_enable(%s) failed (%d)\n",
1192 sc->vreg[VREG_CORE].name, ret);
1193 }
1194}
1195
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001196/* Set initial rate for a given core. */
1197static void __init init_clock_sources(struct scalable *sc,
1198 struct core_speed *tgt_s)
1199{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001200 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001201
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001202 /* Select PLL8 as AUX source input to the secondary MUX. */
1203 writel_relaxed(0x3, sc->aux_clk_sel);
1204
1205 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001206 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001207 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001208 hfpll_init(sc, tgt_s);
1209
1210 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001211 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001212 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001213 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001214
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001215 /* Switch to the target clock source. */
1216 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001217 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1218 sc->current_speed = tgt_s;
1219
1220 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001221 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1222 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001223 */
1224 sc->first_set_call = true;
1225}
1226
Matt Wagantall8e726c72011-08-06 00:49:28 -07001227static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001228{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001229 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001230 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001231
1232 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1233 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001234}
1235
1236/* Register with bus driver. */
1237static void __init bus_init(void)
1238{
1239 int ret;
1240
1241 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1242 if (!bus_perf_client) {
1243 pr_err("unable to register bus client\n");
1244 BUG();
1245 }
1246
1247 ret = msm_bus_scale_client_update_request(bus_perf_client,
1248 (ARRAY_SIZE(bw_level_tbl)-1));
1249 if (ret)
1250 pr_err("initial bandwidth request failed (%d)\n", ret);
1251}
1252
1253#ifdef CONFIG_CPU_FREQ_MSM
1254static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1255
1256static void __init cpufreq_table_init(void)
1257{
1258 int cpu;
1259
1260 for_each_possible_cpu(cpu) {
1261 int i, freq_cnt = 0;
1262 /* Construct the freq_table tables from acpu_freq_tbl. */
1263 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1264 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1265 if (acpu_freq_tbl[i].use_for_scaling) {
1266 freq_table[cpu][freq_cnt].index = freq_cnt;
1267 freq_table[cpu][freq_cnt].frequency
1268 = acpu_freq_tbl[i].speed.khz;
1269 freq_cnt++;
1270 }
1271 }
1272 /* freq_table not big enough to store all usable freqs. */
1273 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1274
1275 freq_table[cpu][freq_cnt].index = freq_cnt;
1276 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1277
1278 pr_info("CPU%d: %d scaling frequencies supported.\n",
1279 cpu, freq_cnt);
1280
1281 /* Register table with CPUFreq. */
1282 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1283 }
1284}
1285#else
1286static void __init cpufreq_table_init(void) {}
1287#endif
1288
1289#define HOT_UNPLUG_KHZ STBY_KHZ
1290static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1291 unsigned long action, void *hcpu)
1292{
1293 static int prev_khz[NR_CPUS];
1294 static int prev_pri_src[NR_CPUS];
1295 static int prev_sec_src[NR_CPUS];
1296 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001297
1298 switch (action) {
1299 case CPU_DYING:
1300 case CPU_DYING_FROZEN:
1301 /*
Matt Wagantall27663842011-08-25 15:11:48 -07001302 * On Krait v1, the primary and secondary muxes must be set
1303 * to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001304 */
Matt Wagantall27663842011-08-25 15:11:48 -07001305 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001306 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1307 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1308 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1309 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1310 }
1311 break;
1312 case CPU_DEAD:
1313 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001314 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001315 /* Fall through. */
1316 case CPU_UP_CANCELED:
1317 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001318 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001319 break;
1320 case CPU_UP_PREPARE:
1321 case CPU_UP_PREPARE_FROZEN:
1322 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001323 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001324 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001325 break;
1326 case CPU_STARTING:
1327 case CPU_STARTING_FROZEN:
Matt Wagantall27663842011-08-25 15:11:48 -07001328 if (cpu_is_krait_v1()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001329 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1330 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1331 }
1332 break;
1333 default:
1334 break;
1335 }
1336
1337 return NOTIFY_OK;
1338}
1339
1340static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1341 .notifier_call = acpuclock_cpu_callback,
1342};
1343
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001344static const int krait_needs_vmin(void)
1345{
1346 switch (read_cpuid_id()) {
1347 case 0x511F04D0:
1348 case 0x511F04D1:
1349 case 0x510F06F0:
1350 return 1;
1351 default:
1352 return 0;
1353 };
1354}
1355
Stephen Boydaefb8de2012-01-05 19:05:01 -08001356static void kraitv2_apply_vmin(struct acpu_level *tbl)
1357{
1358 for (; tbl->speed.khz != 0; tbl++)
1359 if (tbl->vdd_core < 1150000)
1360 tbl->vdd_core = 1150000;
1361}
1362
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001363static struct acpu_level * __init select_freq_plan(void)
1364{
1365 struct acpu_level *l, *max_acpu_level = NULL;
1366
1367 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001368 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001369 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001370 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001371
1372 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1373 pvs = (pte_efuse >> 10) & 0x7;
1374 if (pvs == 0x7)
1375 pvs = (pte_efuse >> 13) & 0x7;
1376
1377 switch (pvs) {
1378 case 0x0:
1379 case 0x7:
1380 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001381 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1382 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001383 break;
1384 case 0x1:
1385 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001386 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001387 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001388 break;
1389 case 0x3:
1390 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001391 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001392 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001393 break;
1394 default:
1395 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001396 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1397 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001398 break;
1399 }
1400
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001401 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001402 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001403 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001404 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1405 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1406 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001407 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001408 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1409 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1410 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001411 } else if (cpu_is_apq8064()) {
1412 scalable = scalable_8064;
1413 acpu_freq_tbl = acpu_freq_tbl_8064;
1414 l2_freq_tbl = l2_freq_tbl_8064;
1415 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001416 } else if (cpu_is_msm8627()) {
1417 scalable = scalable_8627;
1418 acpu_freq_tbl = acpu_freq_tbl_8627;
1419 l2_freq_tbl = l2_freq_tbl_8627;
1420 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001421 } else if (cpu_is_msm8930()) {
1422 scalable = scalable_8930;
1423 acpu_freq_tbl = acpu_freq_tbl_8930;
1424 l2_freq_tbl = l2_freq_tbl_8930;
1425 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001426 } else {
1427 BUG();
1428 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001429 if (krait_needs_vmin())
1430 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001431
1432 /* Find the max supported scaling frequency. */
1433 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1434 if (l->use_for_scaling)
1435 max_acpu_level = l;
1436 BUG_ON(!max_acpu_level);
1437 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1438
1439 return max_acpu_level;
1440}
1441
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001442static struct acpuclk_data acpuclk_8960_data = {
1443 .set_rate = acpuclk_8960_set_rate,
1444 .get_rate = acpuclk_8960_get_rate,
1445 .power_collapse_khz = STBY_KHZ,
1446 .wait_for_irq_khz = STBY_KHZ,
1447};
1448
Matt Wagantallec57f062011-08-16 23:54:46 -07001449static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001450{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001451 struct acpu_level *max_acpu_level = select_freq_plan();
1452 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1453 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001454
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001455 regulator_init();
1456 bus_init();
1457 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001458
1459 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001460 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001461
1462 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001463}
Matt Wagantallec57f062011-08-16 23:54:46 -07001464
1465struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1466 .init = acpuclk_8960_init,
1467};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001468
1469struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1470 .init = acpuclk_8960_init,
1471};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001472
1473struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1474 .init = acpuclk_8960_init,
1475};