blob: 0da03f9e1d7210d33ea794d26d83efd31afd4b4e [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];
145 bool first_set_call;
Tianyi Gou50705682012-02-21 17:51:50 -0800146 unsigned int *hfpll_vdd_tbl;
147};
148
149static unsigned int hfpll_vdd_tbl_8960[] = {
150 [HFPLL_VDD_NONE] = 0,
151 [HFPLL_VDD_LOW] = 850000,
152 [HFPLL_VDD_NOM] = 1050000
153};
154
155static unsigned int hfpll_vdd_tbl_8064[] = {
156 [HFPLL_VDD_NONE] = 0,
157 [HFPLL_VDD_LOW] = 945000,
158 [HFPLL_VDD_NOM] = 1050000
159};
160
161static unsigned int hfpll_vdd_dig_tbl_8930[] = {
162 [HFPLL_VDD_NONE] = LVL_NONE,
163 [HFPLL_VDD_LOW] = LVL_LOW,
164 [HFPLL_VDD_NOM] = LVL_NOM
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165};
166
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700167static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168 [CPU0] = {
169 .hfpll_base = MSM_HFPLL_BASE + 0x200,
170 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
171 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800172 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
174 RPM_VREG_VOTER1,
175 RPM_VREG_ID_PM8921_L24 },
176 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
177 RPM_VREG_VOTER1,
178 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800179 .vreg[VREG_HFPLL_A] = { "hfpll0_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700180 RPM_VREG_VOTER1,
181 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800182 .vreg[VREG_HFPLL_B] = { "hfpll0_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700183 RPM_VREG_VOTER1,
184 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 },
186 [CPU1] = {
187 .hfpll_base = MSM_HFPLL_BASE + 0x300,
188 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
189 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800190 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800191 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192 RPM_VREG_VOTER2,
193 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800194 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195 RPM_VREG_VOTER2,
196 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800197 .vreg[VREG_HFPLL_A] = { "hfpll1_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700198 RPM_VREG_VOTER2,
199 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800200 .vreg[VREG_HFPLL_B] = { "hfpll1_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700201 RPM_VREG_VOTER2,
202 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203 },
204 [L2] = {
205 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800206 .hfpll_vdd_tbl = hfpll_vdd_tbl_8960,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700207 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
208 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800209 .vreg[VREG_HFPLL_A] = { "hfpll_l2_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700210 RPM_VREG_VOTER6,
211 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800212 .vreg[VREG_HFPLL_B] = { "hfpll_l2_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700213 RPM_VREG_VOTER6,
214 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 },
216};
217
Stephen Boyd7ad84752011-08-05 14:04:28 -0700218static DEFINE_MUTEX(driver_lock);
219static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700220
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700221static struct scalable scalable_8064[] = {
222 [CPU0] = {
223 .hfpll_base = MSM_HFPLL_BASE + 0x200,
224 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
225 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800226 .vreg[VREG_CORE] = { "krait0", 1300000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700227 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
228 RPM_VREG_VOTER1,
229 RPM_VREG_ID_PM8921_L24 },
230 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
231 RPM_VREG_VOTER1,
232 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800233 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800234 RPM_VREG_VOTER1,
235 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700236 },
237 [CPU1] = {
238 .hfpll_base = MSM_HFPLL_BASE + 0x240,
239 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
240 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800241 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800242 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700243 RPM_VREG_VOTER2,
244 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800245 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700246 RPM_VREG_VOTER2,
247 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800248 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800249 RPM_VREG_VOTER2,
250 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700251 },
252 [CPU2] = {
253 .hfpll_base = MSM_HFPLL_BASE + 0x280,
254 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
255 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800256 .vreg[VREG_CORE] = { "krait2", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800257 .vreg[VREG_MEM] = { "krait2_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700258 RPM_VREG_VOTER4,
259 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800260 .vreg[VREG_DIG] = { "krait2_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700261 RPM_VREG_VOTER4,
262 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800263 .vreg[VREG_HFPLL_B] = { "hfpll2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800264 RPM_VREG_VOTER4,
265 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700266 },
267 [CPU3] = {
268 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
269 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
270 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800271 .vreg[VREG_CORE] = { "krait3", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800272 .vreg[VREG_MEM] = { "krait3_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700273 RPM_VREG_VOTER5,
274 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800275 .vreg[VREG_DIG] = { "krait3_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700276 RPM_VREG_VOTER5,
277 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800278 .vreg[VREG_HFPLL_B] = { "hfpll3", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800279 RPM_VREG_VOTER5,
280 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700281 },
282 [L2] = {
283 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800284 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700285 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
286 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800287 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800288 RPM_VREG_VOTER6,
289 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700290 },
291};
292
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800293static struct scalable scalable_8930[] = {
294 [CPU0] = {
295 .hfpll_base = MSM_HFPLL_BASE + 0x200,
296 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
297 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
298 .vreg[VREG_CORE] = { "krait0", 1300000 },
299 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
300 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800301 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800302 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800303 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800304 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
305 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800306 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800307 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800308 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800309 },
310 [CPU1] = {
311 .hfpll_base = MSM_HFPLL_BASE + 0x300,
312 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
313 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
314 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800315 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800316 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800317 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800318 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800319 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800320 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
321 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800322 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800323 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800324 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800325 },
326 [L2] = {
327 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800328 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800329 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
330 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800331 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800332 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800333 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800334 },
335};
336
Tianyi Goue0b34de2011-12-20 11:20:10 -0800337/*TODO: Update the rpm vreg id when the rpm driver is ready */
338static struct scalable scalable_8627[] = {
339 [CPU0] = {
340 .hfpll_base = MSM_HFPLL_BASE + 0x200,
341 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
342 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
343 .vreg[VREG_CORE] = { "krait0", 1300000 },
344 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
345 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800346 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800347 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800348 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800349 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
350 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800351 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800352 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800353 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800354 },
355 [CPU1] = {
356 .hfpll_base = MSM_HFPLL_BASE + 0x300,
357 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
358 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
359 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800360 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800361 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800362 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800363 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800364 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800365 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
366 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800367 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800368 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800369 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800370 },
371 [L2] = {
372 .hfpll_base = MSM_HFPLL_BASE + 0x400,
373 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
374 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800375 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800376 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800377 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800378 },
379};
380
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700381static struct scalable *scalable;
382static struct l2_level *l2_freq_tbl;
383static struct acpu_level *acpu_freq_tbl;
384static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700385
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700386/* Instantaneous bandwidth requests in MB/s. */
387#define BW_MBPS(_bw) \
388 { \
389 .vectors = (struct msm_bus_vectors[]){ \
390 {\
391 .src = MSM_BUS_MASTER_AMPSS_M0, \
392 .dst = MSM_BUS_SLAVE_EBI_CH0, \
393 .ib = (_bw) * 1000000UL, \
394 .ab = (_bw) * 100000UL, \
395 }, \
396 { \
397 .src = MSM_BUS_MASTER_AMPSS_M1, \
398 .dst = MSM_BUS_SLAVE_EBI_CH0, \
399 .ib = (_bw) * 1000000UL, \
400 .ab = (_bw) * 100000UL, \
401 }, \
402 }, \
403 .num_paths = 2, \
404 }
405static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800406 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
407 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
408 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
409 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
410 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
411 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
412 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800413 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700414};
415
416static struct msm_bus_scale_pdata bus_client_pdata = {
417 .usecase = bw_level_tbl,
418 .num_usecases = ARRAY_SIZE(bw_level_tbl),
419 .active_only = 1,
420 .name = "acpuclock",
421};
422
423static uint32_t bus_perf_client;
424
425/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800426#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
427static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700428 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700429 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700430 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
431 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
432 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
433 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
434 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
435 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700436 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700437 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
438 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
439 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700440};
441
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800442static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
443 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
444 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
445 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
446 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
447 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
448 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
449 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
450 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
451 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
452 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
453 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
454 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
455 { 0, { 0 } }
456};
457
458static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
459 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
460 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
461 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
462 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
463 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
464 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
465 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
466 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
467 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
468 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
469 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
470 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700471 { 0, { 0 } }
472};
473
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800474#undef L2
475#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
476static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
477 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
478 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800479 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
480 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
481 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800482 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800483 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
484 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
485 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
486 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
487 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
488 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
489 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
490 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
491 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
492 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
493 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800494 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
495 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
496 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800497};
498
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800499static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800500 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
501 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800502 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
503 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
504 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
505 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
506 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
507 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
508 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
509 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
510 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
511 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
512 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
513 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
514 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800515 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800516 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800517 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800518 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800519 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800520 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800521 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1237500 },
522 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800523 { 0, { 0 } }
524};
525
526static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800527 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
528 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800529 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
530 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
531 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
532 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
533 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
534 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
535 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
536 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
537 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
538 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
539 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
540 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
541 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800542 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800543 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800544 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1150000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800545 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1175000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800546 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800547 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800548 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1187500 },
549 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800550 { 0, { 0 } }
551};
552
Stephen Boyd5766f682011-12-27 19:21:08 -0800553static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800554 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
555 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800556 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
557 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
558 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
559 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
560 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
561 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
562 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
563 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
564 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
565 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
566 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
567 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
568 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800569 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800570 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800571 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1100000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800572 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1125000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800573 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800574 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1137500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800575 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1137500 },
576 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800577 { 0, { 0 } }
578};
579
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700580/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
581#undef L2
582#define L2(x) (&l2_freq_tbl_8064[(x)])
583static struct l2_level l2_freq_tbl_8064[] = {
584 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800585 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
586 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
587 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
588 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700589 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800590 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
591 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
592 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
593 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
594 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
595 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
596 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
597 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
598 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
599 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700600};
601
602/* TODO: Update core voltages when data is available. */
603static struct acpu_level acpu_freq_tbl_8064[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800604 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
605 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
606 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
607 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
608 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
609 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
610 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
611 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
612 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
613 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
614 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
615 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
616 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
617 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
618 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
619 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
620 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
621 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
622 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
623 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
624 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
625 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
626 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700627 { 0, { 0 } }
628};
629
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800630/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
631#undef L2
632#define L2(x) (&l2_freq_tbl_8930[(x)])
633static struct l2_level l2_freq_tbl_8930[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800634 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
635 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800636 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 2 },
637 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 2 },
638 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
Tianyi Gou50705682012-02-21 17:51:50 -0800639 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800640 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 4 },
641 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 4 },
642 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 4 },
643 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 4 },
644 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
645 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 7 },
646 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 7 },
647 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, LVL_HIGH, 1150000, 7 },
648 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, LVL_HIGH, 1150000, 7 },
649 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, LVL_HIGH, 1150000, 7 },
650 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, LVL_HIGH, 1150000, 7 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800651};
652
653/* TODO: Update core voltages when data is available. */
654static struct acpu_level acpu_freq_tbl_8930[] = {
655 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
656 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
657 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
658 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
659 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
660 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
661 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
662 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
663 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
664 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
665 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
666 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
667 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
668 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
669 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
670 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
671 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
672 { 0, { 0 } }
673};
674
Tianyi Goue0b34de2011-12-20 11:20:10 -0800675/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
676#undef L2
677#define L2(x) (&l2_freq_tbl_8627[(x)])
678static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800679 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
680 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
681 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
682 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
683 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
684 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
685 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
686 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
687 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
688 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
689 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
690 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
691 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800692};
693
694/* TODO: Update core voltages when data is available. */
695static struct acpu_level acpu_freq_tbl_8627[] = {
696 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
697 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
698 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
699 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
700 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
701 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
702 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
703 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
704 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
705 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
706 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
707 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
708 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
709 { 0, { 0 } }
710};
711
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700712static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700713{
714 return scalable[cpu].current_speed->khz;
715}
716
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700717/* Get the selected source on primary MUX. */
718static int get_pri_clk_src(struct scalable *sc)
719{
720 uint32_t regval;
721
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700722 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700723 return regval & 0x3;
724}
725
726/* Set the selected source on primary MUX. */
727static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
728{
729 uint32_t regval;
730
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700731 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700732 regval &= ~0x3;
733 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700734 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700735 /* Wait for switch to complete. */
736 mb();
737 udelay(1);
738}
739
740/* Get the selected source on secondary MUX. */
741static int get_sec_clk_src(struct scalable *sc)
742{
743 uint32_t regval;
744
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700745 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746 return (regval >> 2) & 0x3;
747}
748
749/* Set the selected source on secondary MUX. */
750static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
751{
752 uint32_t regval;
753
754 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700755 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700756 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700757 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700758
759 /* Program the MUX. */
760 regval &= ~(0x3 << 2);
761 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700762 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700763
764 /* Wait for switch to complete. */
765 mb();
766 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700767
768 /* Re-enable secondary source clock gating. */
769 regval &= ~SECCLKAGD;
770 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700771}
772
773/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800774static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700775{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700776 int rc;
777
Matt Wagantallc1021762012-01-31 20:02:02 -0800778 if (!skip_regulators) {
779 if (cpu_is_msm8960()) {
780 rc = rpm_vreg_set_voltage(
781 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
782 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
783 2100000,
784 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
785 if (rc)
786 pr_err("%s regulator enable failed (%d)\n",
787 sc->vreg[VREG_HFPLL_A].name, rc);
788 }
789 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
790 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
791 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800792 if (rc)
793 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800794 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800795 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700796 /* Disable PLL bypass mode. */
797 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
798
799 /*
800 * H/W requires a 5us delay between disabling the bypass and
801 * de-asserting the reset. Delay 10us just to be safe.
802 */
803 mb();
804 udelay(10);
805
806 /* De-assert active-low PLL reset. */
807 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
808
809 /* Wait for PLL to lock. */
810 mb();
811 udelay(60);
812
813 /* Enable PLL output. */
814 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
815}
816
817/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800818static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700819{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700820 int rc;
821
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700822 /*
823 * Disable the PLL output, disable test mode, enable
824 * the bypass mode, and assert the reset.
825 */
826 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700827
Matt Wagantallc1021762012-01-31 20:02:02 -0800828 if (!skip_regulators) {
829 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
830 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800831 0, 0);
832 if (rc)
833 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800834 sc->vreg[VREG_HFPLL_B].name, rc);
835
836 if (cpu_is_msm8960()) {
837 rc = rpm_vreg_set_voltage(
838 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
839 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
840 0, 0, 0);
841 if (rc)
842 pr_err("%s regulator enable failed (%d)\n",
843 sc->vreg[VREG_HFPLL_A].name, rc);
844 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800845 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700846}
847
848/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
849static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
850{
851 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
852}
853
854/* Return the L2 speed that should be applied. */
855static struct l2_level *compute_l2_level(struct scalable *sc,
856 struct l2_level *vote_l)
857{
858 struct l2_level *new_l;
859 int cpu;
860
861 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700862 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863
864 /* Find max L2 speed vote. */
865 sc->l2_vote = vote_l;
866 new_l = l2_freq_tbl;
867 for_each_present_cpu(cpu)
868 new_l = max(new_l, scalable[cpu].l2_vote);
869
870 return new_l;
871}
872
873/* Update the bus bandwidth request. */
874static void set_bus_bw(unsigned int bw)
875{
876 int ret;
877
878 /* Bounds check. */
879 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
880 pr_err("invalid bandwidth request (%d)\n", bw);
881 return;
882 }
883
884 /* Update bandwidth if request has changed. This may sleep. */
885 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
886 if (ret)
887 pr_err("bandwidth request failed (%d)\n", ret);
888}
889
890/* Set the CPU or L2 clock speed. */
891static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
892 enum setrate_reason reason)
893{
894 struct core_speed *strt_s = sc->current_speed;
895
896 if (tgt_s == strt_s)
897 return;
898
899 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700900 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700901 * Move to an always-on source running at a frequency that does
902 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700904 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700905 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
906
907 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800908 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800910 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911
912 /* Move CPU to HFPLL source. */
913 set_pri_clk_src(sc, tgt_s->pri_src_sel);
914 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700915 /*
916 * If responding to CPU_DEAD we must be running on another
917 * CPU. Therefore, we can't access the downed CPU's CP15
918 * clock MUX registers from here and can't change clock sources.
919 * Just turn off the PLL- since the CPU is down already, halting
920 * its clock should be safe.
921 */
922 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
923 set_sec_clk_src(sc, tgt_s->sec_src_sel);
924 set_pri_clk_src(sc, tgt_s->pri_src_sel);
925 }
Matt Wagantallc1021762012-01-31 20:02:02 -0800926 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700927 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
928 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800929 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 /*
931 * If responding to CPU_UP_PREPARE, we can't change CP15
932 * registers for the CPU that's coming up since we're not
933 * running on that CPU. That's okay though, since the MUX
934 * source was not changed on the way down, either.
935 */
936 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
937 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700938 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700939 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
940 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700941 }
942
943 sc->current_speed = tgt_s;
944}
945
946/* Apply any per-cpu voltage increases. */
947static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
948 unsigned int vdd_dig, enum setrate_reason reason)
949{
950 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700951 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700952
953 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700954 * Increase vdd_mem active-set before vdd_dig.
955 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700956 */
957 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
958 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
959 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
960 sc->vreg[VREG_MEM].max_vdd, 0);
961 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800962 pr_err("%s increase failed (%d)\n",
963 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964 return rc;
965 }
966 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
967 }
968
969 /* Increase vdd_dig active-set vote. */
970 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
971 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
972 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
973 sc->vreg[VREG_DIG].max_vdd, 0);
974 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800975 pr_err("%s increase failed (%d)\n",
976 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700977 return rc;
978 }
979 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
980 }
981
982 /*
983 * Update per-CPU core voltage. Don't do this for the hotplug path for
984 * which it should already be correct. Attempting to set it is bad
985 * because we don't know what CPU we are running on at this point, but
986 * the CPU regulator API requires we call it from the affected CPU.
987 */
988 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
989 && reason != SETRATE_HOTPLUG) {
990 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
991 sc->vreg[VREG_CORE].max_vdd);
992 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800993 pr_err("%s increase failed (%d)\n",
994 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700995 return rc;
996 }
997 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
998 }
999
1000 return rc;
1001}
1002
1003/* Apply any per-cpu voltage decreases. */
1004static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1005 unsigned int vdd_dig, enum setrate_reason reason)
1006{
1007 struct scalable *sc = &scalable[cpu];
1008 int ret;
1009
1010 /*
1011 * Update per-CPU core voltage. This must be called on the CPU
1012 * that's being affected. Don't do this in the hotplug remove path,
1013 * where the rail is off and we're executing on the other CPU.
1014 */
1015 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1016 && reason != SETRATE_HOTPLUG) {
1017 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1018 sc->vreg[VREG_CORE].max_vdd);
1019 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001020 pr_err("%s decrease failed (%d)\n",
1021 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001022 return;
1023 }
1024 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1025 }
1026
1027 /* Decrease vdd_dig active-set vote. */
1028 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1029 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1030 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1031 sc->vreg[VREG_DIG].max_vdd, 0);
1032 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001033 pr_err("%s decrease failed (%d)\n",
1034 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001035 return;
1036 }
1037 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1038 }
1039
1040 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001041 * Decrease vdd_mem active-set after vdd_dig.
1042 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001043 */
1044 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1045 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1046 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1047 sc->vreg[VREG_MEM].max_vdd, 0);
1048 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001049 pr_err("%s decrease failed (%d)\n",
1050 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001051 return;
1052 }
1053 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1054 }
1055}
1056
1057static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1058{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001059 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001060}
1061
1062static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1063{
1064 unsigned int pll_vdd_dig;
1065
Stephen Boydc76158f2011-12-08 12:42:40 -08001066 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001067 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001068 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001069 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1070 else
1071 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1072
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001073 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1074}
1075
Tianyi Gouaded6432012-02-22 14:53:05 -08001076static unsigned int calculate_vdd_core(struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001077{
Tianyi Gouaded6432012-02-22 14:53:05 -08001078 return tgt->vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001079}
1080
1081/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001082static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1083 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001084{
1085 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1086 struct l2_level *tgt_l2_l;
1087 struct acpu_level *tgt;
1088 unsigned int vdd_mem, vdd_dig, vdd_core;
1089 unsigned long flags;
1090 int rc = 0;
1091
1092 if (cpu > num_possible_cpus()) {
1093 rc = -EINVAL;
1094 goto out;
1095 }
1096
1097 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1098 mutex_lock(&driver_lock);
1099
1100 strt_acpu_s = scalable[cpu].current_speed;
1101
1102 /* Return early if rate didn't change. */
1103 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1104 goto out;
1105
1106 /* Find target frequency. */
1107 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1108 if (tgt->speed.khz == rate) {
1109 tgt_acpu_s = &tgt->speed;
1110 break;
1111 }
1112 }
1113 if (tgt->speed.khz == 0) {
1114 rc = -EINVAL;
1115 goto out;
1116 }
1117
1118 /* Calculate voltage requirements for the current CPU. */
1119 vdd_mem = calculate_vdd_mem(tgt);
1120 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gouaded6432012-02-22 14:53:05 -08001121 vdd_core = calculate_vdd_core(tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001122
1123 /* Increase VDD levels if needed. */
1124 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1125 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1126 if (rc)
1127 goto out;
1128 }
1129
1130 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1131 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1132
1133 /* Set the CPU speed. */
1134 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1135
1136 /*
1137 * Update the L2 vote and apply the rate change. A spinlock is
1138 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001139 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001140 * and the driver_lock mutex is not acquired.
1141 */
1142 spin_lock_irqsave(&l2_lock, flags);
1143 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1144 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1145 spin_unlock_irqrestore(&l2_lock, flags);
1146
1147 /* Nothing else to do for power collapse or SWFI. */
1148 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1149 goto out;
1150
1151 /* Update bus bandwith request. */
1152 set_bus_bw(tgt_l2_l->bw_level);
1153
1154 /* Drop VDD levels if we can. */
1155 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1156
1157 scalable[cpu].first_set_call = false;
1158 pr_debug("ACPU%d speed change complete\n", cpu);
1159
1160out:
1161 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1162 mutex_unlock(&driver_lock);
1163 return rc;
1164}
1165
1166/* Initialize a HFPLL at a given rate and enable it. */
1167static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1168{
1169 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1170
1171 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001172 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001173
1174 /* Configure PLL parameters for integer mode. */
1175 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1176 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1177 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1178
1179 /* Program droop controller. */
1180 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1181
1182 /* Set an initial rate and enable the PLL. */
1183 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001184 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001185}
1186
1187/* Voltage regulator initialization. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001188static void __init regulator_init(int set_vdd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001189{
1190 int cpu, ret;
1191 struct scalable *sc;
1192
1193 for_each_possible_cpu(cpu) {
1194 sc = &scalable[cpu];
1195 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1196 sc->vreg[VREG_CORE].name);
1197 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1198 pr_err("regulator_get(%s) failed (%ld)\n",
1199 sc->vreg[VREG_CORE].name,
1200 PTR_ERR(sc->vreg[VREG_CORE].reg));
1201 BUG();
1202 }
1203
1204 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
Stephen Boydcfe192b2011-12-09 21:47:14 -08001205 set_vdd,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206 sc->vreg[VREG_CORE].max_vdd);
1207 if (ret)
1208 pr_err("regulator_set_voltage(%s) failed"
1209 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1210
1211 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1212 if (ret)
1213 pr_err("regulator_enable(%s) failed (%d)\n",
1214 sc->vreg[VREG_CORE].name, ret);
1215 }
1216}
1217
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001218/* Set initial rate for a given core. */
1219static void __init init_clock_sources(struct scalable *sc,
1220 struct core_speed *tgt_s)
1221{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001222 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001223
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001224 /* Select PLL8 as AUX source input to the secondary MUX. */
1225 writel_relaxed(0x3, sc->aux_clk_sel);
1226
1227 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001228 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001229 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001230 hfpll_init(sc, tgt_s);
1231
1232 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001233 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001234 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001235 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001236
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001237 /* Switch to the target clock source. */
1238 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001239 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1240 sc->current_speed = tgt_s;
1241
1242 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001243 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1244 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001245 */
1246 sc->first_set_call = true;
1247}
1248
Matt Wagantall8e726c72011-08-06 00:49:28 -07001249static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001251 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001252 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001253
1254 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1255 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001256}
1257
1258/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001259static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001260{
1261 int ret;
1262
1263 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1264 if (!bus_perf_client) {
1265 pr_err("unable to register bus client\n");
1266 BUG();
1267 }
1268
Stephen Boydcfe192b2011-12-09 21:47:14 -08001269 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001270 if (ret)
1271 pr_err("initial bandwidth request failed (%d)\n", ret);
1272}
1273
1274#ifdef CONFIG_CPU_FREQ_MSM
1275static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1276
1277static void __init cpufreq_table_init(void)
1278{
1279 int cpu;
1280
1281 for_each_possible_cpu(cpu) {
1282 int i, freq_cnt = 0;
1283 /* Construct the freq_table tables from acpu_freq_tbl. */
1284 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1285 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1286 if (acpu_freq_tbl[i].use_for_scaling) {
1287 freq_table[cpu][freq_cnt].index = freq_cnt;
1288 freq_table[cpu][freq_cnt].frequency
1289 = acpu_freq_tbl[i].speed.khz;
1290 freq_cnt++;
1291 }
1292 }
1293 /* freq_table not big enough to store all usable freqs. */
1294 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1295
1296 freq_table[cpu][freq_cnt].index = freq_cnt;
1297 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1298
1299 pr_info("CPU%d: %d scaling frequencies supported.\n",
1300 cpu, freq_cnt);
1301
1302 /* Register table with CPUFreq. */
1303 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1304 }
1305}
1306#else
1307static void __init cpufreq_table_init(void) {}
1308#endif
1309
1310#define HOT_UNPLUG_KHZ STBY_KHZ
1311static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1312 unsigned long action, void *hcpu)
1313{
1314 static int prev_khz[NR_CPUS];
1315 static int prev_pri_src[NR_CPUS];
1316 static int prev_sec_src[NR_CPUS];
1317 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001318
1319 switch (action) {
1320 case CPU_DYING:
1321 case CPU_DYING_FROZEN:
1322 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001323 * On Krait v1 and 8064v1, the primary and secondary muxes must
1324 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001325 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001326 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001327 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1328 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1329 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1330 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1331 }
1332 break;
1333 case CPU_DEAD:
1334 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001335 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001336 /* Fall through. */
1337 case CPU_UP_CANCELED:
1338 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001339 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001340 break;
1341 case CPU_UP_PREPARE:
1342 case CPU_UP_PREPARE_FROZEN:
1343 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001344 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001345 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001346 break;
1347 case CPU_STARTING:
1348 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001349 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1351 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1352 }
1353 break;
1354 default:
1355 break;
1356 }
1357
1358 return NOTIFY_OK;
1359}
1360
1361static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1362 .notifier_call = acpuclock_cpu_callback,
1363};
1364
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001365static const int krait_needs_vmin(void)
1366{
1367 switch (read_cpuid_id()) {
1368 case 0x511F04D0:
1369 case 0x511F04D1:
1370 case 0x510F06F0:
1371 return 1;
1372 default:
1373 return 0;
1374 };
1375}
1376
Stephen Boydaefb8de2012-01-05 19:05:01 -08001377static void kraitv2_apply_vmin(struct acpu_level *tbl)
1378{
1379 for (; tbl->speed.khz != 0; tbl++)
1380 if (tbl->vdd_core < 1150000)
1381 tbl->vdd_core = 1150000;
1382}
1383
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001384static struct acpu_level * __init select_freq_plan(void)
1385{
1386 struct acpu_level *l, *max_acpu_level = NULL;
1387
1388 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001389 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001390 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001391 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001392
1393 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1394 pvs = (pte_efuse >> 10) & 0x7;
1395 if (pvs == 0x7)
1396 pvs = (pte_efuse >> 13) & 0x7;
1397
1398 switch (pvs) {
1399 case 0x0:
1400 case 0x7:
1401 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001402 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1403 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001404 break;
1405 case 0x1:
1406 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001407 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001408 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001409 break;
1410 case 0x3:
1411 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001412 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001413 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001414 break;
1415 default:
1416 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001417 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1418 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001419 break;
1420 }
1421
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001422 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001423 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001424 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001425 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1426 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1427 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001428 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001429 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1430 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1431 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001432 } else if (cpu_is_apq8064()) {
1433 scalable = scalable_8064;
1434 acpu_freq_tbl = acpu_freq_tbl_8064;
1435 l2_freq_tbl = l2_freq_tbl_8064;
1436 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001437 } else if (cpu_is_msm8627()) {
1438 scalable = scalable_8627;
1439 acpu_freq_tbl = acpu_freq_tbl_8627;
1440 l2_freq_tbl = l2_freq_tbl_8627;
1441 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001442 } else if (cpu_is_msm8930()) {
1443 scalable = scalable_8930;
1444 acpu_freq_tbl = acpu_freq_tbl_8930;
1445 l2_freq_tbl = l2_freq_tbl_8930;
1446 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001447 } else {
1448 BUG();
1449 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001450 if (krait_needs_vmin())
1451 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001452
1453 /* Find the max supported scaling frequency. */
1454 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1455 if (l->use_for_scaling)
1456 max_acpu_level = l;
1457 BUG_ON(!max_acpu_level);
1458 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1459
1460 return max_acpu_level;
1461}
1462
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001463static struct acpuclk_data acpuclk_8960_data = {
1464 .set_rate = acpuclk_8960_set_rate,
1465 .get_rate = acpuclk_8960_get_rate,
1466 .power_collapse_khz = STBY_KHZ,
1467 .wait_for_irq_khz = STBY_KHZ,
1468};
1469
Matt Wagantallec57f062011-08-16 23:54:46 -07001470static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001471{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001472 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001473
1474 regulator_init(max_acpu_level->vdd_core);
1475 bus_init(max_acpu_level->l2_level->bw_level);
1476
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001477 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1478 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001479
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001480 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001481
1482 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001483 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001484
1485 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001486}
Matt Wagantallec57f062011-08-16 23:54:46 -07001487
1488struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1489 .init = acpuclk_8960_init,
1490};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001491
1492struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1493 .init = acpuclk_8960_init,
1494};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001495
1496struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1497 .init = acpuclk_8960_init,
1498};