blob: d29fee61f51ac99552be9b09b94d9b0fc17203d7 [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>
Matt Wagantallbf430eb2012-03-22 11:45:49 -070016#include <linux/module.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017#include <linux/init.h>
18#include <linux/io.h>
19#include <linux/delay.h>
20#include <linux/mutex.h>
21#include <linux/err.h>
22#include <linux/errno.h>
23#include <linux/cpufreq.h>
24#include <linux/cpu.h>
25#include <linux/regulator/consumer.h>
Matt Wagantallbf430eb2012-03-22 11:45:49 -070026#include <linux/platform_device.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027
28#include <asm/mach-types.h>
29#include <asm/cpu.h>
30
31#include <mach/board.h>
32#include <mach/msm_iomap.h>
33#include <mach/rpm-regulator.h>
34#include <mach/msm_bus.h>
35#include <mach/msm_bus_board.h>
36#include <mach/socinfo.h>
Stephen Boyd469ed3e2011-09-29 16:41:19 -070037#include <mach/msm-krait-l2-accessors.h>
Matt Wagantallcb12c392011-10-19 10:32:07 -070038#include <mach/rpm-regulator.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039
40#include "acpuclock.h"
Matt Wagantall34c2d962012-02-01 14:30:02 -080041#include "pm.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43/*
44 * Source IDs.
45 * These must be negative to not overlap with the source IDs
46 * used by the 8x60 local clock driver.
47 */
48#define PLL_8 0
49#define HFPLL -1
50#define QSB -2
51
52/* Mux source selects. */
53#define PRI_SRC_SEL_SEC_SRC 0
54#define PRI_SRC_SEL_HFPLL 1
55#define PRI_SRC_SEL_HFPLL_DIV2 2
56#define SEC_SRC_SEL_QSB 0
Matt Wagantall65e5e4b2011-10-27 16:52:10 -070057#define SEC_SRC_SEL_AUX 2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058
59/* HFPLL registers offsets. */
60#define HFPLL_MODE 0x00
61#define HFPLL_CONFIG_CTL 0x04
62#define HFPLL_L_VAL 0x08
63#define HFPLL_M_VAL 0x0C
64#define HFPLL_N_VAL 0x10
65#define HFPLL_DROOP_CTL 0x14
66
67/* CP15 L2 indirect addresses. */
68#define L2CPMR_IADDR 0x500
69#define L2CPUCPMR_IADDR 0x501
70
71#define STBY_KHZ 1
72
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
Tianyi Gou50705682012-02-21 17:51:50 -080080/* Corner type vreg VDD values */
81#define LVL_NONE RPM_VREG_CORNER_NONE
82#define LVL_LOW RPM_VREG_CORNER_LOW
83#define LVL_NOM RPM_VREG_CORNER_NOMINAL
84#define LVL_HIGH RPM_VREG_CORNER_HIGH
85
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086enum scalables {
87 CPU0 = 0,
88 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070089 CPU2,
90 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091 L2,
92 NUM_SCALABLES
93};
94
95enum vregs {
96 VREG_CORE,
97 VREG_MEM,
98 VREG_DIG,
Matt Wagantallcb12c392011-10-19 10:32:07 -070099 VREG_HFPLL_A,
100 VREG_HFPLL_B,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700101 NUM_VREG
102};
103
Tianyi Gou50705682012-02-21 17:51:50 -0800104enum hfpll_vdd_levels {
105 HFPLL_VDD_NONE,
106 HFPLL_VDD_LOW,
107 HFPLL_VDD_NOM
108};
109
Tianyi Goudff51062012-06-04 20:22:23 -0700110enum pvs {
111 PVS_SLOW,
112 PVS_NOM,
113 PVS_FAST,
114 PVS_FASTER,
115 NUM_PVS
116};
117
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118struct vreg {
119 const char name[15];
120 const unsigned int max_vdd;
121 const int rpm_vreg_voter;
122 const int rpm_vreg_id;
123 struct regulator *reg;
124 unsigned int cur_vdd;
125};
126
127struct core_speed {
128 unsigned int khz;
129 int src;
130 unsigned int pri_src_sel;
131 unsigned int sec_src_sel;
132 unsigned int pll_l_val;
133};
134
135struct l2_level {
136 struct core_speed speed;
137 unsigned int vdd_dig;
138 unsigned int vdd_mem;
139 unsigned int bw_level;
140};
141
142struct acpu_level {
143 unsigned int use_for_scaling;
144 struct core_speed speed;
145 struct l2_level *l2_level;
146 unsigned int vdd_core;
147};
148
149struct scalable {
150 void * __iomem const hfpll_base;
151 void * __iomem const aux_clk_sel;
152 const uint32_t l2cpmr_iaddr;
153 struct core_speed *current_speed;
154 struct l2_level *l2_vote;
155 struct vreg vreg[NUM_VREG];
Tianyi Gou50705682012-02-21 17:51:50 -0800156 unsigned int *hfpll_vdd_tbl;
157};
158
159static unsigned int hfpll_vdd_tbl_8960[] = {
160 [HFPLL_VDD_NONE] = 0,
161 [HFPLL_VDD_LOW] = 850000,
162 [HFPLL_VDD_NOM] = 1050000
163};
164
165static unsigned int hfpll_vdd_tbl_8064[] = {
166 [HFPLL_VDD_NONE] = 0,
167 [HFPLL_VDD_LOW] = 945000,
168 [HFPLL_VDD_NOM] = 1050000
169};
170
171static unsigned int hfpll_vdd_dig_tbl_8930[] = {
172 [HFPLL_VDD_NONE] = LVL_NONE,
173 [HFPLL_VDD_LOW] = LVL_LOW,
174 [HFPLL_VDD_NOM] = LVL_NOM
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175};
176
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700177static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178 [CPU0] = {
179 .hfpll_base = MSM_HFPLL_BASE + 0x200,
180 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
181 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800182 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
184 RPM_VREG_VOTER1,
185 RPM_VREG_ID_PM8921_L24 },
186 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
187 RPM_VREG_VOTER1,
188 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800189 .vreg[VREG_HFPLL_A] = { "hfpll0_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700190 RPM_VREG_VOTER1,
191 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800192 .vreg[VREG_HFPLL_B] = { "hfpll0_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700193 RPM_VREG_VOTER1,
194 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195 },
196 [CPU1] = {
197 .hfpll_base = MSM_HFPLL_BASE + 0x300,
198 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
199 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800200 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800201 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202 RPM_VREG_VOTER2,
203 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800204 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205 RPM_VREG_VOTER2,
206 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800207 .vreg[VREG_HFPLL_A] = { "hfpll1_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700208 RPM_VREG_VOTER2,
209 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800210 .vreg[VREG_HFPLL_B] = { "hfpll1_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700211 RPM_VREG_VOTER2,
212 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700213 },
214 [L2] = {
215 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800216 .hfpll_vdd_tbl = hfpll_vdd_tbl_8960,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
218 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800219 .vreg[VREG_HFPLL_A] = { "hfpll_l2_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700220 RPM_VREG_VOTER6,
221 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800222 .vreg[VREG_HFPLL_B] = { "hfpll_l2_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700223 RPM_VREG_VOTER6,
224 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700225 },
226};
227
Stephen Boyd7ad84752011-08-05 14:04:28 -0700228static DEFINE_MUTEX(driver_lock);
229static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700231static struct scalable scalable_8064[] = {
232 [CPU0] = {
233 .hfpll_base = MSM_HFPLL_BASE + 0x200,
234 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
235 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800236 .vreg[VREG_CORE] = { "krait0", 1300000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700237 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
238 RPM_VREG_VOTER1,
239 RPM_VREG_ID_PM8921_L24 },
240 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
241 RPM_VREG_VOTER1,
242 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800243 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800244 RPM_VREG_VOTER1,
245 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700246 },
247 [CPU1] = {
248 .hfpll_base = MSM_HFPLL_BASE + 0x240,
249 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
250 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800251 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800252 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700253 RPM_VREG_VOTER2,
254 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800255 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700256 RPM_VREG_VOTER2,
257 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800258 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800259 RPM_VREG_VOTER2,
260 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700261 },
262 [CPU2] = {
263 .hfpll_base = MSM_HFPLL_BASE + 0x280,
264 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
265 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800266 .vreg[VREG_CORE] = { "krait2", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800267 .vreg[VREG_MEM] = { "krait2_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700268 RPM_VREG_VOTER4,
269 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800270 .vreg[VREG_DIG] = { "krait2_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700271 RPM_VREG_VOTER4,
272 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800273 .vreg[VREG_HFPLL_B] = { "hfpll2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800274 RPM_VREG_VOTER4,
275 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700276 },
277 [CPU3] = {
278 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
279 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
280 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800281 .vreg[VREG_CORE] = { "krait3", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800282 .vreg[VREG_MEM] = { "krait3_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700283 RPM_VREG_VOTER5,
284 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800285 .vreg[VREG_DIG] = { "krait3_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700286 RPM_VREG_VOTER5,
287 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800288 .vreg[VREG_HFPLL_B] = { "hfpll3", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800289 RPM_VREG_VOTER5,
290 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700291 },
292 [L2] = {
293 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800294 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700295 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
296 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800297 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800298 RPM_VREG_VOTER6,
299 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700300 },
301};
302
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800303static struct scalable scalable_8930[] = {
304 [CPU0] = {
305 .hfpll_base = MSM_HFPLL_BASE + 0x200,
306 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
307 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
308 .vreg[VREG_CORE] = { "krait0", 1300000 },
309 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
310 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800311 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800312 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800313 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800314 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
315 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800316 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800317 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800318 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800319 },
320 [CPU1] = {
321 .hfpll_base = MSM_HFPLL_BASE + 0x300,
322 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
323 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
324 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800325 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800326 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800327 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800328 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800329 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800330 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
331 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800332 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800333 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800334 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800335 },
336 [L2] = {
337 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800338 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800339 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
340 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800341 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800342 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800343 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800344 },
345};
346
Tianyi Goue0b34de2011-12-20 11:20:10 -0800347/*TODO: Update the rpm vreg id when the rpm driver is ready */
348static struct scalable scalable_8627[] = {
349 [CPU0] = {
350 .hfpll_base = MSM_HFPLL_BASE + 0x200,
351 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
352 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
353 .vreg[VREG_CORE] = { "krait0", 1300000 },
354 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
355 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800356 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800357 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800358 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800359 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
360 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800361 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800362 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800363 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800364 },
365 [CPU1] = {
366 .hfpll_base = MSM_HFPLL_BASE + 0x300,
367 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
368 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
369 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800370 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800371 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800372 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800373 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800374 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800375 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
376 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800377 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800378 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800379 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800380 },
381 [L2] = {
382 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou73712ed2012-05-23 12:18:29 -0700383 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800384 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
385 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800386 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800387 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800388 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800389 },
390};
391
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700392static struct l2_level *l2_freq_tbl;
393static struct acpu_level *acpu_freq_tbl;
394static int l2_freq_tbl_size;
Matt Wagantall34c2d962012-02-01 14:30:02 -0800395static struct scalable *scalable;
396#define SCALABLE_TO_CPU(sc) ((sc) - scalable)
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700397
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700398/* Instantaneous bandwidth requests in MB/s. */
399#define BW_MBPS(_bw) \
400 { \
401 .vectors = (struct msm_bus_vectors[]){ \
402 {\
403 .src = MSM_BUS_MASTER_AMPSS_M0, \
404 .dst = MSM_BUS_SLAVE_EBI_CH0, \
405 .ib = (_bw) * 1000000UL, \
406 .ab = (_bw) * 100000UL, \
407 }, \
408 { \
409 .src = MSM_BUS_MASTER_AMPSS_M1, \
410 .dst = MSM_BUS_SLAVE_EBI_CH0, \
411 .ib = (_bw) * 1000000UL, \
412 .ab = (_bw) * 100000UL, \
413 }, \
414 }, \
415 .num_paths = 2, \
416 }
417static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800418 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
419 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
420 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
421 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
422 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
423 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
424 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800425 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426};
427
428static struct msm_bus_scale_pdata bus_client_pdata = {
429 .usecase = bw_level_tbl,
430 .num_usecases = ARRAY_SIZE(bw_level_tbl),
431 .active_only = 1,
432 .name = "acpuclock",
433};
434
435static uint32_t bus_perf_client;
436
437/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800438#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
439static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700440 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700441 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700442 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
443 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
444 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
445 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
446 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
447 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700448 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700449 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
450 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
451 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700452};
453
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800454static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
455 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
456 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
457 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
458 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
459 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
460 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
461 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
462 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
463 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
464 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
465 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
466 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
467 { 0, { 0 } }
468};
469
470static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
471 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
472 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
473 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
474 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
475 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
476 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
477 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
478 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
479 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
480 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
481 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
482 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483 { 0, { 0 } }
484};
485
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800486#undef L2
487#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
488static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
489 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
490 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800491 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
492 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
493 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800494 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800495 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
496 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
497 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
498 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
499 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
500 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
501 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
502 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
503 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
504 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
505 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800506 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
507 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
508 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800509};
510
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800511static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800512 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
513 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800514 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
515 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
516 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
517 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
518 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
519 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
520 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
521 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
522 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
523 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
524 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
525 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
Stephen Boydb2e41d02012-06-01 11:21:13 -0700526 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(19), 1175000 },
527 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(19), 1175000 },
528 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(19), 1200000 },
529 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1200000 },
530 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1225000 },
531 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1225000 },
532 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1237500 },
533 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1237500 },
534 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800535 { 0, { 0 } }
536};
537
538static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800539 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
540 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800541 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
542 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
543 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
544 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
545 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
546 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
547 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
548 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
549 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
550 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
551 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
552 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
Stephen Boydb2e41d02012-06-01 11:21:13 -0700553 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(19), 1125000 },
554 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(19), 1125000 },
555 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(19), 1150000 },
556 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1150000 },
557 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1175000 },
558 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1175000 },
559 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1187500 },
560 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1187500 },
561 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800562 { 0, { 0 } }
563};
564
Stephen Boyd5766f682011-12-27 19:21:08 -0800565static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800566 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
567 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800568 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
569 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
570 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
571 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
572 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
573 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
574 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
575 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
576 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
577 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
578 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
579 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
Stephen Boydb2e41d02012-06-01 11:21:13 -0700580 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(19), 1075000 },
581 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(19), 1075000 },
582 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(19), 1100000 },
583 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1100000 },
584 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1125000 },
585 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1125000 },
586 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1137500 },
587 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1137500 },
588 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800589 { 0, { 0 } }
590};
591
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700592/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
593#undef L2
594#define L2(x) (&l2_freq_tbl_8064[(x)])
595static struct l2_level l2_freq_tbl_8064[] = {
596 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800597 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
598 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
599 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
600 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700601 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800602 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
603 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
604 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
605 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
606 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
607 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
608 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
609 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
610 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
611 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700612};
613
614/* TODO: Update core voltages when data is available. */
Tianyi Goudff51062012-06-04 20:22:23 -0700615static struct acpu_level acpu_freq_tbl_8064_slow[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800616 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
617 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
618 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
619 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
620 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
621 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
622 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
623 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
624 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
625 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
626 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
627 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
628 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
629 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
630 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
631 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
632 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
633 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
634 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
635 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
636 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
637 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
638 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700639 { 0, { 0 } }
640};
641
Tianyi Goudff51062012-06-04 20:22:23 -0700642static struct acpu_level acpu_freq_tbl_8064_nom[] = {
643 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
644 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
645 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
646 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
647 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
648 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
649 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
650 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
651 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
652 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
653 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
654 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
655 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
656 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
657 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1125000 },
658 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1125000 },
659 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1150000 },
660 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1150000 },
661 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1175000 },
662 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1175000 },
663 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1187500 },
664 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1187500 },
Tianyi Gouc519b722012-06-13 16:37:36 -0700665 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1200000 },
Tianyi Goudff51062012-06-04 20:22:23 -0700666 { 0, { 0 } }
667};
668
669static struct acpu_level acpu_freq_tbl_8064_fast[] = {
670 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
671 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
672 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
673 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
674 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
675 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
676 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
677 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
678 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
679 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
680 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
681 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
682 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
683 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
684 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1075000 },
685 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1075000 },
686 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1100000 },
687 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1100000 },
688 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1125000 },
689 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1125000 },
690 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1137500 },
691 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1137500 },
Tianyi Gouc519b722012-06-13 16:37:36 -0700692 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1150000 },
Tianyi Goudff51062012-06-04 20:22:23 -0700693 { 0, { 0 } }
694};
695
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800696/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
697#undef L2
698#define L2(x) (&l2_freq_tbl_8930[(x)])
699static struct l2_level l2_freq_tbl_8930[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800700 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
701 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800702 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 2 },
703 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 2 },
704 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
Tianyi Gou50705682012-02-21 17:51:50 -0800705 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800706 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 4 },
707 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 4 },
708 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 4 },
709 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 4 },
710 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
711 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 7 },
712 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 7 },
713 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, LVL_HIGH, 1150000, 7 },
714 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, LVL_HIGH, 1150000, 7 },
715 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, LVL_HIGH, 1150000, 7 },
716 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, LVL_HIGH, 1150000, 7 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800717};
718
719/* TODO: Update core voltages when data is available. */
Tianyi Gou64307be2012-06-06 14:25:25 -0700720static struct acpu_level acpu_freq_tbl_8930_slow[] = {
721 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
722 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
723 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 975000 },
724 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 975000 },
725 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 1000000 },
Tianyi Goud911dd12012-05-10 21:06:40 -0700726 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
727 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
Tianyi Gou64307be2012-06-06 14:25:25 -0700728 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1025000 },
729 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1075000 },
730 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1075000 },
Tianyi Goud911dd12012-05-10 21:06:40 -0700731 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
Tianyi Gou64307be2012-06-06 14:25:25 -0700732 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1100000 },
733 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(11), 1125000 },
734 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(11), 1125000 },
735 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
736 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
737 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
738 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
739 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
740 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
741 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800742 { 0, { 0 } }
743};
744
Tianyi Gou64307be2012-06-06 14:25:25 -0700745static struct acpu_level acpu_freq_tbl_8930_nom[] = {
746 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 925000 },
747 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 925000 },
748 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 950000 },
749 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 950000 },
750 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 975000 },
751 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 975000 },
752 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1000000 },
753 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
754 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1050000 },
755 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1050000 },
756 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1075000 },
757 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1075000 },
758 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(11), 1100000 },
759 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(11), 1100000 },
760 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1150000 },
761 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1150000 },
762 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1175000 },
763 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1175000 },
764 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1200000 },
765 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1200000 },
766 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1212500 },
767 { 0, { 0 } }
768};
769
770static struct acpu_level acpu_freq_tbl_8930_fast[] = {
771 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
772 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
773 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 900000 },
774 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 900000 },
775 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 925000 },
776 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
777 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 950000 },
778 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 950000 },
779 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1000000 },
780 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1000000 },
781 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
782 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
783 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(11), 1050000 },
784 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(11), 1050000 },
785 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
786 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
787 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
788 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1125000 },
789 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1150000 },
790 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1150000 },
791 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1162500 },
792 { 0, { 0 } }
793};
Tianyi Goue0b34de2011-12-20 11:20:10 -0800794/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
795#undef L2
796#define L2(x) (&l2_freq_tbl_8627[(x)])
797static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800798 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
799 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
800 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
801 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
802 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
803 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
804 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
805 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
806 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
807 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
808 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
809 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
810 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800811};
812
813/* TODO: Update core voltages when data is available. */
814static struct acpu_level acpu_freq_tbl_8627[] = {
815 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
816 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
817 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
818 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
819 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
820 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
821 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
822 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
823 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
824 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
825 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
826 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
827 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
828 { 0, { 0 } }
829};
830
Tianyi Goudff51062012-06-04 20:22:23 -0700831static struct acpu_level *acpu_freq_tbl_8960_v1[NUM_PVS] __initdata = {
832 [PVS_SLOW] = acpu_freq_tbl_8960_kraitv1_slow,
833 [PVS_NOM] = acpu_freq_tbl_8960_kraitv1_nom_fast,
834 [PVS_FAST] = acpu_freq_tbl_8960_kraitv1_nom_fast,
835};
836
837static struct acpu_level *acpu_freq_tbl_8960_v2[NUM_PVS] __initdata = {
838 [PVS_SLOW] = acpu_freq_tbl_8960_kraitv2_slow,
839 [PVS_NOM] = acpu_freq_tbl_8960_kraitv2_nom,
840 [PVS_FAST] = acpu_freq_tbl_8960_kraitv2_fast,
841};
842
843/* TODO: update the faster table when data is available */
844static struct acpu_level *acpu_freq_tbl_8064[NUM_PVS] __initdata = {
845 [PVS_SLOW] = acpu_freq_tbl_8064_slow,
846 [PVS_NOM] = acpu_freq_tbl_8064_nom,
847 [PVS_FAST] = acpu_freq_tbl_8064_fast,
848 [PVS_FASTER] = acpu_freq_tbl_8064_fast,
849};
850
Tianyi Gou64307be2012-06-06 14:25:25 -0700851static struct acpu_level *acpu_freq_tbl_8930_pvs[NUM_PVS] __initdata = {
852 [PVS_SLOW] = acpu_freq_tbl_8930_slow,
853 [PVS_NOM] = acpu_freq_tbl_8930_nom,
854 [PVS_FAST] = acpu_freq_tbl_8930_fast,
855};
856
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700857static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700858{
859 return scalable[cpu].current_speed->khz;
860}
861
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862/* Get the selected source on primary MUX. */
863static int get_pri_clk_src(struct scalable *sc)
864{
865 uint32_t regval;
866
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700867 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 return regval & 0x3;
869}
870
871/* Set the selected source on primary MUX. */
872static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
873{
874 uint32_t regval;
875
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700876 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700877 regval &= ~0x3;
878 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700879 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880 /* Wait for switch to complete. */
881 mb();
882 udelay(1);
883}
884
885/* Get the selected source on secondary MUX. */
886static int get_sec_clk_src(struct scalable *sc)
887{
888 uint32_t regval;
889
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700890 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 return (regval >> 2) & 0x3;
892}
893
894/* Set the selected source on secondary MUX. */
895static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
896{
897 uint32_t regval;
898
899 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700900 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700902 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903
904 /* Program the MUX. */
905 regval &= ~(0x3 << 2);
906 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700907 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700908
909 /* Wait for switch to complete. */
910 mb();
911 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700912
913 /* Re-enable secondary source clock gating. */
914 regval &= ~SECCLKAGD;
915 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916}
917
918/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800919static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700920{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700921 int rc;
922
Matt Wagantallc1021762012-01-31 20:02:02 -0800923 if (!skip_regulators) {
924 if (cpu_is_msm8960()) {
925 rc = rpm_vreg_set_voltage(
926 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
927 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
David Collins9a81d6c2012-03-29 15:11:33 -0700928 2050000,
Matt Wagantallc1021762012-01-31 20:02:02 -0800929 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
930 if (rc)
931 pr_err("%s regulator enable failed (%d)\n",
932 sc->vreg[VREG_HFPLL_A].name, rc);
933 }
934 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
935 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
936 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800937 if (rc)
938 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800939 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800940 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700941 /* Disable PLL bypass mode. */
942 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
943
944 /*
945 * H/W requires a 5us delay between disabling the bypass and
946 * de-asserting the reset. Delay 10us just to be safe.
947 */
948 mb();
949 udelay(10);
950
951 /* De-assert active-low PLL reset. */
952 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
953
954 /* Wait for PLL to lock. */
955 mb();
956 udelay(60);
957
958 /* Enable PLL output. */
959 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
960}
961
962/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800963static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700965 int rc;
966
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967 /*
968 * Disable the PLL output, disable test mode, enable
969 * the bypass mode, and assert the reset.
970 */
971 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700972
Matt Wagantallc1021762012-01-31 20:02:02 -0800973 if (!skip_regulators) {
974 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
975 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800976 0, 0);
977 if (rc)
978 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800979 sc->vreg[VREG_HFPLL_B].name, rc);
980
981 if (cpu_is_msm8960()) {
982 rc = rpm_vreg_set_voltage(
983 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
984 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
985 0, 0, 0);
986 if (rc)
987 pr_err("%s regulator enable failed (%d)\n",
988 sc->vreg[VREG_HFPLL_A].name, rc);
989 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800990 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700991}
992
993/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
994static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
995{
996 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
997}
998
999/* Return the L2 speed that should be applied. */
1000static struct l2_level *compute_l2_level(struct scalable *sc,
1001 struct l2_level *vote_l)
1002{
1003 struct l2_level *new_l;
1004 int cpu;
1005
1006 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -07001007 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001008
1009 /* Find max L2 speed vote. */
1010 sc->l2_vote = vote_l;
1011 new_l = l2_freq_tbl;
1012 for_each_present_cpu(cpu)
1013 new_l = max(new_l, scalable[cpu].l2_vote);
1014
1015 return new_l;
1016}
1017
1018/* Update the bus bandwidth request. */
1019static void set_bus_bw(unsigned int bw)
1020{
1021 int ret;
1022
1023 /* Bounds check. */
1024 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
1025 pr_err("invalid bandwidth request (%d)\n", bw);
1026 return;
1027 }
1028
1029 /* Update bandwidth if request has changed. This may sleep. */
1030 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
1031 if (ret)
1032 pr_err("bandwidth request failed (%d)\n", ret);
1033}
1034
1035/* Set the CPU or L2 clock speed. */
1036static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
1037 enum setrate_reason reason)
1038{
1039 struct core_speed *strt_s = sc->current_speed;
1040
1041 if (tgt_s == strt_s)
1042 return;
1043
1044 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001045 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001046 * Move to an always-on source running at a frequency that does
1047 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001048 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001049 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001050 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
1051
1052 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -08001053 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001054 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001055 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001056
1057 /* Move CPU to HFPLL source. */
1058 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1059 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001060 /*
Matt Wagantall34c2d962012-02-01 14:30:02 -08001061 * If responding to CPU_DEAD we must be running on another CPU.
1062 * Therefore, we can't access the downed CPU's clock MUX CP15
1063 * registers from here and can't change clock sources. If the
1064 * CPU is collapsed, however, it is still safe to turn off the
1065 * PLL without switching the MUX away from it.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001066 */
1067 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
1068 set_sec_clk_src(sc, tgt_s->sec_src_sel);
1069 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -08001070 hfpll_disable(sc, 0);
1071 } else if (reason == SETRATE_HOTPLUG
1072 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
1073 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001074 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001075 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001076 /*
1077 * If responding to CPU_UP_PREPARE, we can't change CP15
1078 * registers for the CPU that's coming up since we're not
1079 * running on that CPU. That's okay though, since the MUX
1080 * source was not changed on the way down, either.
1081 */
Matt Wagantall34c2d962012-02-01 14:30:02 -08001082 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
1083 hfpll_set_rate(sc, tgt_s);
1084 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001085 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -08001086 } else if (reason == SETRATE_HOTPLUG
1087 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
1088 /* PLL was disabled during hot-unplug. Re-enable it. */
1089 hfpll_set_rate(sc, tgt_s);
1090 hfpll_enable(sc, 0);
1091 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001092 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001093 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
1094 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001095 }
1096
1097 sc->current_speed = tgt_s;
1098}
1099
1100/* Apply any per-cpu voltage increases. */
1101static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1102 unsigned int vdd_dig, enum setrate_reason reason)
1103{
1104 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -07001105 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001106
1107 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001108 * Increase vdd_mem active-set before vdd_dig.
1109 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001110 */
1111 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
1112 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1113 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1114 sc->vreg[VREG_MEM].max_vdd, 0);
1115 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001116 pr_err("%s increase failed (%d)\n",
1117 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001118 return rc;
1119 }
1120 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1121 }
1122
1123 /* Increase vdd_dig active-set vote. */
1124 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
1125 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1126 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1127 sc->vreg[VREG_DIG].max_vdd, 0);
1128 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001129 pr_err("%s increase failed (%d)\n",
1130 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001131 return rc;
1132 }
1133 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1134 }
1135
1136 /*
1137 * Update per-CPU core voltage. Don't do this for the hotplug path for
1138 * which it should already be correct. Attempting to set it is bad
1139 * because we don't know what CPU we are running on at this point, but
1140 * the CPU regulator API requires we call it from the affected CPU.
1141 */
1142 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
1143 && reason != SETRATE_HOTPLUG) {
1144 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1145 sc->vreg[VREG_CORE].max_vdd);
1146 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001147 pr_err("%s increase failed (%d)\n",
1148 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001149 return rc;
1150 }
1151 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1152 }
1153
1154 return rc;
1155}
1156
1157/* Apply any per-cpu voltage decreases. */
1158static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1159 unsigned int vdd_dig, enum setrate_reason reason)
1160{
1161 struct scalable *sc = &scalable[cpu];
1162 int ret;
1163
1164 /*
1165 * Update per-CPU core voltage. This must be called on the CPU
1166 * that's being affected. Don't do this in the hotplug remove path,
1167 * where the rail is off and we're executing on the other CPU.
1168 */
1169 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1170 && reason != SETRATE_HOTPLUG) {
1171 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1172 sc->vreg[VREG_CORE].max_vdd);
1173 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001174 pr_err("%s decrease failed (%d)\n",
1175 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001176 return;
1177 }
1178 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1179 }
1180
1181 /* Decrease vdd_dig active-set vote. */
1182 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1183 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1184 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1185 sc->vreg[VREG_DIG].max_vdd, 0);
1186 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001187 pr_err("%s decrease failed (%d)\n",
1188 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001189 return;
1190 }
1191 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1192 }
1193
1194 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001195 * Decrease vdd_mem active-set after vdd_dig.
1196 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001197 */
1198 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1199 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1200 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1201 sc->vreg[VREG_MEM].max_vdd, 0);
1202 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001203 pr_err("%s decrease failed (%d)\n",
1204 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001205 return;
1206 }
1207 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1208 }
1209}
1210
1211static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1212{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001213 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001214}
1215
1216static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1217{
1218 unsigned int pll_vdd_dig;
1219
Stephen Boydc76158f2011-12-08 12:42:40 -08001220 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001221 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001222 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001223 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1224 else
1225 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1226
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001227 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1228}
1229
Tianyi Gouaded6432012-02-22 14:53:05 -08001230static unsigned int calculate_vdd_core(struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001231{
Tianyi Gouaded6432012-02-22 14:53:05 -08001232 return tgt->vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233}
1234
1235/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001236static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1237 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001238{
1239 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1240 struct l2_level *tgt_l2_l;
1241 struct acpu_level *tgt;
1242 unsigned int vdd_mem, vdd_dig, vdd_core;
1243 unsigned long flags;
1244 int rc = 0;
1245
1246 if (cpu > num_possible_cpus()) {
1247 rc = -EINVAL;
1248 goto out;
1249 }
1250
1251 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1252 mutex_lock(&driver_lock);
1253
1254 strt_acpu_s = scalable[cpu].current_speed;
1255
1256 /* Return early if rate didn't change. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001257 if (rate == strt_acpu_s->khz)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001258 goto out;
1259
1260 /* Find target frequency. */
1261 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1262 if (tgt->speed.khz == rate) {
1263 tgt_acpu_s = &tgt->speed;
1264 break;
1265 }
1266 }
1267 if (tgt->speed.khz == 0) {
1268 rc = -EINVAL;
1269 goto out;
1270 }
1271
1272 /* Calculate voltage requirements for the current CPU. */
1273 vdd_mem = calculate_vdd_mem(tgt);
1274 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gouaded6432012-02-22 14:53:05 -08001275 vdd_core = calculate_vdd_core(tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001276
1277 /* Increase VDD levels if needed. */
1278 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1279 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1280 if (rc)
1281 goto out;
1282 }
1283
1284 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1285 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1286
1287 /* Set the CPU speed. */
1288 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1289
1290 /*
1291 * Update the L2 vote and apply the rate change. A spinlock is
1292 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001293 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001294 * and the driver_lock mutex is not acquired.
1295 */
1296 spin_lock_irqsave(&l2_lock, flags);
1297 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1298 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1299 spin_unlock_irqrestore(&l2_lock, flags);
1300
1301 /* Nothing else to do for power collapse or SWFI. */
1302 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1303 goto out;
1304
1305 /* Update bus bandwith request. */
1306 set_bus_bw(tgt_l2_l->bw_level);
1307
1308 /* Drop VDD levels if we can. */
1309 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1310
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001311 pr_debug("ACPU%d speed change complete\n", cpu);
1312
1313out:
1314 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1315 mutex_unlock(&driver_lock);
1316 return rc;
1317}
1318
1319/* Initialize a HFPLL at a given rate and enable it. */
1320static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1321{
1322 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1323
1324 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001325 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001326
1327 /* Configure PLL parameters for integer mode. */
1328 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1329 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1330 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1331
1332 /* Program droop controller. */
1333 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1334
1335 /* Set an initial rate and enable the PLL. */
1336 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001337 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001338}
1339
1340/* Voltage regulator initialization. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001341static void __init regulator_init(struct acpu_level *lvl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001342{
1343 int cpu, ret;
1344 struct scalable *sc;
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001345 unsigned int vdd_mem, vdd_dig, vdd_core;
1346
1347 vdd_mem = calculate_vdd_mem(lvl);
1348 vdd_dig = calculate_vdd_dig(lvl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001349
1350 for_each_possible_cpu(cpu) {
1351 sc = &scalable[cpu];
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001352
1353 /* Set initial vdd_mem vote. */
1354 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1355 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1356 sc->vreg[VREG_MEM].max_vdd, 0);
1357 if (ret) {
1358 pr_err("%s initialization failed (%d)\n",
1359 sc->vreg[VREG_MEM].name, ret);
1360 BUG();
1361 }
1362 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1363
1364 /* Set initial vdd_dig vote. */
1365 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1366 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1367 sc->vreg[VREG_DIG].max_vdd, 0);
1368 if (ret) {
1369 pr_err("%s initialization failed (%d)\n",
1370 sc->vreg[VREG_DIG].name, ret);
1371 BUG();
1372 }
1373 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1374
1375 /* Setup Krait CPU regulators and initial core voltage. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001376 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1377 sc->vreg[VREG_CORE].name);
1378 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1379 pr_err("regulator_get(%s) failed (%ld)\n",
1380 sc->vreg[VREG_CORE].name,
1381 PTR_ERR(sc->vreg[VREG_CORE].reg));
1382 BUG();
1383 }
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001384 vdd_core = calculate_vdd_core(lvl);
1385 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001386 sc->vreg[VREG_CORE].max_vdd);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001387 if (ret) {
1388 pr_err("%s initialization failed (%d)\n",
1389 sc->vreg[VREG_CORE].name, ret);
1390 BUG();
1391 }
1392 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001393 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001394 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001395 pr_err("regulator_enable(%s) failed (%d)\n",
1396 sc->vreg[VREG_CORE].name, ret);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001397 BUG();
1398 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001399 }
1400}
1401
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001402/* Set initial rate for a given core. */
1403static void __init init_clock_sources(struct scalable *sc,
1404 struct core_speed *tgt_s)
1405{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001406 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001407
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001408 /* Select PLL8 as AUX source input to the secondary MUX. */
1409 writel_relaxed(0x3, sc->aux_clk_sel);
1410
1411 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001412 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001413 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001414 hfpll_init(sc, tgt_s);
1415
1416 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001417 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001418 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001419 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001420
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001421 /* Switch to the target clock source. */
1422 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001423 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1424 sc->current_speed = tgt_s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001425}
1426
Matt Wagantall8e726c72011-08-06 00:49:28 -07001427static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001428{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001429 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001430 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001431
1432 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1433 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001434}
1435
1436/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001437static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001438{
1439 int ret;
1440
1441 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1442 if (!bus_perf_client) {
1443 pr_err("unable to register bus client\n");
1444 BUG();
1445 }
1446
Stephen Boydcfe192b2011-12-09 21:47:14 -08001447 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001448 if (ret)
1449 pr_err("initial bandwidth request failed (%d)\n", ret);
1450}
1451
1452#ifdef CONFIG_CPU_FREQ_MSM
1453static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1454
1455static void __init cpufreq_table_init(void)
1456{
1457 int cpu;
1458
1459 for_each_possible_cpu(cpu) {
1460 int i, freq_cnt = 0;
1461 /* Construct the freq_table tables from acpu_freq_tbl. */
1462 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1463 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1464 if (acpu_freq_tbl[i].use_for_scaling) {
1465 freq_table[cpu][freq_cnt].index = freq_cnt;
1466 freq_table[cpu][freq_cnt].frequency
1467 = acpu_freq_tbl[i].speed.khz;
1468 freq_cnt++;
1469 }
1470 }
1471 /* freq_table not big enough to store all usable freqs. */
1472 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1473
1474 freq_table[cpu][freq_cnt].index = freq_cnt;
1475 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1476
1477 pr_info("CPU%d: %d scaling frequencies supported.\n",
1478 cpu, freq_cnt);
1479
1480 /* Register table with CPUFreq. */
1481 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1482 }
1483}
1484#else
1485static void __init cpufreq_table_init(void) {}
1486#endif
1487
1488#define HOT_UNPLUG_KHZ STBY_KHZ
1489static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1490 unsigned long action, void *hcpu)
1491{
1492 static int prev_khz[NR_CPUS];
1493 static int prev_pri_src[NR_CPUS];
1494 static int prev_sec_src[NR_CPUS];
1495 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001496
1497 switch (action) {
1498 case CPU_DYING:
1499 case CPU_DYING_FROZEN:
1500 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001501 * On Krait v1 and 8064v1, the primary and secondary muxes must
1502 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001503 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001504 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001505 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1506 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1507 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1508 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1509 }
1510 break;
1511 case CPU_DEAD:
1512 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001513 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001514 /* Fall through. */
1515 case CPU_UP_CANCELED:
1516 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001517 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001518 break;
1519 case CPU_UP_PREPARE:
1520 case CPU_UP_PREPARE_FROZEN:
1521 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001522 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001523 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001524 break;
1525 case CPU_STARTING:
1526 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001527 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001528 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1529 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1530 }
1531 break;
1532 default:
1533 break;
1534 }
1535
1536 return NOTIFY_OK;
1537}
1538
1539static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1540 .notifier_call = acpuclock_cpu_callback,
1541};
1542
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001543static const int krait_needs_vmin(void)
1544{
1545 switch (read_cpuid_id()) {
1546 case 0x511F04D0:
1547 case 0x511F04D1:
1548 case 0x510F06F0:
1549 return 1;
1550 default:
1551 return 0;
1552 };
1553}
1554
Stephen Boydaefb8de2012-01-05 19:05:01 -08001555static void kraitv2_apply_vmin(struct acpu_level *tbl)
1556{
1557 for (; tbl->speed.khz != 0; tbl++)
1558 if (tbl->vdd_core < 1150000)
1559 tbl->vdd_core = 1150000;
1560}
1561
Tianyi Goudff51062012-06-04 20:22:23 -07001562static enum pvs __init get_pvs(void)
1563{
1564 uint32_t pte_efuse, pvs;
1565
1566 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1567 pvs = (pte_efuse >> 10) & 0x7;
1568 if (pvs == 0x7)
1569 pvs = (pte_efuse >> 13) & 0x7;
1570
1571 switch (pvs) {
1572 case 0x0:
1573 case 0x7:
1574 pr_info("ACPU PVS: Slow\n");
1575 return PVS_SLOW;
1576 case 0x1:
1577 pr_info("ACPU PVS: Nominal\n");
1578 return PVS_NOM;
1579 case 0x3:
1580 pr_info("ACPU PVS: Fast\n");
1581 return PVS_FAST;
1582 case 0x4:
1583 if (cpu_is_apq8064()) {
1584 pr_info("ACPU PVS: Faster\n");
1585 return PVS_FASTER;
1586 }
1587 default:
1588 pr_warn("ACPU PVS: Unknown. Defaulting to slow\n");
1589 return PVS_SLOW;
1590 }
1591}
1592
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001593static struct acpu_level * __init select_freq_plan(void)
1594{
1595 struct acpu_level *l, *max_acpu_level = NULL;
1596
1597 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001598 if (cpu_is_msm8960()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001599 enum pvs pvs_id = get_pvs();
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001600
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001601 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001602 if (cpu_is_krait_v1()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001603 acpu_freq_tbl = acpu_freq_tbl_8960_v1[pvs_id];
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001604 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1605 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1606 } else {
Tianyi Goudff51062012-06-04 20:22:23 -07001607 acpu_freq_tbl = acpu_freq_tbl_8960_v2[pvs_id];
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001608 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1609 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1610 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001611 } else if (cpu_is_apq8064()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001612 enum pvs pvs_id = get_pvs();
1613
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001614 scalable = scalable_8064;
Tianyi Goudff51062012-06-04 20:22:23 -07001615 acpu_freq_tbl = acpu_freq_tbl_8064[pvs_id];
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001616 l2_freq_tbl = l2_freq_tbl_8064;
1617 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001618 } else if (cpu_is_msm8627()) {
1619 scalable = scalable_8627;
1620 acpu_freq_tbl = acpu_freq_tbl_8627;
1621 l2_freq_tbl = l2_freq_tbl_8627;
1622 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001623 } else if (cpu_is_msm8930()) {
Tianyi Gou64307be2012-06-06 14:25:25 -07001624 enum pvs pvs_id = get_pvs();
1625
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001626 scalable = scalable_8930;
Tianyi Gou64307be2012-06-06 14:25:25 -07001627 acpu_freq_tbl = acpu_freq_tbl_8930_pvs[pvs_id];
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001628 l2_freq_tbl = l2_freq_tbl_8930;
1629 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001630 } else {
1631 BUG();
1632 }
Tianyi Goudff51062012-06-04 20:22:23 -07001633 BUG_ON(!acpu_freq_tbl);
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001634 if (krait_needs_vmin())
1635 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001636
1637 /* Find the max supported scaling frequency. */
1638 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1639 if (l->use_for_scaling)
1640 max_acpu_level = l;
1641 BUG_ON(!max_acpu_level);
1642 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1643
1644 return max_acpu_level;
1645}
1646
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001647static struct acpuclk_data acpuclk_8960_data = {
1648 .set_rate = acpuclk_8960_set_rate,
1649 .get_rate = acpuclk_8960_get_rate,
1650 .power_collapse_khz = STBY_KHZ,
1651 .wait_for_irq_khz = STBY_KHZ,
1652};
1653
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001654static int __init acpuclk_8960_probe(struct platform_device *pdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001655{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001656 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001657
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001658 regulator_init(max_acpu_level);
Stephen Boydcfe192b2011-12-09 21:47:14 -08001659 bus_init(max_acpu_level->l2_level->bw_level);
1660
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001661 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1662 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001663
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001664 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001665
1666 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001667 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001668
1669 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001670}
Matt Wagantallec57f062011-08-16 23:54:46 -07001671
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001672static struct platform_driver acpuclk_8960_driver = {
1673 .driver = {
1674 .name = "acpuclk-8960",
1675 .owner = THIS_MODULE,
1676 },
Matt Wagantallec57f062011-08-16 23:54:46 -07001677};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001678
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001679static int __init acpuclk_8960_init(void)
1680{
1681 return platform_driver_probe(&acpuclk_8960_driver, acpuclk_8960_probe);
1682}
1683device_initcall(acpuclk_8960_init);