blob: 6986a29a86b9199c6ec97d2cb0e355789aab81a1 [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,
Tianyi Gou73712ed2012-05-23 12:18:29 -0700373 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800374 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
375 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800376 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800377 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800378 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800379 },
380};
381
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700382static struct l2_level *l2_freq_tbl;
383static struct acpu_level *acpu_freq_tbl;
384static int l2_freq_tbl_size;
Matt Wagantall34c2d962012-02-01 14:30:02 -0800385static struct scalable *scalable;
386#define SCALABLE_TO_CPU(sc) ((sc) - scalable)
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700387
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700388/* Instantaneous bandwidth requests in MB/s. */
389#define BW_MBPS(_bw) \
390 { \
391 .vectors = (struct msm_bus_vectors[]){ \
392 {\
393 .src = MSM_BUS_MASTER_AMPSS_M0, \
394 .dst = MSM_BUS_SLAVE_EBI_CH0, \
395 .ib = (_bw) * 1000000UL, \
396 .ab = (_bw) * 100000UL, \
397 }, \
398 { \
399 .src = MSM_BUS_MASTER_AMPSS_M1, \
400 .dst = MSM_BUS_SLAVE_EBI_CH0, \
401 .ib = (_bw) * 1000000UL, \
402 .ab = (_bw) * 100000UL, \
403 }, \
404 }, \
405 .num_paths = 2, \
406 }
407static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800408 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
409 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
410 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
411 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
412 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
413 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
414 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800415 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700416};
417
418static struct msm_bus_scale_pdata bus_client_pdata = {
419 .usecase = bw_level_tbl,
420 .num_usecases = ARRAY_SIZE(bw_level_tbl),
421 .active_only = 1,
422 .name = "acpuclock",
423};
424
425static uint32_t bus_perf_client;
426
427/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800428#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
429static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700430 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700431 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700432 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
433 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
434 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
435 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
436 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
437 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700438 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700439 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
440 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
441 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700442};
443
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800444static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
445 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
446 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
447 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
448 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
449 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
450 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
451 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
452 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
453 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
454 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
455 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
456 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
457 { 0, { 0 } }
458};
459
460static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
461 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
462 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
463 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
464 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
465 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
466 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
467 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
468 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
469 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
470 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
471 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
472 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473 { 0, { 0 } }
474};
475
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800476#undef L2
477#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
478static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
479 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
480 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800481 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
482 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
483 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800484 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800485 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
486 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
487 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
488 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
489 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
490 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
491 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
492 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
493 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
494 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
495 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800496 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
497 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
498 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800499};
500
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800501static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800502 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
503 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800504 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
505 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
506 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
507 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
508 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
509 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
510 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
511 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
512 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
513 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
514 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
515 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
516 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800517 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800518 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800519 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800520 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800521 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800522 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800523 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1237500 },
524 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800525 { 0, { 0 } }
526};
527
528static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800529 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
530 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800531 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
532 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
533 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
534 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
535 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
536 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
537 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
538 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
539 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
540 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
541 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
542 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
543 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800544 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800545 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800546 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1150000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800547 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1175000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800548 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800549 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800550 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1187500 },
551 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800552 { 0, { 0 } }
553};
554
Stephen Boyd5766f682011-12-27 19:21:08 -0800555static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800556 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
557 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800558 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
559 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
560 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
561 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
562 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
563 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
564 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
565 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
566 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
567 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
568 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
569 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
570 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800571 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800572 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800573 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1100000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800574 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1125000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800575 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800576 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1137500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800577 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1137500 },
578 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800579 { 0, { 0 } }
580};
581
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700582/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
583#undef L2
584#define L2(x) (&l2_freq_tbl_8064[(x)])
585static struct l2_level l2_freq_tbl_8064[] = {
586 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800587 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
588 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
589 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
590 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700591 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800592 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
593 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
594 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
595 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
596 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
597 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
598 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
599 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
600 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
601 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700602};
603
604/* TODO: Update core voltages when data is available. */
605static struct acpu_level acpu_freq_tbl_8064[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800606 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
607 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
608 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
609 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
610 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
611 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
612 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
613 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
614 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
615 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
616 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
617 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
618 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
619 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
620 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
621 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
622 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
623 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
624 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
625 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
626 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
627 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
628 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700629 { 0, { 0 } }
630};
631
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800632/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
633#undef L2
634#define L2(x) (&l2_freq_tbl_8930[(x)])
635static struct l2_level l2_freq_tbl_8930[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800636 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
637 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800638 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 2 },
639 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 2 },
640 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
Tianyi Gou50705682012-02-21 17:51:50 -0800641 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800642 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 4 },
643 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 4 },
644 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 4 },
645 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 4 },
646 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
647 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 7 },
648 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 7 },
649 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, LVL_HIGH, 1150000, 7 },
650 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, LVL_HIGH, 1150000, 7 },
651 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, LVL_HIGH, 1150000, 7 },
652 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, LVL_HIGH, 1150000, 7 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800653};
654
655/* TODO: Update core voltages when data is available. */
656static struct acpu_level acpu_freq_tbl_8930[] = {
Tianyi Goud911dd12012-05-10 21:06:40 -0700657 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 925000 },
658 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 925000 },
659 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 937500 },
660 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 962500 },
661 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 987500 },
662 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
663 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
664 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1037500 },
665 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1062500 },
666 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1087500 },
667 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
668 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1125000 },
669 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1137500 },
670 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1162500 },
671 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1187500 },
672 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1200000 },
673 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1225000 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800674 { 0, { 0 } }
675};
676
Tianyi Goue0b34de2011-12-20 11:20:10 -0800677/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
678#undef L2
679#define L2(x) (&l2_freq_tbl_8627[(x)])
680static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800681 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
682 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
683 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
684 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
685 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
686 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
687 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
688 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
689 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
690 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
691 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
692 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
693 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800694};
695
696/* TODO: Update core voltages when data is available. */
697static struct acpu_level acpu_freq_tbl_8627[] = {
698 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
699 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
700 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
701 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
702 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
703 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
704 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
705 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
706 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
707 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
708 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
709 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
710 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
711 { 0, { 0 } }
712};
713
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700714static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700715{
716 return scalable[cpu].current_speed->khz;
717}
718
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700719/* Get the selected source on primary MUX. */
720static int get_pri_clk_src(struct scalable *sc)
721{
722 uint32_t regval;
723
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700724 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700725 return regval & 0x3;
726}
727
728/* Set the selected source on primary MUX. */
729static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
730{
731 uint32_t regval;
732
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700733 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734 regval &= ~0x3;
735 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700736 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700737 /* Wait for switch to complete. */
738 mb();
739 udelay(1);
740}
741
742/* Get the selected source on secondary MUX. */
743static int get_sec_clk_src(struct scalable *sc)
744{
745 uint32_t regval;
746
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700747 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700748 return (regval >> 2) & 0x3;
749}
750
751/* Set the selected source on secondary MUX. */
752static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
753{
754 uint32_t regval;
755
756 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700757 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700758 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700759 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700760
761 /* Program the MUX. */
762 regval &= ~(0x3 << 2);
763 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700764 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700765
766 /* Wait for switch to complete. */
767 mb();
768 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700769
770 /* Re-enable secondary source clock gating. */
771 regval &= ~SECCLKAGD;
772 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700773}
774
775/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800776static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700777{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700778 int rc;
779
Matt Wagantallc1021762012-01-31 20:02:02 -0800780 if (!skip_regulators) {
781 if (cpu_is_msm8960()) {
782 rc = rpm_vreg_set_voltage(
783 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
784 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
David Collins9a81d6c2012-03-29 15:11:33 -0700785 2050000,
Matt Wagantallc1021762012-01-31 20:02:02 -0800786 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
787 if (rc)
788 pr_err("%s regulator enable failed (%d)\n",
789 sc->vreg[VREG_HFPLL_A].name, rc);
790 }
791 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
792 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
793 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800794 if (rc)
795 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800796 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800797 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700798 /* Disable PLL bypass mode. */
799 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
800
801 /*
802 * H/W requires a 5us delay between disabling the bypass and
803 * de-asserting the reset. Delay 10us just to be safe.
804 */
805 mb();
806 udelay(10);
807
808 /* De-assert active-low PLL reset. */
809 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
810
811 /* Wait for PLL to lock. */
812 mb();
813 udelay(60);
814
815 /* Enable PLL output. */
816 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
817}
818
819/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800820static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700822 int rc;
823
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700824 /*
825 * Disable the PLL output, disable test mode, enable
826 * the bypass mode, and assert the reset.
827 */
828 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700829
Matt Wagantallc1021762012-01-31 20:02:02 -0800830 if (!skip_regulators) {
831 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
832 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800833 0, 0);
834 if (rc)
835 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800836 sc->vreg[VREG_HFPLL_B].name, rc);
837
838 if (cpu_is_msm8960()) {
839 rc = rpm_vreg_set_voltage(
840 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
841 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
842 0, 0, 0);
843 if (rc)
844 pr_err("%s regulator enable failed (%d)\n",
845 sc->vreg[VREG_HFPLL_A].name, rc);
846 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800847 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700848}
849
850/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
851static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
852{
853 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
854}
855
856/* Return the L2 speed that should be applied. */
857static struct l2_level *compute_l2_level(struct scalable *sc,
858 struct l2_level *vote_l)
859{
860 struct l2_level *new_l;
861 int cpu;
862
863 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700864 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700865
866 /* Find max L2 speed vote. */
867 sc->l2_vote = vote_l;
868 new_l = l2_freq_tbl;
869 for_each_present_cpu(cpu)
870 new_l = max(new_l, scalable[cpu].l2_vote);
871
872 return new_l;
873}
874
875/* Update the bus bandwidth request. */
876static void set_bus_bw(unsigned int bw)
877{
878 int ret;
879
880 /* Bounds check. */
881 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
882 pr_err("invalid bandwidth request (%d)\n", bw);
883 return;
884 }
885
886 /* Update bandwidth if request has changed. This may sleep. */
887 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
888 if (ret)
889 pr_err("bandwidth request failed (%d)\n", ret);
890}
891
892/* Set the CPU or L2 clock speed. */
893static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
894 enum setrate_reason reason)
895{
896 struct core_speed *strt_s = sc->current_speed;
897
898 if (tgt_s == strt_s)
899 return;
900
901 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700903 * Move to an always-on source running at a frequency that does
904 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700905 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700906 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700907 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
908
909 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800910 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800912 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913
914 /* Move CPU to HFPLL source. */
915 set_pri_clk_src(sc, tgt_s->pri_src_sel);
916 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700917 /*
Matt Wagantall34c2d962012-02-01 14:30:02 -0800918 * If responding to CPU_DEAD we must be running on another CPU.
919 * Therefore, we can't access the downed CPU's clock MUX CP15
920 * registers from here and can't change clock sources. If the
921 * CPU is collapsed, however, it is still safe to turn off the
922 * PLL without switching the MUX away from it.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700923 */
924 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
925 set_sec_clk_src(sc, tgt_s->sec_src_sel);
926 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -0800927 hfpll_disable(sc, 0);
928 } else if (reason == SETRATE_HOTPLUG
929 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
930 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700933 /*
934 * If responding to CPU_UP_PREPARE, we can't change CP15
935 * registers for the CPU that's coming up since we're not
936 * running on that CPU. That's okay though, since the MUX
937 * source was not changed on the way down, either.
938 */
Matt Wagantall34c2d962012-02-01 14:30:02 -0800939 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
940 hfpll_set_rate(sc, tgt_s);
941 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700942 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -0800943 } else if (reason == SETRATE_HOTPLUG
944 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
945 /* PLL was disabled during hot-unplug. Re-enable it. */
946 hfpll_set_rate(sc, tgt_s);
947 hfpll_enable(sc, 0);
948 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
951 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700952 }
953
954 sc->current_speed = tgt_s;
955}
956
957/* Apply any per-cpu voltage increases. */
958static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
959 unsigned int vdd_dig, enum setrate_reason reason)
960{
961 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700962 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700963
964 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700965 * Increase vdd_mem active-set before vdd_dig.
966 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967 */
968 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
969 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
970 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
971 sc->vreg[VREG_MEM].max_vdd, 0);
972 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800973 pr_err("%s increase failed (%d)\n",
974 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975 return rc;
976 }
977 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
978 }
979
980 /* Increase vdd_dig active-set vote. */
981 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
982 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
983 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
984 sc->vreg[VREG_DIG].max_vdd, 0);
985 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800986 pr_err("%s increase failed (%d)\n",
987 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988 return rc;
989 }
990 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
991 }
992
993 /*
994 * Update per-CPU core voltage. Don't do this for the hotplug path for
995 * which it should already be correct. Attempting to set it is bad
996 * because we don't know what CPU we are running on at this point, but
997 * the CPU regulator API requires we call it from the affected CPU.
998 */
999 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
1000 && reason != SETRATE_HOTPLUG) {
1001 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1002 sc->vreg[VREG_CORE].max_vdd);
1003 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001004 pr_err("%s increase failed (%d)\n",
1005 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001006 return rc;
1007 }
1008 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1009 }
1010
1011 return rc;
1012}
1013
1014/* Apply any per-cpu voltage decreases. */
1015static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1016 unsigned int vdd_dig, enum setrate_reason reason)
1017{
1018 struct scalable *sc = &scalable[cpu];
1019 int ret;
1020
1021 /*
1022 * Update per-CPU core voltage. This must be called on the CPU
1023 * that's being affected. Don't do this in the hotplug remove path,
1024 * where the rail is off and we're executing on the other CPU.
1025 */
1026 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1027 && reason != SETRATE_HOTPLUG) {
1028 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1029 sc->vreg[VREG_CORE].max_vdd);
1030 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001031 pr_err("%s decrease failed (%d)\n",
1032 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001033 return;
1034 }
1035 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1036 }
1037
1038 /* Decrease vdd_dig active-set vote. */
1039 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1040 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1041 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1042 sc->vreg[VREG_DIG].max_vdd, 0);
1043 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001044 pr_err("%s decrease failed (%d)\n",
1045 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001046 return;
1047 }
1048 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1049 }
1050
1051 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001052 * Decrease vdd_mem active-set after vdd_dig.
1053 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001054 */
1055 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1056 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1057 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1058 sc->vreg[VREG_MEM].max_vdd, 0);
1059 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001060 pr_err("%s decrease failed (%d)\n",
1061 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001062 return;
1063 }
1064 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1065 }
1066}
1067
1068static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1069{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001070 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001071}
1072
1073static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1074{
1075 unsigned int pll_vdd_dig;
1076
Stephen Boydc76158f2011-12-08 12:42:40 -08001077 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001078 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001079 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001080 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1081 else
1082 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1083
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001084 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1085}
1086
Tianyi Gouaded6432012-02-22 14:53:05 -08001087static unsigned int calculate_vdd_core(struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001088{
Tianyi Gouaded6432012-02-22 14:53:05 -08001089 return tgt->vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001090}
1091
1092/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001093static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1094 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001095{
1096 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1097 struct l2_level *tgt_l2_l;
1098 struct acpu_level *tgt;
1099 unsigned int vdd_mem, vdd_dig, vdd_core;
1100 unsigned long flags;
1101 int rc = 0;
1102
1103 if (cpu > num_possible_cpus()) {
1104 rc = -EINVAL;
1105 goto out;
1106 }
1107
1108 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1109 mutex_lock(&driver_lock);
1110
1111 strt_acpu_s = scalable[cpu].current_speed;
1112
1113 /* Return early if rate didn't change. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001114 if (rate == strt_acpu_s->khz)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001115 goto out;
1116
1117 /* Find target frequency. */
1118 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1119 if (tgt->speed.khz == rate) {
1120 tgt_acpu_s = &tgt->speed;
1121 break;
1122 }
1123 }
1124 if (tgt->speed.khz == 0) {
1125 rc = -EINVAL;
1126 goto out;
1127 }
1128
1129 /* Calculate voltage requirements for the current CPU. */
1130 vdd_mem = calculate_vdd_mem(tgt);
1131 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gouaded6432012-02-22 14:53:05 -08001132 vdd_core = calculate_vdd_core(tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001133
1134 /* Increase VDD levels if needed. */
1135 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1136 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1137 if (rc)
1138 goto out;
1139 }
1140
1141 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1142 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1143
1144 /* Set the CPU speed. */
1145 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1146
1147 /*
1148 * Update the L2 vote and apply the rate change. A spinlock is
1149 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001150 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001151 * and the driver_lock mutex is not acquired.
1152 */
1153 spin_lock_irqsave(&l2_lock, flags);
1154 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1155 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1156 spin_unlock_irqrestore(&l2_lock, flags);
1157
1158 /* Nothing else to do for power collapse or SWFI. */
1159 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1160 goto out;
1161
1162 /* Update bus bandwith request. */
1163 set_bus_bw(tgt_l2_l->bw_level);
1164
1165 /* Drop VDD levels if we can. */
1166 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1167
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001168 pr_debug("ACPU%d speed change complete\n", cpu);
1169
1170out:
1171 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1172 mutex_unlock(&driver_lock);
1173 return rc;
1174}
1175
1176/* Initialize a HFPLL at a given rate and enable it. */
1177static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1178{
1179 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1180
1181 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001182 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001183
1184 /* Configure PLL parameters for integer mode. */
1185 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1186 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1187 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1188
1189 /* Program droop controller. */
1190 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1191
1192 /* Set an initial rate and enable the PLL. */
1193 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001194 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195}
1196
1197/* Voltage regulator initialization. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001198static void __init regulator_init(struct acpu_level *lvl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001199{
1200 int cpu, ret;
1201 struct scalable *sc;
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001202 unsigned int vdd_mem, vdd_dig, vdd_core;
1203
1204 vdd_mem = calculate_vdd_mem(lvl);
1205 vdd_dig = calculate_vdd_dig(lvl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206
1207 for_each_possible_cpu(cpu) {
1208 sc = &scalable[cpu];
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001209
1210 /* Set initial vdd_mem vote. */
1211 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1212 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1213 sc->vreg[VREG_MEM].max_vdd, 0);
1214 if (ret) {
1215 pr_err("%s initialization failed (%d)\n",
1216 sc->vreg[VREG_MEM].name, ret);
1217 BUG();
1218 }
1219 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1220
1221 /* Set initial vdd_dig vote. */
1222 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1223 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1224 sc->vreg[VREG_DIG].max_vdd, 0);
1225 if (ret) {
1226 pr_err("%s initialization failed (%d)\n",
1227 sc->vreg[VREG_DIG].name, ret);
1228 BUG();
1229 }
1230 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1231
1232 /* Setup Krait CPU regulators and initial core voltage. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1234 sc->vreg[VREG_CORE].name);
1235 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1236 pr_err("regulator_get(%s) failed (%ld)\n",
1237 sc->vreg[VREG_CORE].name,
1238 PTR_ERR(sc->vreg[VREG_CORE].reg));
1239 BUG();
1240 }
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001241 vdd_core = calculate_vdd_core(lvl);
1242 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001243 sc->vreg[VREG_CORE].max_vdd);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001244 if (ret) {
1245 pr_err("%s initialization failed (%d)\n",
1246 sc->vreg[VREG_CORE].name, ret);
1247 BUG();
1248 }
1249 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001251 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001252 pr_err("regulator_enable(%s) failed (%d)\n",
1253 sc->vreg[VREG_CORE].name, ret);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001254 BUG();
1255 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001256 }
1257}
1258
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001259/* Set initial rate for a given core. */
1260static void __init init_clock_sources(struct scalable *sc,
1261 struct core_speed *tgt_s)
1262{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001263 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001264
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001265 /* Select PLL8 as AUX source input to the secondary MUX. */
1266 writel_relaxed(0x3, sc->aux_clk_sel);
1267
1268 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001269 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001270 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001271 hfpll_init(sc, tgt_s);
1272
1273 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001274 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001275 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001276 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001277
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001278 /* Switch to the target clock source. */
1279 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001280 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1281 sc->current_speed = tgt_s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001282}
1283
Matt Wagantall8e726c72011-08-06 00:49:28 -07001284static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001285{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001286 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001287 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001288
1289 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1290 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001291}
1292
1293/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001294static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001295{
1296 int ret;
1297
1298 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1299 if (!bus_perf_client) {
1300 pr_err("unable to register bus client\n");
1301 BUG();
1302 }
1303
Stephen Boydcfe192b2011-12-09 21:47:14 -08001304 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001305 if (ret)
1306 pr_err("initial bandwidth request failed (%d)\n", ret);
1307}
1308
1309#ifdef CONFIG_CPU_FREQ_MSM
1310static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1311
1312static void __init cpufreq_table_init(void)
1313{
1314 int cpu;
1315
1316 for_each_possible_cpu(cpu) {
1317 int i, freq_cnt = 0;
1318 /* Construct the freq_table tables from acpu_freq_tbl. */
1319 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1320 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1321 if (acpu_freq_tbl[i].use_for_scaling) {
1322 freq_table[cpu][freq_cnt].index = freq_cnt;
1323 freq_table[cpu][freq_cnt].frequency
1324 = acpu_freq_tbl[i].speed.khz;
1325 freq_cnt++;
1326 }
1327 }
1328 /* freq_table not big enough to store all usable freqs. */
1329 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1330
1331 freq_table[cpu][freq_cnt].index = freq_cnt;
1332 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1333
1334 pr_info("CPU%d: %d scaling frequencies supported.\n",
1335 cpu, freq_cnt);
1336
1337 /* Register table with CPUFreq. */
1338 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1339 }
1340}
1341#else
1342static void __init cpufreq_table_init(void) {}
1343#endif
1344
1345#define HOT_UNPLUG_KHZ STBY_KHZ
1346static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1347 unsigned long action, void *hcpu)
1348{
1349 static int prev_khz[NR_CPUS];
1350 static int prev_pri_src[NR_CPUS];
1351 static int prev_sec_src[NR_CPUS];
1352 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001353
1354 switch (action) {
1355 case CPU_DYING:
1356 case CPU_DYING_FROZEN:
1357 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001358 * On Krait v1 and 8064v1, the primary and secondary muxes must
1359 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001360 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001361 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001362 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1363 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1364 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1365 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1366 }
1367 break;
1368 case CPU_DEAD:
1369 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001370 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001371 /* Fall through. */
1372 case CPU_UP_CANCELED:
1373 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001374 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001375 break;
1376 case CPU_UP_PREPARE:
1377 case CPU_UP_PREPARE_FROZEN:
1378 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001379 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001380 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001381 break;
1382 case CPU_STARTING:
1383 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001384 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001385 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1386 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1387 }
1388 break;
1389 default:
1390 break;
1391 }
1392
1393 return NOTIFY_OK;
1394}
1395
1396static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1397 .notifier_call = acpuclock_cpu_callback,
1398};
1399
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001400static const int krait_needs_vmin(void)
1401{
1402 switch (read_cpuid_id()) {
1403 case 0x511F04D0:
1404 case 0x511F04D1:
1405 case 0x510F06F0:
1406 return 1;
1407 default:
1408 return 0;
1409 };
1410}
1411
Stephen Boydaefb8de2012-01-05 19:05:01 -08001412static void kraitv2_apply_vmin(struct acpu_level *tbl)
1413{
1414 for (; tbl->speed.khz != 0; tbl++)
1415 if (tbl->vdd_core < 1150000)
1416 tbl->vdd_core = 1150000;
1417}
1418
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001419static struct acpu_level * __init select_freq_plan(void)
1420{
1421 struct acpu_level *l, *max_acpu_level = NULL;
1422
1423 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001424 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001425 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001426 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001427
1428 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1429 pvs = (pte_efuse >> 10) & 0x7;
1430 if (pvs == 0x7)
1431 pvs = (pte_efuse >> 13) & 0x7;
1432
1433 switch (pvs) {
1434 case 0x0:
1435 case 0x7:
1436 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001437 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1438 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001439 break;
1440 case 0x1:
1441 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001442 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001443 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001444 break;
1445 case 0x3:
1446 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001447 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001448 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001449 break;
1450 default:
1451 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001452 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1453 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001454 break;
1455 }
1456
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001457 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001458 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001459 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001460 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1461 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1462 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001463 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001464 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1465 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1466 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001467 } else if (cpu_is_apq8064()) {
1468 scalable = scalable_8064;
1469 acpu_freq_tbl = acpu_freq_tbl_8064;
1470 l2_freq_tbl = l2_freq_tbl_8064;
1471 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001472 } else if (cpu_is_msm8627()) {
1473 scalable = scalable_8627;
1474 acpu_freq_tbl = acpu_freq_tbl_8627;
1475 l2_freq_tbl = l2_freq_tbl_8627;
1476 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001477 } else if (cpu_is_msm8930()) {
1478 scalable = scalable_8930;
1479 acpu_freq_tbl = acpu_freq_tbl_8930;
1480 l2_freq_tbl = l2_freq_tbl_8930;
1481 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001482 } else {
1483 BUG();
1484 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001485 if (krait_needs_vmin())
1486 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001487
1488 /* Find the max supported scaling frequency. */
1489 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1490 if (l->use_for_scaling)
1491 max_acpu_level = l;
1492 BUG_ON(!max_acpu_level);
1493 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1494
1495 return max_acpu_level;
1496}
1497
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001498static struct acpuclk_data acpuclk_8960_data = {
1499 .set_rate = acpuclk_8960_set_rate,
1500 .get_rate = acpuclk_8960_get_rate,
1501 .power_collapse_khz = STBY_KHZ,
1502 .wait_for_irq_khz = STBY_KHZ,
1503};
1504
Matt Wagantallec57f062011-08-16 23:54:46 -07001505static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001506{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001507 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001508
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001509 regulator_init(max_acpu_level);
Stephen Boydcfe192b2011-12-09 21:47:14 -08001510 bus_init(max_acpu_level->l2_level->bw_level);
1511
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001512 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1513 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001514
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001515 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001516
1517 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001518 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001519
1520 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001521}
Matt Wagantallec57f062011-08-16 23:54:46 -07001522
1523struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1524 .init = acpuclk_8960_init,
1525};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001526
1527struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1528 .init = acpuclk_8960_init,
1529};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001530
1531struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1532 .init = acpuclk_8960_init,
1533};