blob: 8d35148eca218dd6d7eb0de2e248b5cbcc4f1dde [file] [log] [blame]
Stephen Boydaefb8de2012-01-05 19:05:01 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#define pr_fmt(fmt) "%s: " fmt, __func__
14
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/io.h>
18#include <linux/delay.h>
19#include <linux/mutex.h>
20#include <linux/err.h>
21#include <linux/errno.h>
22#include <linux/cpufreq.h>
23#include <linux/cpu.h>
24#include <linux/regulator/consumer.h>
25
26#include <asm/mach-types.h>
27#include <asm/cpu.h>
28
29#include <mach/board.h>
30#include <mach/msm_iomap.h>
31#include <mach/rpm-regulator.h>
32#include <mach/msm_bus.h>
33#include <mach/msm_bus_board.h>
34#include <mach/socinfo.h>
Stephen Boyd469ed3e2011-09-29 16:41:19 -070035#include <mach/msm-krait-l2-accessors.h>
Matt Wagantallcb12c392011-10-19 10:32:07 -070036#include <mach/rpm-regulator.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38#include "acpuclock.h"
39
40/*
41 * Source IDs.
42 * These must be negative to not overlap with the source IDs
43 * used by the 8x60 local clock driver.
44 */
45#define PLL_8 0
46#define HFPLL -1
47#define QSB -2
48
49/* Mux source selects. */
50#define PRI_SRC_SEL_SEC_SRC 0
51#define PRI_SRC_SEL_HFPLL 1
52#define PRI_SRC_SEL_HFPLL_DIV2 2
53#define SEC_SRC_SEL_QSB 0
Matt Wagantall65e5e4b2011-10-27 16:52:10 -070054#define SEC_SRC_SEL_AUX 2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055
56/* HFPLL registers offsets. */
57#define HFPLL_MODE 0x00
58#define HFPLL_CONFIG_CTL 0x04
59#define HFPLL_L_VAL 0x08
60#define HFPLL_M_VAL 0x0C
61#define HFPLL_N_VAL 0x10
62#define HFPLL_DROOP_CTL 0x14
63
64/* CP15 L2 indirect addresses. */
65#define L2CPMR_IADDR 0x500
66#define L2CPUCPMR_IADDR 0x501
67
68#define STBY_KHZ 1
69
70#define HFPLL_NOMINAL_VDD 1050000
Tianyi Goufff00402012-01-23 14:36:20 -080071#define HFPLL_LOW_VDD_8960 850000
72#define HFPLL_LOW_VDD 945000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070073#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
74
75#define SECCLKAGD BIT(4)
76
Matt Wagantalla518f8f2011-10-17 13:24:53 -070077/* PTE EFUSE register. */
78#define QFPROM_PTE_EFUSE_ADDR (MSM_QFPROM_BASE + 0x00C0)
79
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080enum scalables {
81 CPU0 = 0,
82 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070083 CPU2,
84 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085 L2,
86 NUM_SCALABLES
87};
88
89enum vregs {
90 VREG_CORE,
91 VREG_MEM,
92 VREG_DIG,
Matt Wagantallcb12c392011-10-19 10:32:07 -070093 VREG_HFPLL_A,
94 VREG_HFPLL_B,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095 NUM_VREG
96};
97
98struct vreg {
99 const char name[15];
100 const unsigned int max_vdd;
101 const int rpm_vreg_voter;
102 const int rpm_vreg_id;
103 struct regulator *reg;
104 unsigned int cur_vdd;
105};
106
107struct core_speed {
108 unsigned int khz;
109 int src;
110 unsigned int pri_src_sel;
111 unsigned int sec_src_sel;
112 unsigned int pll_l_val;
113};
114
115struct l2_level {
116 struct core_speed speed;
117 unsigned int vdd_dig;
118 unsigned int vdd_mem;
119 unsigned int bw_level;
120};
121
122struct acpu_level {
123 unsigned int use_for_scaling;
124 struct core_speed speed;
125 struct l2_level *l2_level;
126 unsigned int vdd_core;
127};
128
129struct scalable {
130 void * __iomem const hfpll_base;
131 void * __iomem const aux_clk_sel;
132 const uint32_t l2cpmr_iaddr;
133 struct core_speed *current_speed;
134 struct l2_level *l2_vote;
135 struct vreg vreg[NUM_VREG];
136 bool first_set_call;
137};
138
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700139static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140 [CPU0] = {
141 .hfpll_base = MSM_HFPLL_BASE + 0x200,
142 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
143 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800144 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700145 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
146 RPM_VREG_VOTER1,
147 RPM_VREG_ID_PM8921_L24 },
148 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
149 RPM_VREG_VOTER1,
150 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800151 .vreg[VREG_HFPLL_A] = { "hfpll0_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700152 RPM_VREG_VOTER1,
153 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800154 .vreg[VREG_HFPLL_B] = { "hfpll0_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700155 RPM_VREG_VOTER1,
156 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700157 },
158 [CPU1] = {
159 .hfpll_base = MSM_HFPLL_BASE + 0x300,
160 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
161 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800162 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800163 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164 RPM_VREG_VOTER2,
165 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800166 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167 RPM_VREG_VOTER2,
168 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800169 .vreg[VREG_HFPLL_A] = { "hfpll1_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700170 RPM_VREG_VOTER2,
171 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800172 .vreg[VREG_HFPLL_B] = { "hfpll1_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700173 RPM_VREG_VOTER2,
174 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175 },
176 [L2] = {
177 .hfpll_base = MSM_HFPLL_BASE + 0x400,
178 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
179 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800180 .vreg[VREG_HFPLL_A] = { "hfpll_l2_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700181 RPM_VREG_VOTER6,
182 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800183 .vreg[VREG_HFPLL_B] = { "hfpll_l2_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700184 RPM_VREG_VOTER6,
185 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186 },
187};
188
Stephen Boyd7ad84752011-08-05 14:04:28 -0700189static DEFINE_MUTEX(driver_lock);
190static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700192static struct scalable scalable_8064[] = {
193 [CPU0] = {
194 .hfpll_base = MSM_HFPLL_BASE + 0x200,
195 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
196 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800197 .vreg[VREG_CORE] = { "krait0", 1300000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700198 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
199 RPM_VREG_VOTER1,
200 RPM_VREG_ID_PM8921_L24 },
201 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
202 RPM_VREG_VOTER1,
203 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800204 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800205 RPM_VREG_VOTER1,
206 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700207 },
208 [CPU1] = {
209 .hfpll_base = MSM_HFPLL_BASE + 0x240,
210 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
211 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800212 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800213 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700214 RPM_VREG_VOTER2,
215 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800216 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700217 RPM_VREG_VOTER2,
218 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800219 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800220 RPM_VREG_VOTER2,
221 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700222 },
223 [CPU2] = {
224 .hfpll_base = MSM_HFPLL_BASE + 0x280,
225 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
226 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800227 .vreg[VREG_CORE] = { "krait2", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800228 .vreg[VREG_MEM] = { "krait2_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700229 RPM_VREG_VOTER4,
230 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800231 .vreg[VREG_DIG] = { "krait2_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700232 RPM_VREG_VOTER4,
233 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800234 .vreg[VREG_HFPLL_B] = { "hfpll2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800235 RPM_VREG_VOTER4,
236 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700237 },
238 [CPU3] = {
239 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
240 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
241 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800242 .vreg[VREG_CORE] = { "krait3", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800243 .vreg[VREG_MEM] = { "krait3_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700244 RPM_VREG_VOTER5,
245 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800246 .vreg[VREG_DIG] = { "krait3_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700247 RPM_VREG_VOTER5,
248 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800249 .vreg[VREG_HFPLL_B] = { "hfpll3", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800250 RPM_VREG_VOTER5,
251 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700252 },
253 [L2] = {
254 .hfpll_base = MSM_HFPLL_BASE + 0x300,
255 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
256 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800257 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800258 RPM_VREG_VOTER6,
259 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700260 },
261};
262
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800263static struct scalable scalable_8930[] = {
264 [CPU0] = {
265 .hfpll_base = MSM_HFPLL_BASE + 0x200,
266 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
267 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
268 .vreg[VREG_CORE] = { "krait0", 1300000 },
269 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
270 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800271 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800272 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
273 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800274 RPM_VREG_ID_PM8038_S1 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800275 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800276 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800277 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800278 },
279 [CPU1] = {
280 .hfpll_base = MSM_HFPLL_BASE + 0x300,
281 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
282 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
283 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800284 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800285 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800286 RPM_VREG_ID_PM8038_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800287 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800288 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800289 RPM_VREG_ID_PM8038_S1 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800290 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800291 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800292 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800293 },
294 [L2] = {
295 .hfpll_base = MSM_HFPLL_BASE + 0x400,
296 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
297 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800298 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800299 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800300 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800301 },
302};
303
Tianyi Goue0b34de2011-12-20 11:20:10 -0800304/*TODO: Update the rpm vreg id when the rpm driver is ready */
305static struct scalable scalable_8627[] = {
306 [CPU0] = {
307 .hfpll_base = MSM_HFPLL_BASE + 0x200,
308 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
309 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
310 .vreg[VREG_CORE] = { "krait0", 1300000 },
311 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
312 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800313 RPM_VREG_ID_PM8038_L24 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800314 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
315 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800316 RPM_VREG_ID_PM8038_S1 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800317 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800318 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800319 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800320 },
321 [CPU1] = {
322 .hfpll_base = MSM_HFPLL_BASE + 0x300,
323 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
324 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
325 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800326 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800327 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800328 RPM_VREG_ID_PM8038_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800329 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800330 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800331 RPM_VREG_ID_PM8038_S1 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800332 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800333 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800334 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800335 },
336 [L2] = {
337 .hfpll_base = MSM_HFPLL_BASE + 0x400,
338 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
339 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800340 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800341 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800342 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800343 },
344};
345
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700346static struct scalable *scalable;
347static struct l2_level *l2_freq_tbl;
348static struct acpu_level *acpu_freq_tbl;
349static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700350
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700351/* Instantaneous bandwidth requests in MB/s. */
352#define BW_MBPS(_bw) \
353 { \
354 .vectors = (struct msm_bus_vectors[]){ \
355 {\
356 .src = MSM_BUS_MASTER_AMPSS_M0, \
357 .dst = MSM_BUS_SLAVE_EBI_CH0, \
358 .ib = (_bw) * 1000000UL, \
359 .ab = (_bw) * 100000UL, \
360 }, \
361 { \
362 .src = MSM_BUS_MASTER_AMPSS_M1, \
363 .dst = MSM_BUS_SLAVE_EBI_CH0, \
364 .ib = (_bw) * 1000000UL, \
365 .ab = (_bw) * 100000UL, \
366 }, \
367 }, \
368 .num_paths = 2, \
369 }
370static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800371 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
372 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
373 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
374 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
375 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
376 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
377 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800378 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700379};
380
381static struct msm_bus_scale_pdata bus_client_pdata = {
382 .usecase = bw_level_tbl,
383 .num_usecases = ARRAY_SIZE(bw_level_tbl),
384 .active_only = 1,
385 .name = "acpuclock",
386};
387
388static uint32_t bus_perf_client;
389
390/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800391#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
392static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700393 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700394 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700395 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
396 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
397 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
398 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
399 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
400 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700401 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700402 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
403 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
404 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700405};
406
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800407static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
408 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
409 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
410 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
411 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
412 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
413 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
414 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
415 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
416 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
417 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
418 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
419 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
420 { 0, { 0 } }
421};
422
423static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
424 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
425 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
426 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
427 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
428 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
429 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
430 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
431 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
432 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
433 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
434 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
435 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700436 { 0, { 0 } }
437};
438
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800439#undef L2
440#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
441static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
442 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
443 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800444 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
445 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
446 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800447 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800448 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
449 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
450 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
451 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
452 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
453 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
454 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
455 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
456 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
457 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
458 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800459 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
460 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
461 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800462};
463
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800464static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800465 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
466 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800467 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
468 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
469 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
470 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
471 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
472 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
473 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
474 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
475 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
476 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
477 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
478 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
479 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800480 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800481 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800482 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800483 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800484 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800485 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800486 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1237500 },
487 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800488 { 0, { 0 } }
489};
490
491static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800492 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
493 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800494 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
495 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
496 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
497 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
498 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
499 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
500 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
501 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
502 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
503 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
504 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
505 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
506 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800507 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800508 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800509 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1150000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800510 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1175000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800511 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800512 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800513 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1187500 },
514 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800515 { 0, { 0 } }
516};
517
Stephen Boyd5766f682011-12-27 19:21:08 -0800518static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800519 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
520 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800521 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
522 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
523 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
524 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
525 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
526 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
527 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
528 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
529 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
530 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
531 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
532 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
533 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800534 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800535 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800536 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1100000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800537 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1125000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800538 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800539 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1137500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800540 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1137500 },
541 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800542 { 0, { 0 } }
543};
544
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700545/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
546#undef L2
547#define L2(x) (&l2_freq_tbl_8064[(x)])
548static struct l2_level l2_freq_tbl_8064[] = {
549 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800550 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
551 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
552 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
553 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700554 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800555 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
556 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
557 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
558 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
559 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
560 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
561 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
562 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
563 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
564 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700565};
566
567/* TODO: Update core voltages when data is available. */
568static struct acpu_level acpu_freq_tbl_8064[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800569 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
570 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
571 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
572 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
573 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
574 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
575 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
576 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
577 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
578 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
579 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
580 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
581 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
582 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
583 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
584 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
585 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
586 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
587 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
588 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
589 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
590 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
591 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700592 { 0, { 0 } }
593};
594
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800595/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
596#undef L2
597#define L2(x) (&l2_freq_tbl_8930[(x)])
598static struct l2_level l2_freq_tbl_8930[] = {
599 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
600 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
601 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
602 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
603 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
604 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
605 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
606 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
607 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
608 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
609 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
610 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
611 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
612 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
613 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
614 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
615 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
616};
617
618/* TODO: Update core voltages when data is available. */
619static struct acpu_level acpu_freq_tbl_8930[] = {
620 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
621 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
622 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
623 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
624 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
625 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
626 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
627 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
628 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
629 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
630 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
631 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
632 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
633 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
634 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
635 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
636 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
637 { 0, { 0 } }
638};
639
Tianyi Goue0b34de2011-12-20 11:20:10 -0800640/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
641#undef L2
642#define L2(x) (&l2_freq_tbl_8627[(x)])
643static struct l2_level l2_freq_tbl_8627[] = {
644 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
645 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
646 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
647 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
648 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
649 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
650 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
651 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 3 },
652 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 3 },
653 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
654 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
655 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 4 },
656 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 4 },
657};
658
659/* TODO: Update core voltages when data is available. */
660static struct acpu_level acpu_freq_tbl_8627[] = {
661 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
662 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
663 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
664 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
665 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
666 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
667 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
668 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
669 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
670 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
671 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
672 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
673 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
674 { 0, { 0 } }
675};
676
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700677static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700678{
679 return scalable[cpu].current_speed->khz;
680}
681
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700682/* Get the selected source on primary MUX. */
683static int get_pri_clk_src(struct scalable *sc)
684{
685 uint32_t regval;
686
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700687 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700688 return regval & 0x3;
689}
690
691/* Set the selected source on primary MUX. */
692static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
693{
694 uint32_t regval;
695
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700696 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700697 regval &= ~0x3;
698 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700699 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700700 /* Wait for switch to complete. */
701 mb();
702 udelay(1);
703}
704
705/* Get the selected source on secondary MUX. */
706static int get_sec_clk_src(struct scalable *sc)
707{
708 uint32_t regval;
709
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700710 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700711 return (regval >> 2) & 0x3;
712}
713
714/* Set the selected source on secondary MUX. */
715static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
716{
717 uint32_t regval;
718
719 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700720 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700722 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700723
724 /* Program the MUX. */
725 regval &= ~(0x3 << 2);
726 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700727 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700728
729 /* Wait for switch to complete. */
730 mb();
731 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700732
733 /* Re-enable secondary source clock gating. */
734 regval &= ~SECCLKAGD;
735 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700736}
737
738/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800739static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700740{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700741 int rc;
742
Matt Wagantallc1021762012-01-31 20:02:02 -0800743 if (!skip_regulators) {
744 if (cpu_is_msm8960()) {
745 rc = rpm_vreg_set_voltage(
746 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
747 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
748 2100000,
749 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
750 if (rc)
751 pr_err("%s regulator enable failed (%d)\n",
752 sc->vreg[VREG_HFPLL_A].name, rc);
753 }
754 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
755 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
756 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800757 if (rc)
758 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800759 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800760 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700761 /* Disable PLL bypass mode. */
762 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
763
764 /*
765 * H/W requires a 5us delay between disabling the bypass and
766 * de-asserting the reset. Delay 10us just to be safe.
767 */
768 mb();
769 udelay(10);
770
771 /* De-assert active-low PLL reset. */
772 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
773
774 /* Wait for PLL to lock. */
775 mb();
776 udelay(60);
777
778 /* Enable PLL output. */
779 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
780}
781
782/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800783static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700784{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700785 int rc;
786
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700787 /*
788 * Disable the PLL output, disable test mode, enable
789 * the bypass mode, and assert the reset.
790 */
791 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700792
Matt Wagantallc1021762012-01-31 20:02:02 -0800793 if (!skip_regulators) {
794 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
795 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800796 0, 0);
797 if (rc)
798 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800799 sc->vreg[VREG_HFPLL_B].name, rc);
800
801 if (cpu_is_msm8960()) {
802 rc = rpm_vreg_set_voltage(
803 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
804 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
805 0, 0, 0);
806 if (rc)
807 pr_err("%s regulator enable failed (%d)\n",
808 sc->vreg[VREG_HFPLL_A].name, rc);
809 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800810 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811}
812
813/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
814static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
815{
816 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
817}
818
819/* Return the L2 speed that should be applied. */
820static struct l2_level *compute_l2_level(struct scalable *sc,
821 struct l2_level *vote_l)
822{
823 struct l2_level *new_l;
824 int cpu;
825
826 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700827 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828
829 /* Find max L2 speed vote. */
830 sc->l2_vote = vote_l;
831 new_l = l2_freq_tbl;
832 for_each_present_cpu(cpu)
833 new_l = max(new_l, scalable[cpu].l2_vote);
834
835 return new_l;
836}
837
838/* Update the bus bandwidth request. */
839static void set_bus_bw(unsigned int bw)
840{
841 int ret;
842
843 /* Bounds check. */
844 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
845 pr_err("invalid bandwidth request (%d)\n", bw);
846 return;
847 }
848
849 /* Update bandwidth if request has changed. This may sleep. */
850 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
851 if (ret)
852 pr_err("bandwidth request failed (%d)\n", ret);
853}
854
855/* Set the CPU or L2 clock speed. */
856static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
857 enum setrate_reason reason)
858{
859 struct core_speed *strt_s = sc->current_speed;
860
861 if (tgt_s == strt_s)
862 return;
863
864 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700865 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700866 * Move to an always-on source running at a frequency that does
867 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700869 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700870 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
871
872 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800873 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800875 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700876
877 /* Move CPU to HFPLL source. */
878 set_pri_clk_src(sc, tgt_s->pri_src_sel);
879 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880 /*
881 * If responding to CPU_DEAD we must be running on another
882 * CPU. Therefore, we can't access the downed CPU's CP15
883 * clock MUX registers from here and can't change clock sources.
884 * Just turn off the PLL- since the CPU is down already, halting
885 * its clock should be safe.
886 */
887 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
888 set_sec_clk_src(sc, tgt_s->sec_src_sel);
889 set_pri_clk_src(sc, tgt_s->pri_src_sel);
890 }
Matt Wagantallc1021762012-01-31 20:02:02 -0800891 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700892 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
893 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800894 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895 /*
896 * If responding to CPU_UP_PREPARE, we can't change CP15
897 * registers for the CPU that's coming up since we're not
898 * running on that CPU. That's okay though, since the MUX
899 * source was not changed on the way down, either.
900 */
901 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
902 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700904 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
905 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 }
907
908 sc->current_speed = tgt_s;
909}
910
911/* Apply any per-cpu voltage increases. */
912static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
913 unsigned int vdd_dig, enum setrate_reason reason)
914{
915 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700916 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700917
918 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700919 * Increase vdd_mem active-set before vdd_dig.
920 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700921 */
922 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
923 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
924 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
925 sc->vreg[VREG_MEM].max_vdd, 0);
926 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800927 pr_err("%s increase failed (%d)\n",
928 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700929 return rc;
930 }
931 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
932 }
933
934 /* Increase vdd_dig active-set vote. */
935 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
936 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
937 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
938 sc->vreg[VREG_DIG].max_vdd, 0);
939 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800940 pr_err("%s increase failed (%d)\n",
941 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700942 return rc;
943 }
944 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
945 }
946
947 /*
948 * Update per-CPU core voltage. Don't do this for the hotplug path for
949 * which it should already be correct. Attempting to set it is bad
950 * because we don't know what CPU we are running on at this point, but
951 * the CPU regulator API requires we call it from the affected CPU.
952 */
953 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
954 && reason != SETRATE_HOTPLUG) {
955 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
956 sc->vreg[VREG_CORE].max_vdd);
957 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800958 pr_err("%s increase failed (%d)\n",
959 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700960 return rc;
961 }
962 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
963 }
964
965 return rc;
966}
967
968/* Apply any per-cpu voltage decreases. */
969static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
970 unsigned int vdd_dig, enum setrate_reason reason)
971{
972 struct scalable *sc = &scalable[cpu];
973 int ret;
974
975 /*
976 * Update per-CPU core voltage. This must be called on the CPU
977 * that's being affected. Don't do this in the hotplug remove path,
978 * where the rail is off and we're executing on the other CPU.
979 */
980 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
981 && reason != SETRATE_HOTPLUG) {
982 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
983 sc->vreg[VREG_CORE].max_vdd);
984 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800985 pr_err("%s decrease failed (%d)\n",
986 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987 return;
988 }
989 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
990 }
991
992 /* Decrease vdd_dig active-set vote. */
993 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
994 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
995 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
996 sc->vreg[VREG_DIG].max_vdd, 0);
997 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800998 pr_err("%s decrease failed (%d)\n",
999 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001000 return;
1001 }
1002 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1003 }
1004
1005 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001006 * Decrease vdd_mem active-set after vdd_dig.
1007 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001008 */
1009 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1010 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1011 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1012 sc->vreg[VREG_MEM].max_vdd, 0);
1013 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001014 pr_err("%s decrease failed (%d)\n",
1015 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001016 return;
1017 }
1018 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1019 }
1020}
1021
1022static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1023{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001024 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001025}
1026
1027static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1028{
1029 unsigned int pll_vdd_dig;
1030
Stephen Boydc76158f2011-12-08 12:42:40 -08001031 if (tgt->l2_level->speed.src != HFPLL)
1032 pll_vdd_dig = 0;
1033 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001034 pll_vdd_dig = HFPLL_NOMINAL_VDD;
Tianyi Goufff00402012-01-23 14:36:20 -08001035 else {
1036 if (cpu_is_msm8960())
1037 pll_vdd_dig = HFPLL_LOW_VDD_8960;
1038 else
1039 pll_vdd_dig = HFPLL_LOW_VDD;
1040 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001041 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1042}
1043
1044static unsigned int calculate_vdd_core(struct acpu_level *tgt)
1045{
1046 unsigned int pll_vdd_core;
1047
Stephen Boydc76158f2011-12-08 12:42:40 -08001048 if (tgt->speed.src != HFPLL)
1049 pll_vdd_core = 0;
1050 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001051 pll_vdd_core = HFPLL_NOMINAL_VDD;
Tianyi Goufff00402012-01-23 14:36:20 -08001052 else {
1053 if (cpu_is_msm8960())
1054 pll_vdd_core = HFPLL_LOW_VDD_8960;
1055 else
1056 pll_vdd_core = HFPLL_LOW_VDD;
1057 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001058 return max(tgt->vdd_core, pll_vdd_core);
1059}
1060
1061/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001062static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1063 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001064{
1065 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1066 struct l2_level *tgt_l2_l;
1067 struct acpu_level *tgt;
1068 unsigned int vdd_mem, vdd_dig, vdd_core;
1069 unsigned long flags;
1070 int rc = 0;
1071
1072 if (cpu > num_possible_cpus()) {
1073 rc = -EINVAL;
1074 goto out;
1075 }
1076
1077 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1078 mutex_lock(&driver_lock);
1079
1080 strt_acpu_s = scalable[cpu].current_speed;
1081
1082 /* Return early if rate didn't change. */
1083 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1084 goto out;
1085
1086 /* Find target frequency. */
1087 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1088 if (tgt->speed.khz == rate) {
1089 tgt_acpu_s = &tgt->speed;
1090 break;
1091 }
1092 }
1093 if (tgt->speed.khz == 0) {
1094 rc = -EINVAL;
1095 goto out;
1096 }
1097
1098 /* Calculate voltage requirements for the current CPU. */
1099 vdd_mem = calculate_vdd_mem(tgt);
1100 vdd_dig = calculate_vdd_dig(tgt);
1101 vdd_core = calculate_vdd_core(tgt);
1102
1103 /* Increase VDD levels if needed. */
1104 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1105 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1106 if (rc)
1107 goto out;
1108 }
1109
1110 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1111 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1112
1113 /* Set the CPU speed. */
1114 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1115
1116 /*
1117 * Update the L2 vote and apply the rate change. A spinlock is
1118 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001119 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001120 * and the driver_lock mutex is not acquired.
1121 */
1122 spin_lock_irqsave(&l2_lock, flags);
1123 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1124 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1125 spin_unlock_irqrestore(&l2_lock, flags);
1126
1127 /* Nothing else to do for power collapse or SWFI. */
1128 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1129 goto out;
1130
1131 /* Update bus bandwith request. */
1132 set_bus_bw(tgt_l2_l->bw_level);
1133
1134 /* Drop VDD levels if we can. */
1135 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1136
1137 scalable[cpu].first_set_call = false;
1138 pr_debug("ACPU%d speed change complete\n", cpu);
1139
1140out:
1141 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1142 mutex_unlock(&driver_lock);
1143 return rc;
1144}
1145
1146/* Initialize a HFPLL at a given rate and enable it. */
1147static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1148{
1149 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1150
1151 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001152 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001153
1154 /* Configure PLL parameters for integer mode. */
1155 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1156 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1157 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1158
1159 /* Program droop controller. */
1160 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1161
1162 /* Set an initial rate and enable the PLL. */
1163 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001164 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001165}
1166
1167/* Voltage regulator initialization. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001168static void __init regulator_init(int set_vdd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001169{
1170 int cpu, ret;
1171 struct scalable *sc;
1172
1173 for_each_possible_cpu(cpu) {
1174 sc = &scalable[cpu];
1175 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1176 sc->vreg[VREG_CORE].name);
1177 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1178 pr_err("regulator_get(%s) failed (%ld)\n",
1179 sc->vreg[VREG_CORE].name,
1180 PTR_ERR(sc->vreg[VREG_CORE].reg));
1181 BUG();
1182 }
1183
1184 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
Stephen Boydcfe192b2011-12-09 21:47:14 -08001185 set_vdd,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001186 sc->vreg[VREG_CORE].max_vdd);
1187 if (ret)
1188 pr_err("regulator_set_voltage(%s) failed"
1189 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1190
1191 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1192 if (ret)
1193 pr_err("regulator_enable(%s) failed (%d)\n",
1194 sc->vreg[VREG_CORE].name, ret);
1195 }
1196}
1197
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001198/* Set initial rate for a given core. */
1199static void __init init_clock_sources(struct scalable *sc,
1200 struct core_speed *tgt_s)
1201{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001202 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001203
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001204 /* Select PLL8 as AUX source input to the secondary MUX. */
1205 writel_relaxed(0x3, sc->aux_clk_sel);
1206
1207 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001208 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001209 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001210 hfpll_init(sc, tgt_s);
1211
1212 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001213 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001214 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001215 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001216
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001217 /* Switch to the target clock source. */
1218 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001219 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1220 sc->current_speed = tgt_s;
1221
1222 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001223 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1224 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 */
1226 sc->first_set_call = true;
1227}
1228
Matt Wagantall8e726c72011-08-06 00:49:28 -07001229static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001230{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001231 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001232 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001233
1234 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1235 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001236}
1237
1238/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001239static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001240{
1241 int ret;
1242
1243 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1244 if (!bus_perf_client) {
1245 pr_err("unable to register bus client\n");
1246 BUG();
1247 }
1248
Stephen Boydcfe192b2011-12-09 21:47:14 -08001249 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250 if (ret)
1251 pr_err("initial bandwidth request failed (%d)\n", ret);
1252}
1253
1254#ifdef CONFIG_CPU_FREQ_MSM
1255static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1256
1257static void __init cpufreq_table_init(void)
1258{
1259 int cpu;
1260
1261 for_each_possible_cpu(cpu) {
1262 int i, freq_cnt = 0;
1263 /* Construct the freq_table tables from acpu_freq_tbl. */
1264 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1265 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1266 if (acpu_freq_tbl[i].use_for_scaling) {
1267 freq_table[cpu][freq_cnt].index = freq_cnt;
1268 freq_table[cpu][freq_cnt].frequency
1269 = acpu_freq_tbl[i].speed.khz;
1270 freq_cnt++;
1271 }
1272 }
1273 /* freq_table not big enough to store all usable freqs. */
1274 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1275
1276 freq_table[cpu][freq_cnt].index = freq_cnt;
1277 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1278
1279 pr_info("CPU%d: %d scaling frequencies supported.\n",
1280 cpu, freq_cnt);
1281
1282 /* Register table with CPUFreq. */
1283 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1284 }
1285}
1286#else
1287static void __init cpufreq_table_init(void) {}
1288#endif
1289
1290#define HOT_UNPLUG_KHZ STBY_KHZ
1291static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1292 unsigned long action, void *hcpu)
1293{
1294 static int prev_khz[NR_CPUS];
1295 static int prev_pri_src[NR_CPUS];
1296 static int prev_sec_src[NR_CPUS];
1297 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001298
1299 switch (action) {
1300 case CPU_DYING:
1301 case CPU_DYING_FROZEN:
1302 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001303 * On Krait v1 and 8064v1, the primary and secondary muxes must
1304 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001305 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001306 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001307 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1308 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1309 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1310 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1311 }
1312 break;
1313 case CPU_DEAD:
1314 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001315 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001316 /* Fall through. */
1317 case CPU_UP_CANCELED:
1318 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001319 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001320 break;
1321 case CPU_UP_PREPARE:
1322 case CPU_UP_PREPARE_FROZEN:
1323 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001324 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001325 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001326 break;
1327 case CPU_STARTING:
1328 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001329 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001330 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1331 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1332 }
1333 break;
1334 default:
1335 break;
1336 }
1337
1338 return NOTIFY_OK;
1339}
1340
1341static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1342 .notifier_call = acpuclock_cpu_callback,
1343};
1344
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001345static const int krait_needs_vmin(void)
1346{
1347 switch (read_cpuid_id()) {
1348 case 0x511F04D0:
1349 case 0x511F04D1:
1350 case 0x510F06F0:
1351 return 1;
1352 default:
1353 return 0;
1354 };
1355}
1356
Stephen Boydaefb8de2012-01-05 19:05:01 -08001357static void kraitv2_apply_vmin(struct acpu_level *tbl)
1358{
1359 for (; tbl->speed.khz != 0; tbl++)
1360 if (tbl->vdd_core < 1150000)
1361 tbl->vdd_core = 1150000;
1362}
1363
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001364static struct acpu_level * __init select_freq_plan(void)
1365{
1366 struct acpu_level *l, *max_acpu_level = NULL;
1367
1368 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001369 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001370 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001371 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001372
1373 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1374 pvs = (pte_efuse >> 10) & 0x7;
1375 if (pvs == 0x7)
1376 pvs = (pte_efuse >> 13) & 0x7;
1377
1378 switch (pvs) {
1379 case 0x0:
1380 case 0x7:
1381 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001382 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1383 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001384 break;
1385 case 0x1:
1386 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001387 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001388 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001389 break;
1390 case 0x3:
1391 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001392 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001393 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001394 break;
1395 default:
1396 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001397 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1398 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001399 break;
1400 }
1401
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001402 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001403 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001404 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001405 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1406 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1407 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001408 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001409 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1410 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1411 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001412 } else if (cpu_is_apq8064()) {
1413 scalable = scalable_8064;
1414 acpu_freq_tbl = acpu_freq_tbl_8064;
1415 l2_freq_tbl = l2_freq_tbl_8064;
1416 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001417 } else if (cpu_is_msm8627()) {
1418 scalable = scalable_8627;
1419 acpu_freq_tbl = acpu_freq_tbl_8627;
1420 l2_freq_tbl = l2_freq_tbl_8627;
1421 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001422 } else if (cpu_is_msm8930()) {
1423 scalable = scalable_8930;
1424 acpu_freq_tbl = acpu_freq_tbl_8930;
1425 l2_freq_tbl = l2_freq_tbl_8930;
1426 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001427 } else {
1428 BUG();
1429 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001430 if (krait_needs_vmin())
1431 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001432
1433 /* Find the max supported scaling frequency. */
1434 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1435 if (l->use_for_scaling)
1436 max_acpu_level = l;
1437 BUG_ON(!max_acpu_level);
1438 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1439
1440 return max_acpu_level;
1441}
1442
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001443static struct acpuclk_data acpuclk_8960_data = {
1444 .set_rate = acpuclk_8960_set_rate,
1445 .get_rate = acpuclk_8960_get_rate,
1446 .power_collapse_khz = STBY_KHZ,
1447 .wait_for_irq_khz = STBY_KHZ,
1448};
1449
Matt Wagantallec57f062011-08-16 23:54:46 -07001450static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001451{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001452 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001453
1454 regulator_init(max_acpu_level->vdd_core);
1455 bus_init(max_acpu_level->l2_level->bw_level);
1456
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001457 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1458 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001459
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001460 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001461
1462 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001463 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001464
1465 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001466}
Matt Wagantallec57f062011-08-16 23:54:46 -07001467
1468struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1469 .init = acpuclk_8960_init,
1470};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001471
1472struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1473 .init = acpuclk_8960_init,
1474};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001475
1476struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1477 .init = acpuclk_8960_init,
1478};