blob: cbeac3f2322b900d5d17efeea03c6e13f1cbac0a [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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
71
72#define SECCLKAGD BIT(4)
73
Matt Wagantalla518f8f2011-10-17 13:24:53 -070074/* PTE EFUSE register. */
75#define QFPROM_PTE_EFUSE_ADDR (MSM_QFPROM_BASE + 0x00C0)
76
Tianyi Gou50705682012-02-21 17:51:50 -080077/* Corner type vreg VDD values */
78#define LVL_NONE RPM_VREG_CORNER_NONE
79#define LVL_LOW RPM_VREG_CORNER_LOW
80#define LVL_NOM RPM_VREG_CORNER_NOMINAL
81#define LVL_HIGH RPM_VREG_CORNER_HIGH
82
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070083enum scalables {
84 CPU0 = 0,
85 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070086 CPU2,
87 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088 L2,
89 NUM_SCALABLES
90};
91
92enum vregs {
93 VREG_CORE,
94 VREG_MEM,
95 VREG_DIG,
Matt Wagantallcb12c392011-10-19 10:32:07 -070096 VREG_HFPLL_A,
97 VREG_HFPLL_B,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098 NUM_VREG
99};
100
Tianyi Gou50705682012-02-21 17:51:50 -0800101enum hfpll_vdd_levels {
102 HFPLL_VDD_NONE,
103 HFPLL_VDD_LOW,
104 HFPLL_VDD_NOM
105};
106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107struct vreg {
108 const char name[15];
109 const unsigned int max_vdd;
110 const int rpm_vreg_voter;
111 const int rpm_vreg_id;
112 struct regulator *reg;
113 unsigned int cur_vdd;
114};
115
116struct core_speed {
117 unsigned int khz;
118 int src;
119 unsigned int pri_src_sel;
120 unsigned int sec_src_sel;
121 unsigned int pll_l_val;
122};
123
124struct l2_level {
125 struct core_speed speed;
126 unsigned int vdd_dig;
127 unsigned int vdd_mem;
128 unsigned int bw_level;
129};
130
131struct acpu_level {
132 unsigned int use_for_scaling;
133 struct core_speed speed;
134 struct l2_level *l2_level;
135 unsigned int vdd_core;
136};
137
138struct scalable {
139 void * __iomem const hfpll_base;
140 void * __iomem const aux_clk_sel;
141 const uint32_t l2cpmr_iaddr;
142 struct core_speed *current_speed;
143 struct l2_level *l2_vote;
144 struct vreg vreg[NUM_VREG];
Tianyi Gou50705682012-02-21 17:51:50 -0800145 unsigned int *hfpll_vdd_tbl;
146};
147
148static unsigned int hfpll_vdd_tbl_8960[] = {
149 [HFPLL_VDD_NONE] = 0,
150 [HFPLL_VDD_LOW] = 850000,
151 [HFPLL_VDD_NOM] = 1050000
152};
153
154static unsigned int hfpll_vdd_tbl_8064[] = {
155 [HFPLL_VDD_NONE] = 0,
156 [HFPLL_VDD_LOW] = 945000,
157 [HFPLL_VDD_NOM] = 1050000
158};
159
160static unsigned int hfpll_vdd_dig_tbl_8930[] = {
161 [HFPLL_VDD_NONE] = LVL_NONE,
162 [HFPLL_VDD_LOW] = LVL_LOW,
163 [HFPLL_VDD_NOM] = LVL_NOM
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164};
165
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700166static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167 [CPU0] = {
168 .hfpll_base = MSM_HFPLL_BASE + 0x200,
169 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
170 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800171 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
173 RPM_VREG_VOTER1,
174 RPM_VREG_ID_PM8921_L24 },
175 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
176 RPM_VREG_VOTER1,
177 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800178 .vreg[VREG_HFPLL_A] = { "hfpll0_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700179 RPM_VREG_VOTER1,
180 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800181 .vreg[VREG_HFPLL_B] = { "hfpll0_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700182 RPM_VREG_VOTER1,
183 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184 },
185 [CPU1] = {
186 .hfpll_base = MSM_HFPLL_BASE + 0x300,
187 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
188 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800189 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800190 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191 RPM_VREG_VOTER2,
192 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800193 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194 RPM_VREG_VOTER2,
195 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800196 .vreg[VREG_HFPLL_A] = { "hfpll1_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700197 RPM_VREG_VOTER2,
198 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800199 .vreg[VREG_HFPLL_B] = { "hfpll1_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700200 RPM_VREG_VOTER2,
201 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202 },
203 [L2] = {
204 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800205 .hfpll_vdd_tbl = hfpll_vdd_tbl_8960,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700206 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
207 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800208 .vreg[VREG_HFPLL_A] = { "hfpll_l2_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700209 RPM_VREG_VOTER6,
210 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800211 .vreg[VREG_HFPLL_B] = { "hfpll_l2_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700212 RPM_VREG_VOTER6,
213 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700214 },
215};
216
Stephen Boyd7ad84752011-08-05 14:04:28 -0700217static DEFINE_MUTEX(driver_lock);
218static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700220static struct scalable scalable_8064[] = {
221 [CPU0] = {
222 .hfpll_base = MSM_HFPLL_BASE + 0x200,
223 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
224 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800225 .vreg[VREG_CORE] = { "krait0", 1300000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700226 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
227 RPM_VREG_VOTER1,
228 RPM_VREG_ID_PM8921_L24 },
229 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
230 RPM_VREG_VOTER1,
231 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800232 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800233 RPM_VREG_VOTER1,
234 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700235 },
236 [CPU1] = {
237 .hfpll_base = MSM_HFPLL_BASE + 0x240,
238 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
239 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800240 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800241 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700242 RPM_VREG_VOTER2,
243 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800244 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700245 RPM_VREG_VOTER2,
246 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800247 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800248 RPM_VREG_VOTER2,
249 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700250 },
251 [CPU2] = {
252 .hfpll_base = MSM_HFPLL_BASE + 0x280,
253 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
254 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800255 .vreg[VREG_CORE] = { "krait2", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800256 .vreg[VREG_MEM] = { "krait2_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700257 RPM_VREG_VOTER4,
258 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800259 .vreg[VREG_DIG] = { "krait2_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700260 RPM_VREG_VOTER4,
261 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800262 .vreg[VREG_HFPLL_B] = { "hfpll2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800263 RPM_VREG_VOTER4,
264 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700265 },
266 [CPU3] = {
267 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
268 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
269 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800270 .vreg[VREG_CORE] = { "krait3", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800271 .vreg[VREG_MEM] = { "krait3_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700272 RPM_VREG_VOTER5,
273 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800274 .vreg[VREG_DIG] = { "krait3_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700275 RPM_VREG_VOTER5,
276 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800277 .vreg[VREG_HFPLL_B] = { "hfpll3", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800278 RPM_VREG_VOTER5,
279 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700280 },
281 [L2] = {
282 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800283 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700284 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
285 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800286 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800287 RPM_VREG_VOTER6,
288 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700289 },
290};
291
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800292static struct scalable scalable_8930[] = {
293 [CPU0] = {
294 .hfpll_base = MSM_HFPLL_BASE + 0x200,
295 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
296 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
297 .vreg[VREG_CORE] = { "krait0", 1300000 },
298 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
299 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800300 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800301 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800302 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800303 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
304 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800305 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800306 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800307 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800308 },
309 [CPU1] = {
310 .hfpll_base = MSM_HFPLL_BASE + 0x300,
311 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
312 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
313 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800314 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800315 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800316 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800317 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800318 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800319 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
320 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800321 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800322 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800323 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800324 },
325 [L2] = {
326 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800327 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800328 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
329 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800330 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800331 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800332 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800333 },
334};
335
Tianyi Goue0b34de2011-12-20 11:20:10 -0800336/*TODO: Update the rpm vreg id when the rpm driver is ready */
337static struct scalable scalable_8627[] = {
338 [CPU0] = {
339 .hfpll_base = MSM_HFPLL_BASE + 0x200,
340 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
341 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
342 .vreg[VREG_CORE] = { "krait0", 1300000 },
343 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
344 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800345 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800346 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800347 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800348 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
349 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800350 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800351 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800352 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800353 },
354 [CPU1] = {
355 .hfpll_base = MSM_HFPLL_BASE + 0x300,
356 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
357 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
358 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800359 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800360 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800361 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800362 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800363 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800364 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
365 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800366 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800367 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800368 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800369 },
370 [L2] = {
371 .hfpll_base = MSM_HFPLL_BASE + 0x400,
372 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
373 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800374 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800375 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800376 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800377 },
378};
379
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700380static struct scalable *scalable;
381static struct l2_level *l2_freq_tbl;
382static struct acpu_level *acpu_freq_tbl;
383static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700384
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700385/* Instantaneous bandwidth requests in MB/s. */
386#define BW_MBPS(_bw) \
387 { \
388 .vectors = (struct msm_bus_vectors[]){ \
389 {\
390 .src = MSM_BUS_MASTER_AMPSS_M0, \
391 .dst = MSM_BUS_SLAVE_EBI_CH0, \
392 .ib = (_bw) * 1000000UL, \
393 .ab = (_bw) * 100000UL, \
394 }, \
395 { \
396 .src = MSM_BUS_MASTER_AMPSS_M1, \
397 .dst = MSM_BUS_SLAVE_EBI_CH0, \
398 .ib = (_bw) * 1000000UL, \
399 .ab = (_bw) * 100000UL, \
400 }, \
401 }, \
402 .num_paths = 2, \
403 }
404static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800405 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
406 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
407 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
408 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
409 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
410 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
411 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800412 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700413};
414
415static struct msm_bus_scale_pdata bus_client_pdata = {
416 .usecase = bw_level_tbl,
417 .num_usecases = ARRAY_SIZE(bw_level_tbl),
418 .active_only = 1,
419 .name = "acpuclock",
420};
421
422static uint32_t bus_perf_client;
423
424/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800425#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
426static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700427 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700428 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700429 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
430 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
431 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
432 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
433 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
434 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700435 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700436 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
437 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
438 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700439};
440
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800441static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
442 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
443 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
444 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
445 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
446 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
447 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
448 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
449 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
450 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
451 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
452 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
453 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
454 { 0, { 0 } }
455};
456
457static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
458 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
459 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
460 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
461 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
462 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
463 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
464 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
465 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
466 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
467 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
468 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
469 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700470 { 0, { 0 } }
471};
472
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800473#undef L2
474#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
475static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
476 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
477 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800478 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
479 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
480 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800481 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800482 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
483 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
484 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
485 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
486 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
487 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
488 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
489 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
490 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
491 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
492 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800493 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
494 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
495 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800496};
497
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800498static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800499 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
500 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800501 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
502 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
503 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
504 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
505 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
506 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
507 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
508 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
509 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
510 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
511 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
512 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
513 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800514 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800515 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800516 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800517 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800518 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800519 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800520 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1237500 },
521 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800522 { 0, { 0 } }
523};
524
525static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800526 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
527 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800528 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
529 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
530 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
531 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
532 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
533 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
534 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
535 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
536 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
537 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
538 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
539 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
540 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800541 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800542 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800543 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1150000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800544 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1175000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800545 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800546 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800547 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1187500 },
548 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800549 { 0, { 0 } }
550};
551
Stephen Boyd5766f682011-12-27 19:21:08 -0800552static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800553 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
554 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800555 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
556 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
557 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
558 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
559 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
560 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
561 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
562 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
563 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
564 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
565 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
566 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
567 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800568 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800569 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800570 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1100000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800571 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1125000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800572 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800573 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1137500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800574 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1137500 },
575 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800576 { 0, { 0 } }
577};
578
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700579/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
580#undef L2
581#define L2(x) (&l2_freq_tbl_8064[(x)])
582static struct l2_level l2_freq_tbl_8064[] = {
583 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800584 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
585 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
586 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
587 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700588 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800589 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
590 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
591 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
592 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
593 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
594 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
595 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
596 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
597 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
598 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700599};
600
601/* TODO: Update core voltages when data is available. */
602static struct acpu_level acpu_freq_tbl_8064[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800603 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
604 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
605 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
606 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
607 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
608 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
609 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
610 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
611 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
612 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
613 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
614 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
615 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
616 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
617 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
618 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
619 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
620 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
621 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
622 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
623 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
624 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
625 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700626 { 0, { 0 } }
627};
628
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800629/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
630#undef L2
631#define L2(x) (&l2_freq_tbl_8930[(x)])
632static struct l2_level l2_freq_tbl_8930[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800633 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
634 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800635 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 2 },
636 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 2 },
637 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
Tianyi Gou50705682012-02-21 17:51:50 -0800638 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800639 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 4 },
640 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 4 },
641 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 4 },
642 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 4 },
643 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
644 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 7 },
645 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 7 },
646 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, LVL_HIGH, 1150000, 7 },
647 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, LVL_HIGH, 1150000, 7 },
648 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, LVL_HIGH, 1150000, 7 },
649 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, LVL_HIGH, 1150000, 7 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800650};
651
652/* TODO: Update core voltages when data is available. */
653static struct acpu_level acpu_freq_tbl_8930[] = {
654 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
655 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
656 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
657 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
658 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
659 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
660 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
661 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
662 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
663 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
664 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
665 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
666 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
667 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
668 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
669 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
670 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
671 { 0, { 0 } }
672};
673
Tianyi Goue0b34de2011-12-20 11:20:10 -0800674/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
675#undef L2
676#define L2(x) (&l2_freq_tbl_8627[(x)])
677static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800678 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
679 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
680 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
681 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
682 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
683 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
684 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
685 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
686 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
687 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
688 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
689 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
690 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800691};
692
693/* TODO: Update core voltages when data is available. */
694static struct acpu_level acpu_freq_tbl_8627[] = {
695 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
696 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
697 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
698 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
699 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
700 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
701 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
702 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
703 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
704 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
705 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
706 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
707 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
708 { 0, { 0 } }
709};
710
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700711static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700712{
713 return scalable[cpu].current_speed->khz;
714}
715
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716/* Get the selected source on primary MUX. */
717static int get_pri_clk_src(struct scalable *sc)
718{
719 uint32_t regval;
720
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700721 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700722 return regval & 0x3;
723}
724
725/* Set the selected source on primary MUX. */
726static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
727{
728 uint32_t regval;
729
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700730 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700731 regval &= ~0x3;
732 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700733 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734 /* Wait for switch to complete. */
735 mb();
736 udelay(1);
737}
738
739/* Get the selected source on secondary MUX. */
740static int get_sec_clk_src(struct scalable *sc)
741{
742 uint32_t regval;
743
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700744 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700745 return (regval >> 2) & 0x3;
746}
747
748/* Set the selected source on secondary MUX. */
749static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
750{
751 uint32_t regval;
752
753 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700754 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700755 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700756 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757
758 /* Program the MUX. */
759 regval &= ~(0x3 << 2);
760 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700761 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700762
763 /* Wait for switch to complete. */
764 mb();
765 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700766
767 /* Re-enable secondary source clock gating. */
768 regval &= ~SECCLKAGD;
769 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700770}
771
772/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800773static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700774{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700775 int rc;
776
Matt Wagantallc1021762012-01-31 20:02:02 -0800777 if (!skip_regulators) {
778 if (cpu_is_msm8960()) {
779 rc = rpm_vreg_set_voltage(
780 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
781 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
782 2100000,
783 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
784 if (rc)
785 pr_err("%s regulator enable failed (%d)\n",
786 sc->vreg[VREG_HFPLL_A].name, rc);
787 }
788 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
789 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
790 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800791 if (rc)
792 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800793 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800794 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700795 /* Disable PLL bypass mode. */
796 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
797
798 /*
799 * H/W requires a 5us delay between disabling the bypass and
800 * de-asserting the reset. Delay 10us just to be safe.
801 */
802 mb();
803 udelay(10);
804
805 /* De-assert active-low PLL reset. */
806 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
807
808 /* Wait for PLL to lock. */
809 mb();
810 udelay(60);
811
812 /* Enable PLL output. */
813 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
814}
815
816/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800817static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700818{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700819 int rc;
820
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821 /*
822 * Disable the PLL output, disable test mode, enable
823 * the bypass mode, and assert the reset.
824 */
825 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700826
Matt Wagantallc1021762012-01-31 20:02:02 -0800827 if (!skip_regulators) {
828 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
829 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800830 0, 0);
831 if (rc)
832 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800833 sc->vreg[VREG_HFPLL_B].name, rc);
834
835 if (cpu_is_msm8960()) {
836 rc = rpm_vreg_set_voltage(
837 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
838 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
839 0, 0, 0);
840 if (rc)
841 pr_err("%s regulator enable failed (%d)\n",
842 sc->vreg[VREG_HFPLL_A].name, rc);
843 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800844 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700845}
846
847/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
848static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
849{
850 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
851}
852
853/* Return the L2 speed that should be applied. */
854static struct l2_level *compute_l2_level(struct scalable *sc,
855 struct l2_level *vote_l)
856{
857 struct l2_level *new_l;
858 int cpu;
859
860 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700861 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700862
863 /* Find max L2 speed vote. */
864 sc->l2_vote = vote_l;
865 new_l = l2_freq_tbl;
866 for_each_present_cpu(cpu)
867 new_l = max(new_l, scalable[cpu].l2_vote);
868
869 return new_l;
870}
871
872/* Update the bus bandwidth request. */
873static void set_bus_bw(unsigned int bw)
874{
875 int ret;
876
877 /* Bounds check. */
878 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
879 pr_err("invalid bandwidth request (%d)\n", bw);
880 return;
881 }
882
883 /* Update bandwidth if request has changed. This may sleep. */
884 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
885 if (ret)
886 pr_err("bandwidth request failed (%d)\n", ret);
887}
888
889/* Set the CPU or L2 clock speed. */
890static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
891 enum setrate_reason reason)
892{
893 struct core_speed *strt_s = sc->current_speed;
894
895 if (tgt_s == strt_s)
896 return;
897
898 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700899 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700900 * Move to an always-on source running at a frequency that does
901 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700903 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700904 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
905
906 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800907 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700908 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800909 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910
911 /* Move CPU to HFPLL source. */
912 set_pri_clk_src(sc, tgt_s->pri_src_sel);
913 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700914 /*
915 * If responding to CPU_DEAD we must be running on another
916 * CPU. Therefore, we can't access the downed CPU's CP15
917 * clock MUX registers from here and can't change clock sources.
918 * Just turn off the PLL- since the CPU is down already, halting
919 * its clock should be safe.
920 */
921 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
922 set_sec_clk_src(sc, tgt_s->sec_src_sel);
923 set_pri_clk_src(sc, tgt_s->pri_src_sel);
924 }
Matt Wagantallc1021762012-01-31 20:02:02 -0800925 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
927 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800928 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700929 /*
930 * If responding to CPU_UP_PREPARE, we can't change CP15
931 * registers for the CPU that's coming up since we're not
932 * running on that CPU. That's okay though, since the MUX
933 * source was not changed on the way down, either.
934 */
935 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
936 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700937 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700938 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
939 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700940 }
941
942 sc->current_speed = tgt_s;
943}
944
945/* Apply any per-cpu voltage increases. */
946static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
947 unsigned int vdd_dig, enum setrate_reason reason)
948{
949 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700950 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700951
952 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700953 * Increase vdd_mem active-set before vdd_dig.
954 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700955 */
956 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
957 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
958 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
959 sc->vreg[VREG_MEM].max_vdd, 0);
960 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800961 pr_err("%s increase failed (%d)\n",
962 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700963 return rc;
964 }
965 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
966 }
967
968 /* Increase vdd_dig active-set vote. */
969 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
970 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
971 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
972 sc->vreg[VREG_DIG].max_vdd, 0);
973 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800974 pr_err("%s increase failed (%d)\n",
975 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700976 return rc;
977 }
978 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
979 }
980
981 /*
982 * Update per-CPU core voltage. Don't do this for the hotplug path for
983 * which it should already be correct. Attempting to set it is bad
984 * because we don't know what CPU we are running on at this point, but
985 * the CPU regulator API requires we call it from the affected CPU.
986 */
987 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
988 && reason != SETRATE_HOTPLUG) {
989 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
990 sc->vreg[VREG_CORE].max_vdd);
991 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800992 pr_err("%s increase failed (%d)\n",
993 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700994 return rc;
995 }
996 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
997 }
998
999 return rc;
1000}
1001
1002/* Apply any per-cpu voltage decreases. */
1003static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1004 unsigned int vdd_dig, enum setrate_reason reason)
1005{
1006 struct scalable *sc = &scalable[cpu];
1007 int ret;
1008
1009 /*
1010 * Update per-CPU core voltage. This must be called on the CPU
1011 * that's being affected. Don't do this in the hotplug remove path,
1012 * where the rail is off and we're executing on the other CPU.
1013 */
1014 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1015 && reason != SETRATE_HOTPLUG) {
1016 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1017 sc->vreg[VREG_CORE].max_vdd);
1018 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001019 pr_err("%s decrease failed (%d)\n",
1020 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001021 return;
1022 }
1023 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1024 }
1025
1026 /* Decrease vdd_dig active-set vote. */
1027 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1028 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1029 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1030 sc->vreg[VREG_DIG].max_vdd, 0);
1031 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001032 pr_err("%s decrease failed (%d)\n",
1033 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001034 return;
1035 }
1036 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1037 }
1038
1039 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001040 * Decrease vdd_mem active-set after vdd_dig.
1041 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001042 */
1043 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1044 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1045 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1046 sc->vreg[VREG_MEM].max_vdd, 0);
1047 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001048 pr_err("%s decrease failed (%d)\n",
1049 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001050 return;
1051 }
1052 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1053 }
1054}
1055
1056static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1057{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001058 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001059}
1060
1061static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1062{
1063 unsigned int pll_vdd_dig;
1064
Stephen Boydc76158f2011-12-08 12:42:40 -08001065 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001066 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001067 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001068 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1069 else
1070 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1071
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001072 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1073}
1074
Tianyi Gouaded6432012-02-22 14:53:05 -08001075static unsigned int calculate_vdd_core(struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001076{
Tianyi Gouaded6432012-02-22 14:53:05 -08001077 return tgt->vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001078}
1079
1080/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001081static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1082 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001083{
1084 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1085 struct l2_level *tgt_l2_l;
1086 struct acpu_level *tgt;
1087 unsigned int vdd_mem, vdd_dig, vdd_core;
1088 unsigned long flags;
1089 int rc = 0;
1090
1091 if (cpu > num_possible_cpus()) {
1092 rc = -EINVAL;
1093 goto out;
1094 }
1095
1096 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1097 mutex_lock(&driver_lock);
1098
1099 strt_acpu_s = scalable[cpu].current_speed;
1100
1101 /* Return early if rate didn't change. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001102 if (rate == strt_acpu_s->khz)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001103 goto out;
1104
1105 /* Find target frequency. */
1106 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1107 if (tgt->speed.khz == rate) {
1108 tgt_acpu_s = &tgt->speed;
1109 break;
1110 }
1111 }
1112 if (tgt->speed.khz == 0) {
1113 rc = -EINVAL;
1114 goto out;
1115 }
1116
1117 /* Calculate voltage requirements for the current CPU. */
1118 vdd_mem = calculate_vdd_mem(tgt);
1119 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gouaded6432012-02-22 14:53:05 -08001120 vdd_core = calculate_vdd_core(tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001121
1122 /* Increase VDD levels if needed. */
1123 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1124 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1125 if (rc)
1126 goto out;
1127 }
1128
1129 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1130 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1131
1132 /* Set the CPU speed. */
1133 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1134
1135 /*
1136 * Update the L2 vote and apply the rate change. A spinlock is
1137 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001138 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001139 * and the driver_lock mutex is not acquired.
1140 */
1141 spin_lock_irqsave(&l2_lock, flags);
1142 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1143 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1144 spin_unlock_irqrestore(&l2_lock, flags);
1145
1146 /* Nothing else to do for power collapse or SWFI. */
1147 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1148 goto out;
1149
1150 /* Update bus bandwith request. */
1151 set_bus_bw(tgt_l2_l->bw_level);
1152
1153 /* Drop VDD levels if we can. */
1154 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1155
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001156 pr_debug("ACPU%d speed change complete\n", cpu);
1157
1158out:
1159 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1160 mutex_unlock(&driver_lock);
1161 return rc;
1162}
1163
1164/* Initialize a HFPLL at a given rate and enable it. */
1165static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1166{
1167 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1168
1169 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001170 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001171
1172 /* Configure PLL parameters for integer mode. */
1173 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1174 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1175 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1176
1177 /* Program droop controller. */
1178 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1179
1180 /* Set an initial rate and enable the PLL. */
1181 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001182 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001183}
1184
1185/* Voltage regulator initialization. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001186static void __init regulator_init(struct acpu_level *lvl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001187{
1188 int cpu, ret;
1189 struct scalable *sc;
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001190 unsigned int vdd_mem, vdd_dig, vdd_core;
1191
1192 vdd_mem = calculate_vdd_mem(lvl);
1193 vdd_dig = calculate_vdd_dig(lvl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001194
1195 for_each_possible_cpu(cpu) {
1196 sc = &scalable[cpu];
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001197
1198 /* Set initial vdd_mem vote. */
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) {
1203 pr_err("%s initialization failed (%d)\n",
1204 sc->vreg[VREG_MEM].name, ret);
1205 BUG();
1206 }
1207 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1208
1209 /* Set initial vdd_dig vote. */
1210 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1211 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1212 sc->vreg[VREG_DIG].max_vdd, 0);
1213 if (ret) {
1214 pr_err("%s initialization failed (%d)\n",
1215 sc->vreg[VREG_DIG].name, ret);
1216 BUG();
1217 }
1218 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1219
1220 /* Setup Krait CPU regulators and initial core voltage. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001221 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1222 sc->vreg[VREG_CORE].name);
1223 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1224 pr_err("regulator_get(%s) failed (%ld)\n",
1225 sc->vreg[VREG_CORE].name,
1226 PTR_ERR(sc->vreg[VREG_CORE].reg));
1227 BUG();
1228 }
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001229 vdd_core = calculate_vdd_core(lvl);
1230 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001231 sc->vreg[VREG_CORE].max_vdd);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001232 if (ret) {
1233 pr_err("%s initialization failed (%d)\n",
1234 sc->vreg[VREG_CORE].name, ret);
1235 BUG();
1236 }
1237 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001238 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001239 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001240 pr_err("regulator_enable(%s) failed (%d)\n",
1241 sc->vreg[VREG_CORE].name, ret);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001242 BUG();
1243 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001244 }
1245}
1246
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001247/* Set initial rate for a given core. */
1248static void __init init_clock_sources(struct scalable *sc,
1249 struct core_speed *tgt_s)
1250{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001251 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001252
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001253 /* Select PLL8 as AUX source input to the secondary MUX. */
1254 writel_relaxed(0x3, sc->aux_clk_sel);
1255
1256 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001257 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001258 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001259 hfpll_init(sc, tgt_s);
1260
1261 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001262 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001263 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001264 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001266 /* Switch to the target clock source. */
1267 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001268 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1269 sc->current_speed = tgt_s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001270}
1271
Matt Wagantall8e726c72011-08-06 00:49:28 -07001272static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001273{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001274 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001275 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001276
1277 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1278 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001279}
1280
1281/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001282static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001283{
1284 int ret;
1285
1286 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1287 if (!bus_perf_client) {
1288 pr_err("unable to register bus client\n");
1289 BUG();
1290 }
1291
Stephen Boydcfe192b2011-12-09 21:47:14 -08001292 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001293 if (ret)
1294 pr_err("initial bandwidth request failed (%d)\n", ret);
1295}
1296
1297#ifdef CONFIG_CPU_FREQ_MSM
1298static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1299
1300static void __init cpufreq_table_init(void)
1301{
1302 int cpu;
1303
1304 for_each_possible_cpu(cpu) {
1305 int i, freq_cnt = 0;
1306 /* Construct the freq_table tables from acpu_freq_tbl. */
1307 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1308 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1309 if (acpu_freq_tbl[i].use_for_scaling) {
1310 freq_table[cpu][freq_cnt].index = freq_cnt;
1311 freq_table[cpu][freq_cnt].frequency
1312 = acpu_freq_tbl[i].speed.khz;
1313 freq_cnt++;
1314 }
1315 }
1316 /* freq_table not big enough to store all usable freqs. */
1317 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1318
1319 freq_table[cpu][freq_cnt].index = freq_cnt;
1320 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1321
1322 pr_info("CPU%d: %d scaling frequencies supported.\n",
1323 cpu, freq_cnt);
1324
1325 /* Register table with CPUFreq. */
1326 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1327 }
1328}
1329#else
1330static void __init cpufreq_table_init(void) {}
1331#endif
1332
1333#define HOT_UNPLUG_KHZ STBY_KHZ
1334static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1335 unsigned long action, void *hcpu)
1336{
1337 static int prev_khz[NR_CPUS];
1338 static int prev_pri_src[NR_CPUS];
1339 static int prev_sec_src[NR_CPUS];
1340 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001341
1342 switch (action) {
1343 case CPU_DYING:
1344 case CPU_DYING_FROZEN:
1345 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001346 * On Krait v1 and 8064v1, the primary and secondary muxes must
1347 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001348 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001349 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1351 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1352 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1353 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1354 }
1355 break;
1356 case CPU_DEAD:
1357 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001358 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001359 /* Fall through. */
1360 case CPU_UP_CANCELED:
1361 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001362 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001363 break;
1364 case CPU_UP_PREPARE:
1365 case CPU_UP_PREPARE_FROZEN:
1366 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001367 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001368 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001369 break;
1370 case CPU_STARTING:
1371 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001372 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001373 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1374 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1375 }
1376 break;
1377 default:
1378 break;
1379 }
1380
1381 return NOTIFY_OK;
1382}
1383
1384static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1385 .notifier_call = acpuclock_cpu_callback,
1386};
1387
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001388static const int krait_needs_vmin(void)
1389{
1390 switch (read_cpuid_id()) {
1391 case 0x511F04D0:
1392 case 0x511F04D1:
1393 case 0x510F06F0:
1394 return 1;
1395 default:
1396 return 0;
1397 };
1398}
1399
Stephen Boydaefb8de2012-01-05 19:05:01 -08001400static void kraitv2_apply_vmin(struct acpu_level *tbl)
1401{
1402 for (; tbl->speed.khz != 0; tbl++)
1403 if (tbl->vdd_core < 1150000)
1404 tbl->vdd_core = 1150000;
1405}
1406
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001407static struct acpu_level * __init select_freq_plan(void)
1408{
1409 struct acpu_level *l, *max_acpu_level = NULL;
1410
1411 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001412 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001413 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001414 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001415
1416 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1417 pvs = (pte_efuse >> 10) & 0x7;
1418 if (pvs == 0x7)
1419 pvs = (pte_efuse >> 13) & 0x7;
1420
1421 switch (pvs) {
1422 case 0x0:
1423 case 0x7:
1424 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001425 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1426 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001427 break;
1428 case 0x1:
1429 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001430 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001431 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001432 break;
1433 case 0x3:
1434 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001435 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001436 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001437 break;
1438 default:
1439 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001440 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1441 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001442 break;
1443 }
1444
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001445 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001446 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001447 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001448 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1449 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1450 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001451 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001452 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1453 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1454 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001455 } else if (cpu_is_apq8064()) {
1456 scalable = scalable_8064;
1457 acpu_freq_tbl = acpu_freq_tbl_8064;
1458 l2_freq_tbl = l2_freq_tbl_8064;
1459 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001460 } else if (cpu_is_msm8627()) {
1461 scalable = scalable_8627;
1462 acpu_freq_tbl = acpu_freq_tbl_8627;
1463 l2_freq_tbl = l2_freq_tbl_8627;
1464 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001465 } else if (cpu_is_msm8930()) {
1466 scalable = scalable_8930;
1467 acpu_freq_tbl = acpu_freq_tbl_8930;
1468 l2_freq_tbl = l2_freq_tbl_8930;
1469 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001470 } else {
1471 BUG();
1472 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001473 if (krait_needs_vmin())
1474 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001475
1476 /* Find the max supported scaling frequency. */
1477 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1478 if (l->use_for_scaling)
1479 max_acpu_level = l;
1480 BUG_ON(!max_acpu_level);
1481 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1482
1483 return max_acpu_level;
1484}
1485
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001486static struct acpuclk_data acpuclk_8960_data = {
1487 .set_rate = acpuclk_8960_set_rate,
1488 .get_rate = acpuclk_8960_get_rate,
1489 .power_collapse_khz = STBY_KHZ,
1490 .wait_for_irq_khz = STBY_KHZ,
1491};
1492
Matt Wagantallec57f062011-08-16 23:54:46 -07001493static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001494{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001495 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001496
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001497 regulator_init(max_acpu_level);
Stephen Boydcfe192b2011-12-09 21:47:14 -08001498 bus_init(max_acpu_level->l2_level->bw_level);
1499
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001500 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1501 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001502
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001503 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001504
1505 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001506 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001507
1508 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001509}
Matt Wagantallec57f062011-08-16 23:54:46 -07001510
1511struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1512 .init = acpuclk_8960_init,
1513};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001514
1515struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1516 .init = acpuclk_8960_init,
1517};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001518
1519struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1520 .init = acpuclk_8960_init,
1521};