blob: a65c5b05913179c60abfe14f955d1d9f47b1b0a1 [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"
Matt Wagantall34c2d962012-02-01 14:30:02 -080039#include "pm.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040
41/*
42 * Source IDs.
43 * These must be negative to not overlap with the source IDs
44 * used by the 8x60 local clock driver.
45 */
46#define PLL_8 0
47#define HFPLL -1
48#define QSB -2
49
50/* Mux source selects. */
51#define PRI_SRC_SEL_SEC_SRC 0
52#define PRI_SRC_SEL_HFPLL 1
53#define PRI_SRC_SEL_HFPLL_DIV2 2
54#define SEC_SRC_SEL_QSB 0
Matt Wagantall65e5e4b2011-10-27 16:52:10 -070055#define SEC_SRC_SEL_AUX 2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056
57/* HFPLL registers offsets. */
58#define HFPLL_MODE 0x00
59#define HFPLL_CONFIG_CTL 0x04
60#define HFPLL_L_VAL 0x08
61#define HFPLL_M_VAL 0x0C
62#define HFPLL_N_VAL 0x10
63#define HFPLL_DROOP_CTL 0x14
64
65/* CP15 L2 indirect addresses. */
66#define L2CPMR_IADDR 0x500
67#define L2CPUCPMR_IADDR 0x501
68
69#define STBY_KHZ 1
70
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
72
73#define SECCLKAGD BIT(4)
74
Matt Wagantalla518f8f2011-10-17 13:24:53 -070075/* PTE EFUSE register. */
76#define QFPROM_PTE_EFUSE_ADDR (MSM_QFPROM_BASE + 0x00C0)
77
Tianyi Gou50705682012-02-21 17:51:50 -080078/* Corner type vreg VDD values */
79#define LVL_NONE RPM_VREG_CORNER_NONE
80#define LVL_LOW RPM_VREG_CORNER_LOW
81#define LVL_NOM RPM_VREG_CORNER_NOMINAL
82#define LVL_HIGH RPM_VREG_CORNER_HIGH
83
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084enum scalables {
85 CPU0 = 0,
86 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070087 CPU2,
88 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089 L2,
90 NUM_SCALABLES
91};
92
93enum vregs {
94 VREG_CORE,
95 VREG_MEM,
96 VREG_DIG,
Matt Wagantallcb12c392011-10-19 10:32:07 -070097 VREG_HFPLL_A,
98 VREG_HFPLL_B,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099 NUM_VREG
100};
101
Tianyi Gou50705682012-02-21 17:51:50 -0800102enum hfpll_vdd_levels {
103 HFPLL_VDD_NONE,
104 HFPLL_VDD_LOW,
105 HFPLL_VDD_NOM
106};
107
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108struct vreg {
109 const char name[15];
110 const unsigned int max_vdd;
111 const int rpm_vreg_voter;
112 const int rpm_vreg_id;
113 struct regulator *reg;
114 unsigned int cur_vdd;
115};
116
117struct core_speed {
118 unsigned int khz;
119 int src;
120 unsigned int pri_src_sel;
121 unsigned int sec_src_sel;
122 unsigned int pll_l_val;
123};
124
125struct l2_level {
126 struct core_speed speed;
127 unsigned int vdd_dig;
128 unsigned int vdd_mem;
129 unsigned int bw_level;
130};
131
132struct acpu_level {
133 unsigned int use_for_scaling;
134 struct core_speed speed;
135 struct l2_level *l2_level;
136 unsigned int vdd_core;
137};
138
139struct scalable {
140 void * __iomem const hfpll_base;
141 void * __iomem const aux_clk_sel;
142 const uint32_t l2cpmr_iaddr;
143 struct core_speed *current_speed;
144 struct l2_level *l2_vote;
145 struct vreg vreg[NUM_VREG];
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 l2_level *l2_freq_tbl;
382static struct acpu_level *acpu_freq_tbl;
383static int l2_freq_tbl_size;
Matt Wagantall34c2d962012-02-01 14:30:02 -0800384static struct scalable *scalable;
385#define SCALABLE_TO_CPU(sc) ((sc) - scalable)
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700386
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700387/* Instantaneous bandwidth requests in MB/s. */
388#define BW_MBPS(_bw) \
389 { \
390 .vectors = (struct msm_bus_vectors[]){ \
391 {\
392 .src = MSM_BUS_MASTER_AMPSS_M0, \
393 .dst = MSM_BUS_SLAVE_EBI_CH0, \
394 .ib = (_bw) * 1000000UL, \
395 .ab = (_bw) * 100000UL, \
396 }, \
397 { \
398 .src = MSM_BUS_MASTER_AMPSS_M1, \
399 .dst = MSM_BUS_SLAVE_EBI_CH0, \
400 .ib = (_bw) * 1000000UL, \
401 .ab = (_bw) * 100000UL, \
402 }, \
403 }, \
404 .num_paths = 2, \
405 }
406static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800407 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
408 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
409 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
410 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
411 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
412 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
413 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800414 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700415};
416
417static struct msm_bus_scale_pdata bus_client_pdata = {
418 .usecase = bw_level_tbl,
419 .num_usecases = ARRAY_SIZE(bw_level_tbl),
420 .active_only = 1,
421 .name = "acpuclock",
422};
423
424static uint32_t bus_perf_client;
425
426/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800427#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
428static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700429 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700430 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700431 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
432 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
433 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
434 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
435 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
436 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700437 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700438 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
439 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
440 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700441};
442
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800443static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
444 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
445 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
446 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
447 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
448 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
449 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
450 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
451 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
452 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
453 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
454 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
455 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
456 { 0, { 0 } }
457};
458
459static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
460 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
461 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
462 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
463 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
464 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
465 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
466 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
467 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
468 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
469 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
470 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
471 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700472 { 0, { 0 } }
473};
474
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800475#undef L2
476#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
477static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
478 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
479 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800480 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
481 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
482 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800483 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800484 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
485 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
486 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
487 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
488 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
489 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
490 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
491 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
492 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
493 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
494 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800495 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
496 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
497 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800498};
499
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800500static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800501 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
502 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800503 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
504 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
505 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
506 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
507 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
508 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
509 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
510 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
511 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
512 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
513 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
514 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
515 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800516 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800517 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800518 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800519 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800520 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800521 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800522 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1237500 },
523 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800524 { 0, { 0 } }
525};
526
527static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800528 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
529 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800530 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
531 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
532 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
533 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
534 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
535 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
536 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
537 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
538 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
539 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
540 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
541 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
542 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800543 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800544 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800545 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1150000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800546 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1175000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800547 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800548 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800549 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1187500 },
550 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800551 { 0, { 0 } }
552};
553
Stephen Boyd5766f682011-12-27 19:21:08 -0800554static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800555 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
556 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800557 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
558 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
559 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
560 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
561 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
562 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
563 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
564 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
565 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
566 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
567 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
568 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
569 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800570 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800571 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800572 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1100000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800573 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1125000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800574 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800575 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1137500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800576 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1137500 },
577 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800578 { 0, { 0 } }
579};
580
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700581/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
582#undef L2
583#define L2(x) (&l2_freq_tbl_8064[(x)])
584static struct l2_level l2_freq_tbl_8064[] = {
585 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800586 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
587 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
588 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
589 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700590 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800591 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
592 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
593 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
594 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
595 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
596 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
597 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
598 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
599 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
600 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700601};
602
603/* TODO: Update core voltages when data is available. */
604static struct acpu_level acpu_freq_tbl_8064[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800605 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
606 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
607 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
608 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
609 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
610 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
611 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
612 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
613 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
614 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
615 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
616 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
617 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
618 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
619 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
620 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
621 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
622 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
623 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
624 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
625 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
626 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
627 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700628 { 0, { 0 } }
629};
630
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800631/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
632#undef L2
633#define L2(x) (&l2_freq_tbl_8930[(x)])
634static struct l2_level l2_freq_tbl_8930[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800635 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
636 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800637 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 2 },
638 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 2 },
639 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
Tianyi Gou50705682012-02-21 17:51:50 -0800640 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800641 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 4 },
642 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 4 },
643 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 4 },
644 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 4 },
645 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
646 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 7 },
647 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 7 },
648 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, LVL_HIGH, 1150000, 7 },
649 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, LVL_HIGH, 1150000, 7 },
650 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, LVL_HIGH, 1150000, 7 },
651 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, LVL_HIGH, 1150000, 7 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800652};
653
654/* TODO: Update core voltages when data is available. */
655static struct acpu_level acpu_freq_tbl_8930[] = {
Tianyi Goud911dd12012-05-10 21:06:40 -0700656 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 925000 },
657 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 925000 },
658 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 937500 },
659 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 962500 },
660 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 987500 },
661 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
662 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
663 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1037500 },
664 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1062500 },
665 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1087500 },
666 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
667 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1125000 },
668 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1137500 },
669 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1162500 },
670 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1187500 },
671 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1200000 },
672 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1225000 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800673 { 0, { 0 } }
674};
675
Tianyi Goue0b34de2011-12-20 11:20:10 -0800676/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
677#undef L2
678#define L2(x) (&l2_freq_tbl_8627[(x)])
679static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800680 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
681 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
682 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
683 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
684 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
685 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
686 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
687 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
688 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
689 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
690 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
691 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
692 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800693};
694
695/* TODO: Update core voltages when data is available. */
696static struct acpu_level acpu_freq_tbl_8627[] = {
697 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
698 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
699 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
700 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
701 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
702 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
703 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
704 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
705 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
706 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
707 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
708 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
709 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
710 { 0, { 0 } }
711};
712
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700713static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700714{
715 return scalable[cpu].current_speed->khz;
716}
717
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700718/* Get the selected source on primary MUX. */
719static int get_pri_clk_src(struct scalable *sc)
720{
721 uint32_t regval;
722
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700723 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700724 return regval & 0x3;
725}
726
727/* Set the selected source on primary MUX. */
728static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
729{
730 uint32_t regval;
731
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700732 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700733 regval &= ~0x3;
734 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700735 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700736 /* Wait for switch to complete. */
737 mb();
738 udelay(1);
739}
740
741/* Get the selected source on secondary MUX. */
742static int get_sec_clk_src(struct scalable *sc)
743{
744 uint32_t regval;
745
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700746 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700747 return (regval >> 2) & 0x3;
748}
749
750/* Set the selected source on secondary MUX. */
751static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
752{
753 uint32_t regval;
754
755 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700756 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700758 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700759
760 /* Program the MUX. */
761 regval &= ~(0x3 << 2);
762 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700763 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700764
765 /* Wait for switch to complete. */
766 mb();
767 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700768
769 /* Re-enable secondary source clock gating. */
770 regval &= ~SECCLKAGD;
771 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700772}
773
774/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800775static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700776{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700777 int rc;
778
Matt Wagantallc1021762012-01-31 20:02:02 -0800779 if (!skip_regulators) {
780 if (cpu_is_msm8960()) {
781 rc = rpm_vreg_set_voltage(
782 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
783 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
David Collins9a81d6c2012-03-29 15:11:33 -0700784 2050000,
Matt Wagantallc1021762012-01-31 20:02:02 -0800785 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
786 if (rc)
787 pr_err("%s regulator enable failed (%d)\n",
788 sc->vreg[VREG_HFPLL_A].name, rc);
789 }
790 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
791 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
792 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800793 if (rc)
794 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800795 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800796 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700797 /* Disable PLL bypass mode. */
798 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
799
800 /*
801 * H/W requires a 5us delay between disabling the bypass and
802 * de-asserting the reset. Delay 10us just to be safe.
803 */
804 mb();
805 udelay(10);
806
807 /* De-assert active-low PLL reset. */
808 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
809
810 /* Wait for PLL to lock. */
811 mb();
812 udelay(60);
813
814 /* Enable PLL output. */
815 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
816}
817
818/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800819static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700820{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700821 int rc;
822
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 /*
824 * Disable the PLL output, disable test mode, enable
825 * the bypass mode, and assert the reset.
826 */
827 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700828
Matt Wagantallc1021762012-01-31 20:02:02 -0800829 if (!skip_regulators) {
830 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
831 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800832 0, 0);
833 if (rc)
834 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800835 sc->vreg[VREG_HFPLL_B].name, rc);
836
837 if (cpu_is_msm8960()) {
838 rc = rpm_vreg_set_voltage(
839 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
840 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
841 0, 0, 0);
842 if (rc)
843 pr_err("%s regulator enable failed (%d)\n",
844 sc->vreg[VREG_HFPLL_A].name, rc);
845 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800846 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700847}
848
849/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
850static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
851{
852 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
853}
854
855/* Return the L2 speed that should be applied. */
856static struct l2_level *compute_l2_level(struct scalable *sc,
857 struct l2_level *vote_l)
858{
859 struct l2_level *new_l;
860 int cpu;
861
862 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700863 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864
865 /* Find max L2 speed vote. */
866 sc->l2_vote = vote_l;
867 new_l = l2_freq_tbl;
868 for_each_present_cpu(cpu)
869 new_l = max(new_l, scalable[cpu].l2_vote);
870
871 return new_l;
872}
873
874/* Update the bus bandwidth request. */
875static void set_bus_bw(unsigned int bw)
876{
877 int ret;
878
879 /* Bounds check. */
880 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
881 pr_err("invalid bandwidth request (%d)\n", bw);
882 return;
883 }
884
885 /* Update bandwidth if request has changed. This may sleep. */
886 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
887 if (ret)
888 pr_err("bandwidth request failed (%d)\n", ret);
889}
890
891/* Set the CPU or L2 clock speed. */
892static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
893 enum setrate_reason reason)
894{
895 struct core_speed *strt_s = sc->current_speed;
896
897 if (tgt_s == strt_s)
898 return;
899
900 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700902 * Move to an always-on source running at a frequency that does
903 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700904 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700905 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
907
908 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800909 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700910 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800911 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912
913 /* Move CPU to HFPLL source. */
914 set_pri_clk_src(sc, tgt_s->pri_src_sel);
915 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916 /*
Matt Wagantall34c2d962012-02-01 14:30:02 -0800917 * If responding to CPU_DEAD we must be running on another CPU.
918 * Therefore, we can't access the downed CPU's clock MUX CP15
919 * registers from here and can't change clock sources. If the
920 * CPU is collapsed, however, it is still safe to turn off the
921 * PLL without switching the MUX away from it.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922 */
923 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
924 set_sec_clk_src(sc, tgt_s->sec_src_sel);
925 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -0800926 hfpll_disable(sc, 0);
927 } else if (reason == SETRATE_HOTPLUG
928 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
929 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932 /*
933 * If responding to CPU_UP_PREPARE, we can't change CP15
934 * registers for the CPU that's coming up since we're not
935 * running on that CPU. That's okay though, since the MUX
936 * source was not changed on the way down, either.
937 */
Matt Wagantall34c2d962012-02-01 14:30:02 -0800938 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
939 hfpll_set_rate(sc, tgt_s);
940 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700941 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -0800942 } else if (reason == SETRATE_HOTPLUG
943 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
944 /* PLL was disabled during hot-unplug. Re-enable it. */
945 hfpll_set_rate(sc, tgt_s);
946 hfpll_enable(sc, 0);
947 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700948 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
950 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700951 }
952
953 sc->current_speed = tgt_s;
954}
955
956/* Apply any per-cpu voltage increases. */
957static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
958 unsigned int vdd_dig, enum setrate_reason reason)
959{
960 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700961 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700962
963 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700964 * Increase vdd_mem active-set before vdd_dig.
965 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700966 */
967 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
968 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
969 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
970 sc->vreg[VREG_MEM].max_vdd, 0);
971 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800972 pr_err("%s increase failed (%d)\n",
973 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700974 return rc;
975 }
976 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
977 }
978
979 /* Increase vdd_dig active-set vote. */
980 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
981 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
982 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
983 sc->vreg[VREG_DIG].max_vdd, 0);
984 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800985 pr_err("%s increase failed (%d)\n",
986 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987 return rc;
988 }
989 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
990 }
991
992 /*
993 * Update per-CPU core voltage. Don't do this for the hotplug path for
994 * which it should already be correct. Attempting to set it is bad
995 * because we don't know what CPU we are running on at this point, but
996 * the CPU regulator API requires we call it from the affected CPU.
997 */
998 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
999 && reason != SETRATE_HOTPLUG) {
1000 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1001 sc->vreg[VREG_CORE].max_vdd);
1002 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001003 pr_err("%s increase failed (%d)\n",
1004 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001005 return rc;
1006 }
1007 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1008 }
1009
1010 return rc;
1011}
1012
1013/* Apply any per-cpu voltage decreases. */
1014static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1015 unsigned int vdd_dig, enum setrate_reason reason)
1016{
1017 struct scalable *sc = &scalable[cpu];
1018 int ret;
1019
1020 /*
1021 * Update per-CPU core voltage. This must be called on the CPU
1022 * that's being affected. Don't do this in the hotplug remove path,
1023 * where the rail is off and we're executing on the other CPU.
1024 */
1025 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1026 && reason != SETRATE_HOTPLUG) {
1027 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1028 sc->vreg[VREG_CORE].max_vdd);
1029 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001030 pr_err("%s decrease failed (%d)\n",
1031 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001032 return;
1033 }
1034 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1035 }
1036
1037 /* Decrease vdd_dig active-set vote. */
1038 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1039 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1040 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1041 sc->vreg[VREG_DIG].max_vdd, 0);
1042 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001043 pr_err("%s decrease failed (%d)\n",
1044 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001045 return;
1046 }
1047 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1048 }
1049
1050 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001051 * Decrease vdd_mem active-set after vdd_dig.
1052 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001053 */
1054 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1055 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1056 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1057 sc->vreg[VREG_MEM].max_vdd, 0);
1058 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001059 pr_err("%s decrease failed (%d)\n",
1060 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001061 return;
1062 }
1063 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1064 }
1065}
1066
1067static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1068{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001069 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001070}
1071
1072static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1073{
1074 unsigned int pll_vdd_dig;
1075
Stephen Boydc76158f2011-12-08 12:42:40 -08001076 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001077 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001078 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001079 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1080 else
1081 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1082
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001083 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1084}
1085
Tianyi Gouaded6432012-02-22 14:53:05 -08001086static unsigned int calculate_vdd_core(struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001087{
Tianyi Gouaded6432012-02-22 14:53:05 -08001088 return tgt->vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001089}
1090
1091/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001092static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1093 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001094{
1095 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1096 struct l2_level *tgt_l2_l;
1097 struct acpu_level *tgt;
1098 unsigned int vdd_mem, vdd_dig, vdd_core;
1099 unsigned long flags;
1100 int rc = 0;
1101
1102 if (cpu > num_possible_cpus()) {
1103 rc = -EINVAL;
1104 goto out;
1105 }
1106
1107 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1108 mutex_lock(&driver_lock);
1109
1110 strt_acpu_s = scalable[cpu].current_speed;
1111
1112 /* Return early if rate didn't change. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001113 if (rate == strt_acpu_s->khz)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001114 goto out;
1115
1116 /* Find target frequency. */
1117 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1118 if (tgt->speed.khz == rate) {
1119 tgt_acpu_s = &tgt->speed;
1120 break;
1121 }
1122 }
1123 if (tgt->speed.khz == 0) {
1124 rc = -EINVAL;
1125 goto out;
1126 }
1127
1128 /* Calculate voltage requirements for the current CPU. */
1129 vdd_mem = calculate_vdd_mem(tgt);
1130 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gouaded6432012-02-22 14:53:05 -08001131 vdd_core = calculate_vdd_core(tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001132
1133 /* Increase VDD levels if needed. */
1134 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1135 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1136 if (rc)
1137 goto out;
1138 }
1139
1140 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1141 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1142
1143 /* Set the CPU speed. */
1144 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1145
1146 /*
1147 * Update the L2 vote and apply the rate change. A spinlock is
1148 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001149 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001150 * and the driver_lock mutex is not acquired.
1151 */
1152 spin_lock_irqsave(&l2_lock, flags);
1153 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1154 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1155 spin_unlock_irqrestore(&l2_lock, flags);
1156
1157 /* Nothing else to do for power collapse or SWFI. */
1158 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1159 goto out;
1160
1161 /* Update bus bandwith request. */
1162 set_bus_bw(tgt_l2_l->bw_level);
1163
1164 /* Drop VDD levels if we can. */
1165 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1166
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001167 pr_debug("ACPU%d speed change complete\n", cpu);
1168
1169out:
1170 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1171 mutex_unlock(&driver_lock);
1172 return rc;
1173}
1174
1175/* Initialize a HFPLL at a given rate and enable it. */
1176static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1177{
1178 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1179
1180 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001181 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001182
1183 /* Configure PLL parameters for integer mode. */
1184 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1185 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1186 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1187
1188 /* Program droop controller. */
1189 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1190
1191 /* Set an initial rate and enable the PLL. */
1192 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001193 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001194}
1195
1196/* Voltage regulator initialization. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001197static void __init regulator_init(struct acpu_level *lvl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001198{
1199 int cpu, ret;
1200 struct scalable *sc;
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001201 unsigned int vdd_mem, vdd_dig, vdd_core;
1202
1203 vdd_mem = calculate_vdd_mem(lvl);
1204 vdd_dig = calculate_vdd_dig(lvl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001205
1206 for_each_possible_cpu(cpu) {
1207 sc = &scalable[cpu];
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001208
1209 /* Set initial vdd_mem vote. */
1210 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1211 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1212 sc->vreg[VREG_MEM].max_vdd, 0);
1213 if (ret) {
1214 pr_err("%s initialization failed (%d)\n",
1215 sc->vreg[VREG_MEM].name, ret);
1216 BUG();
1217 }
1218 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1219
1220 /* Set initial vdd_dig vote. */
1221 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1222 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1223 sc->vreg[VREG_DIG].max_vdd, 0);
1224 if (ret) {
1225 pr_err("%s initialization failed (%d)\n",
1226 sc->vreg[VREG_DIG].name, ret);
1227 BUG();
1228 }
1229 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1230
1231 /* Setup Krait CPU regulators and initial core voltage. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001232 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1233 sc->vreg[VREG_CORE].name);
1234 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1235 pr_err("regulator_get(%s) failed (%ld)\n",
1236 sc->vreg[VREG_CORE].name,
1237 PTR_ERR(sc->vreg[VREG_CORE].reg));
1238 BUG();
1239 }
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001240 vdd_core = calculate_vdd_core(lvl);
1241 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001242 sc->vreg[VREG_CORE].max_vdd);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001243 if (ret) {
1244 pr_err("%s initialization failed (%d)\n",
1245 sc->vreg[VREG_CORE].name, ret);
1246 BUG();
1247 }
1248 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001249 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001250 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001251 pr_err("regulator_enable(%s) failed (%d)\n",
1252 sc->vreg[VREG_CORE].name, ret);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001253 BUG();
1254 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001255 }
1256}
1257
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001258/* Set initial rate for a given core. */
1259static void __init init_clock_sources(struct scalable *sc,
1260 struct core_speed *tgt_s)
1261{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001262 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001263
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001264 /* Select PLL8 as AUX source input to the secondary MUX. */
1265 writel_relaxed(0x3, sc->aux_clk_sel);
1266
1267 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001268 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001269 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001270 hfpll_init(sc, tgt_s);
1271
1272 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001273 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001274 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001275 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001276
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001277 /* Switch to the target clock source. */
1278 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001279 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1280 sc->current_speed = tgt_s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001281}
1282
Matt Wagantall8e726c72011-08-06 00:49:28 -07001283static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001284{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001285 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001286 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001287
1288 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1289 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001290}
1291
1292/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001293static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001294{
1295 int ret;
1296
1297 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1298 if (!bus_perf_client) {
1299 pr_err("unable to register bus client\n");
1300 BUG();
1301 }
1302
Stephen Boydcfe192b2011-12-09 21:47:14 -08001303 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001304 if (ret)
1305 pr_err("initial bandwidth request failed (%d)\n", ret);
1306}
1307
1308#ifdef CONFIG_CPU_FREQ_MSM
1309static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1310
1311static void __init cpufreq_table_init(void)
1312{
1313 int cpu;
1314
1315 for_each_possible_cpu(cpu) {
1316 int i, freq_cnt = 0;
1317 /* Construct the freq_table tables from acpu_freq_tbl. */
1318 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1319 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1320 if (acpu_freq_tbl[i].use_for_scaling) {
1321 freq_table[cpu][freq_cnt].index = freq_cnt;
1322 freq_table[cpu][freq_cnt].frequency
1323 = acpu_freq_tbl[i].speed.khz;
1324 freq_cnt++;
1325 }
1326 }
1327 /* freq_table not big enough to store all usable freqs. */
1328 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1329
1330 freq_table[cpu][freq_cnt].index = freq_cnt;
1331 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1332
1333 pr_info("CPU%d: %d scaling frequencies supported.\n",
1334 cpu, freq_cnt);
1335
1336 /* Register table with CPUFreq. */
1337 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1338 }
1339}
1340#else
1341static void __init cpufreq_table_init(void) {}
1342#endif
1343
1344#define HOT_UNPLUG_KHZ STBY_KHZ
1345static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1346 unsigned long action, void *hcpu)
1347{
1348 static int prev_khz[NR_CPUS];
1349 static int prev_pri_src[NR_CPUS];
1350 static int prev_sec_src[NR_CPUS];
1351 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001352
1353 switch (action) {
1354 case CPU_DYING:
1355 case CPU_DYING_FROZEN:
1356 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001357 * On Krait v1 and 8064v1, the primary and secondary muxes must
1358 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001359 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001360 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001361 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1362 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1363 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1364 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1365 }
1366 break;
1367 case CPU_DEAD:
1368 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001369 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001370 /* Fall through. */
1371 case CPU_UP_CANCELED:
1372 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001373 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001374 break;
1375 case CPU_UP_PREPARE:
1376 case CPU_UP_PREPARE_FROZEN:
1377 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001378 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001379 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001380 break;
1381 case CPU_STARTING:
1382 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001383 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001384 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1385 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1386 }
1387 break;
1388 default:
1389 break;
1390 }
1391
1392 return NOTIFY_OK;
1393}
1394
1395static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1396 .notifier_call = acpuclock_cpu_callback,
1397};
1398
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001399static const int krait_needs_vmin(void)
1400{
1401 switch (read_cpuid_id()) {
1402 case 0x511F04D0:
1403 case 0x511F04D1:
1404 case 0x510F06F0:
1405 return 1;
1406 default:
1407 return 0;
1408 };
1409}
1410
Stephen Boydaefb8de2012-01-05 19:05:01 -08001411static void kraitv2_apply_vmin(struct acpu_level *tbl)
1412{
1413 for (; tbl->speed.khz != 0; tbl++)
1414 if (tbl->vdd_core < 1150000)
1415 tbl->vdd_core = 1150000;
1416}
1417
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001418static struct acpu_level * __init select_freq_plan(void)
1419{
1420 struct acpu_level *l, *max_acpu_level = NULL;
1421
1422 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001423 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001424 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001425 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001426
1427 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1428 pvs = (pte_efuse >> 10) & 0x7;
1429 if (pvs == 0x7)
1430 pvs = (pte_efuse >> 13) & 0x7;
1431
1432 switch (pvs) {
1433 case 0x0:
1434 case 0x7:
1435 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001436 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1437 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001438 break;
1439 case 0x1:
1440 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001441 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001442 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001443 break;
1444 case 0x3:
1445 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001446 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001447 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001448 break;
1449 default:
1450 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001451 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1452 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001453 break;
1454 }
1455
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001456 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001457 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001458 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001459 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1460 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1461 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001462 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001463 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1464 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1465 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001466 } else if (cpu_is_apq8064()) {
1467 scalable = scalable_8064;
1468 acpu_freq_tbl = acpu_freq_tbl_8064;
1469 l2_freq_tbl = l2_freq_tbl_8064;
1470 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001471 } else if (cpu_is_msm8627()) {
1472 scalable = scalable_8627;
1473 acpu_freq_tbl = acpu_freq_tbl_8627;
1474 l2_freq_tbl = l2_freq_tbl_8627;
1475 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001476 } else if (cpu_is_msm8930()) {
1477 scalable = scalable_8930;
1478 acpu_freq_tbl = acpu_freq_tbl_8930;
1479 l2_freq_tbl = l2_freq_tbl_8930;
1480 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001481 } else {
1482 BUG();
1483 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001484 if (krait_needs_vmin())
1485 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001486
1487 /* Find the max supported scaling frequency. */
1488 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1489 if (l->use_for_scaling)
1490 max_acpu_level = l;
1491 BUG_ON(!max_acpu_level);
1492 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1493
1494 return max_acpu_level;
1495}
1496
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001497static struct acpuclk_data acpuclk_8960_data = {
1498 .set_rate = acpuclk_8960_set_rate,
1499 .get_rate = acpuclk_8960_get_rate,
1500 .power_collapse_khz = STBY_KHZ,
1501 .wait_for_irq_khz = STBY_KHZ,
1502};
1503
Matt Wagantallec57f062011-08-16 23:54:46 -07001504static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001505{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001506 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001507
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001508 regulator_init(max_acpu_level);
Stephen Boydcfe192b2011-12-09 21:47:14 -08001509 bus_init(max_acpu_level->l2_level->bw_level);
1510
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001511 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1512 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001513
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001514 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001515
1516 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001517 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001518
1519 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001520}
Matt Wagantallec57f062011-08-16 23:54:46 -07001521
1522struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1523 .init = acpuclk_8960_init,
1524};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001525
1526struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1527 .init = acpuclk_8960_init,
1528};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001529
1530struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1531 .init = acpuclk_8960_init,
1532};