blob: a58eb6e2779391a0e84ece72cef2f469e0046096 [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
Tianyi Goudff51062012-06-04 20:22:23 -0700108enum pvs {
109 PVS_SLOW,
110 PVS_NOM,
111 PVS_FAST,
112 PVS_FASTER,
113 NUM_PVS
114};
115
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116struct vreg {
117 const char name[15];
118 const unsigned int max_vdd;
119 const int rpm_vreg_voter;
120 const int rpm_vreg_id;
121 struct regulator *reg;
122 unsigned int cur_vdd;
123};
124
125struct core_speed {
126 unsigned int khz;
127 int src;
128 unsigned int pri_src_sel;
129 unsigned int sec_src_sel;
130 unsigned int pll_l_val;
131};
132
133struct l2_level {
134 struct core_speed speed;
135 unsigned int vdd_dig;
136 unsigned int vdd_mem;
137 unsigned int bw_level;
138};
139
140struct acpu_level {
141 unsigned int use_for_scaling;
142 struct core_speed speed;
143 struct l2_level *l2_level;
144 unsigned int vdd_core;
145};
146
147struct scalable {
148 void * __iomem const hfpll_base;
149 void * __iomem const aux_clk_sel;
150 const uint32_t l2cpmr_iaddr;
151 struct core_speed *current_speed;
152 struct l2_level *l2_vote;
153 struct vreg vreg[NUM_VREG];
Tianyi Gou50705682012-02-21 17:51:50 -0800154 unsigned int *hfpll_vdd_tbl;
155};
156
157static unsigned int hfpll_vdd_tbl_8960[] = {
158 [HFPLL_VDD_NONE] = 0,
159 [HFPLL_VDD_LOW] = 850000,
160 [HFPLL_VDD_NOM] = 1050000
161};
162
163static unsigned int hfpll_vdd_tbl_8064[] = {
164 [HFPLL_VDD_NONE] = 0,
165 [HFPLL_VDD_LOW] = 945000,
166 [HFPLL_VDD_NOM] = 1050000
167};
168
169static unsigned int hfpll_vdd_dig_tbl_8930[] = {
170 [HFPLL_VDD_NONE] = LVL_NONE,
171 [HFPLL_VDD_LOW] = LVL_LOW,
172 [HFPLL_VDD_NOM] = LVL_NOM
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173};
174
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700175static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176 [CPU0] = {
177 .hfpll_base = MSM_HFPLL_BASE + 0x200,
178 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
179 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800180 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
182 RPM_VREG_VOTER1,
183 RPM_VREG_ID_PM8921_L24 },
184 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
185 RPM_VREG_VOTER1,
186 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800187 .vreg[VREG_HFPLL_A] = { "hfpll0_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700188 RPM_VREG_VOTER1,
189 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800190 .vreg[VREG_HFPLL_B] = { "hfpll0_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700191 RPM_VREG_VOTER1,
192 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193 },
194 [CPU1] = {
195 .hfpll_base = MSM_HFPLL_BASE + 0x300,
196 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
197 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800198 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800199 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200 RPM_VREG_VOTER2,
201 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800202 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203 RPM_VREG_VOTER2,
204 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800205 .vreg[VREG_HFPLL_A] = { "hfpll1_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700206 RPM_VREG_VOTER2,
207 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800208 .vreg[VREG_HFPLL_B] = { "hfpll1_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700209 RPM_VREG_VOTER2,
210 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 },
212 [L2] = {
213 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800214 .hfpll_vdd_tbl = hfpll_vdd_tbl_8960,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700215 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
216 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800217 .vreg[VREG_HFPLL_A] = { "hfpll_l2_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700218 RPM_VREG_VOTER6,
219 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800220 .vreg[VREG_HFPLL_B] = { "hfpll_l2_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700221 RPM_VREG_VOTER6,
222 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700223 },
224};
225
Stephen Boyd7ad84752011-08-05 14:04:28 -0700226static DEFINE_MUTEX(driver_lock);
227static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700228
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700229static struct scalable scalable_8064[] = {
230 [CPU0] = {
231 .hfpll_base = MSM_HFPLL_BASE + 0x200,
232 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
233 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800234 .vreg[VREG_CORE] = { "krait0", 1300000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700235 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
236 RPM_VREG_VOTER1,
237 RPM_VREG_ID_PM8921_L24 },
238 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
239 RPM_VREG_VOTER1,
240 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800241 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800242 RPM_VREG_VOTER1,
243 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700244 },
245 [CPU1] = {
246 .hfpll_base = MSM_HFPLL_BASE + 0x240,
247 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
248 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800249 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800250 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700251 RPM_VREG_VOTER2,
252 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800253 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700254 RPM_VREG_VOTER2,
255 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800256 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800257 RPM_VREG_VOTER2,
258 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700259 },
260 [CPU2] = {
261 .hfpll_base = MSM_HFPLL_BASE + 0x280,
262 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
263 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800264 .vreg[VREG_CORE] = { "krait2", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800265 .vreg[VREG_MEM] = { "krait2_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700266 RPM_VREG_VOTER4,
267 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800268 .vreg[VREG_DIG] = { "krait2_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700269 RPM_VREG_VOTER4,
270 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800271 .vreg[VREG_HFPLL_B] = { "hfpll2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800272 RPM_VREG_VOTER4,
273 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700274 },
275 [CPU3] = {
276 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
277 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
278 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800279 .vreg[VREG_CORE] = { "krait3", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800280 .vreg[VREG_MEM] = { "krait3_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700281 RPM_VREG_VOTER5,
282 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800283 .vreg[VREG_DIG] = { "krait3_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700284 RPM_VREG_VOTER5,
285 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800286 .vreg[VREG_HFPLL_B] = { "hfpll3", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800287 RPM_VREG_VOTER5,
288 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700289 },
290 [L2] = {
291 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800292 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700293 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
294 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800295 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800296 RPM_VREG_VOTER6,
297 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700298 },
299};
300
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800301static struct scalable scalable_8930[] = {
302 [CPU0] = {
303 .hfpll_base = MSM_HFPLL_BASE + 0x200,
304 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
305 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
306 .vreg[VREG_CORE] = { "krait0", 1300000 },
307 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
308 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800309 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800310 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800311 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800312 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
313 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800314 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800315 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800316 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800317 },
318 [CPU1] = {
319 .hfpll_base = MSM_HFPLL_BASE + 0x300,
320 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
321 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
322 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800323 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800324 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800325 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800326 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800327 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800328 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
329 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800330 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800331 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800332 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800333 },
334 [L2] = {
335 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800336 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800337 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
338 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800339 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800340 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800341 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800342 },
343};
344
Tianyi Goue0b34de2011-12-20 11:20:10 -0800345/*TODO: Update the rpm vreg id when the rpm driver is ready */
346static struct scalable scalable_8627[] = {
347 [CPU0] = {
348 .hfpll_base = MSM_HFPLL_BASE + 0x200,
349 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
350 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
351 .vreg[VREG_CORE] = { "krait0", 1300000 },
352 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
353 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800354 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800355 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800356 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800357 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
358 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800359 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800360 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800361 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800362 },
363 [CPU1] = {
364 .hfpll_base = MSM_HFPLL_BASE + 0x300,
365 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
366 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
367 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800368 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800369 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800370 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800371 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800372 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800373 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
374 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800375 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800376 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800377 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800378 },
379 [L2] = {
380 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou73712ed2012-05-23 12:18:29 -0700381 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800382 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
383 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800384 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800385 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800386 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800387 },
388};
389
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700390static struct l2_level *l2_freq_tbl;
391static struct acpu_level *acpu_freq_tbl;
392static int l2_freq_tbl_size;
Matt Wagantall34c2d962012-02-01 14:30:02 -0800393static struct scalable *scalable;
394#define SCALABLE_TO_CPU(sc) ((sc) - scalable)
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700395
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700396/* Instantaneous bandwidth requests in MB/s. */
397#define BW_MBPS(_bw) \
398 { \
399 .vectors = (struct msm_bus_vectors[]){ \
400 {\
401 .src = MSM_BUS_MASTER_AMPSS_M0, \
402 .dst = MSM_BUS_SLAVE_EBI_CH0, \
403 .ib = (_bw) * 1000000UL, \
404 .ab = (_bw) * 100000UL, \
405 }, \
406 { \
407 .src = MSM_BUS_MASTER_AMPSS_M1, \
408 .dst = MSM_BUS_SLAVE_EBI_CH0, \
409 .ib = (_bw) * 1000000UL, \
410 .ab = (_bw) * 100000UL, \
411 }, \
412 }, \
413 .num_paths = 2, \
414 }
415static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800416 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
417 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
418 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
419 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
420 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
421 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
422 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800423 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700424};
425
426static struct msm_bus_scale_pdata bus_client_pdata = {
427 .usecase = bw_level_tbl,
428 .num_usecases = ARRAY_SIZE(bw_level_tbl),
429 .active_only = 1,
430 .name = "acpuclock",
431};
432
433static uint32_t bus_perf_client;
434
435/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800436#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
437static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700438 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700439 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700440 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
441 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
442 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
443 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
444 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
445 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700446 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700447 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
448 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
449 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700450};
451
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800452static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
453 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
454 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
455 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
456 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
457 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
458 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
459 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
460 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
461 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
462 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
463 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
464 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
465 { 0, { 0 } }
466};
467
468static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
469 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
470 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
471 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
472 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
473 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
474 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
475 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
476 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
477 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
478 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
479 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
480 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700481 { 0, { 0 } }
482};
483
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800484#undef L2
485#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
486static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
487 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
488 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800489 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
490 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
491 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800492 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800493 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
494 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
495 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
496 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
497 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
498 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
499 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
500 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
501 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
502 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
503 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800504 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
505 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
506 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800507};
508
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800509static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800510 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
511 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800512 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
513 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
514 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
515 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
516 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
517 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
518 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
519 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
520 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
521 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
522 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
523 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
Stephen Boydb2e41d02012-06-01 11:21:13 -0700524 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(19), 1175000 },
525 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(19), 1175000 },
526 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(19), 1200000 },
527 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1200000 },
528 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1225000 },
529 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1225000 },
530 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1237500 },
531 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1237500 },
532 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800533 { 0, { 0 } }
534};
535
536static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800537 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
538 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800539 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
540 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
541 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
542 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
543 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
544 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
545 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
546 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
547 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
548 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
549 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
550 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
Stephen Boydb2e41d02012-06-01 11:21:13 -0700551 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(19), 1125000 },
552 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(19), 1125000 },
553 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(19), 1150000 },
554 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1150000 },
555 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1175000 },
556 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1175000 },
557 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1187500 },
558 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1187500 },
559 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800560 { 0, { 0 } }
561};
562
Stephen Boyd5766f682011-12-27 19:21:08 -0800563static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800564 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
565 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800566 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
567 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
568 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
569 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
570 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
571 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
572 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
573 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
574 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
575 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
576 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
577 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
Stephen Boydb2e41d02012-06-01 11:21:13 -0700578 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(19), 1075000 },
579 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(19), 1075000 },
580 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(19), 1100000 },
581 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(19), 1100000 },
582 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(19), 1125000 },
583 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(19), 1125000 },
584 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(19), 1137500 },
585 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(19), 1137500 },
586 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(19), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800587 { 0, { 0 } }
588};
589
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700590/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
591#undef L2
592#define L2(x) (&l2_freq_tbl_8064[(x)])
593static struct l2_level l2_freq_tbl_8064[] = {
594 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800595 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
596 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
597 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
598 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700599 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800600 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
601 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
602 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
603 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
604 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
605 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
606 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
607 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
608 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
609 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700610};
611
612/* TODO: Update core voltages when data is available. */
Tianyi Goudff51062012-06-04 20:22:23 -0700613static struct acpu_level acpu_freq_tbl_8064_slow[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800614 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
615 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
616 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
617 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
618 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
619 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
620 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
621 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
622 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
623 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
624 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
625 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
626 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
627 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
628 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
629 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
630 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
631 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
632 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
633 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
634 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
635 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
636 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700637 { 0, { 0 } }
638};
639
Tianyi Goudff51062012-06-04 20:22:23 -0700640static struct acpu_level acpu_freq_tbl_8064_nom[] = {
641 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
642 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
643 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
644 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
645 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
646 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
647 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
648 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
649 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
650 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
651 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
652 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
653 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
654 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
655 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1125000 },
656 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1125000 },
657 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1150000 },
658 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1150000 },
659 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1175000 },
660 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1175000 },
661 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1187500 },
662 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1187500 },
663 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1212500 },
664 { 0, { 0 } }
665};
666
667static struct acpu_level acpu_freq_tbl_8064_fast[] = {
668 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
669 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
670 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
671 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
672 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
673 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
674 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
675 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
676 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
677 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
678 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
679 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
680 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
681 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
682 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1075000 },
683 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1075000 },
684 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1100000 },
685 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1100000 },
686 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1125000 },
687 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1125000 },
688 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1137500 },
689 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1137500 },
690 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1175000 },
691 { 0, { 0 } }
692};
693
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800694/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
695#undef L2
696#define L2(x) (&l2_freq_tbl_8930[(x)])
697static struct l2_level l2_freq_tbl_8930[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800698 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
699 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800700 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 2 },
701 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 2 },
702 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
Tianyi Gou50705682012-02-21 17:51:50 -0800703 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
Tianyi Goud03f4622012-01-04 19:29:00 -0800704 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 4 },
705 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 4 },
706 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 4 },
707 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 4 },
708 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
709 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 7 },
710 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 7 },
711 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, LVL_HIGH, 1150000, 7 },
712 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, LVL_HIGH, 1150000, 7 },
713 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, LVL_HIGH, 1150000, 7 },
714 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, LVL_HIGH, 1150000, 7 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800715};
716
717/* TODO: Update core voltages when data is available. */
718static struct acpu_level acpu_freq_tbl_8930[] = {
Tianyi Goud911dd12012-05-10 21:06:40 -0700719 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 925000 },
720 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 925000 },
721 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 937500 },
722 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 962500 },
723 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 987500 },
724 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
725 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
726 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1037500 },
727 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1062500 },
728 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1087500 },
729 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
730 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1125000 },
731 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1137500 },
732 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1162500 },
733 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1187500 },
734 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1200000 },
735 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1225000 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800736 { 0, { 0 } }
737};
738
Tianyi Goue0b34de2011-12-20 11:20:10 -0800739/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
740#undef L2
741#define L2(x) (&l2_freq_tbl_8627[(x)])
742static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800743 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
744 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
745 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
746 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
747 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
748 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
749 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
750 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
751 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
752 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
753 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
754 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
755 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800756};
757
758/* TODO: Update core voltages when data is available. */
759static struct acpu_level acpu_freq_tbl_8627[] = {
760 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
761 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
762 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
763 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
764 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
765 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
766 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
767 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
768 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
769 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
770 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
771 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
772 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
773 { 0, { 0 } }
774};
775
Tianyi Goudff51062012-06-04 20:22:23 -0700776static struct acpu_level *acpu_freq_tbl_8960_v1[NUM_PVS] __initdata = {
777 [PVS_SLOW] = acpu_freq_tbl_8960_kraitv1_slow,
778 [PVS_NOM] = acpu_freq_tbl_8960_kraitv1_nom_fast,
779 [PVS_FAST] = acpu_freq_tbl_8960_kraitv1_nom_fast,
780};
781
782static struct acpu_level *acpu_freq_tbl_8960_v2[NUM_PVS] __initdata = {
783 [PVS_SLOW] = acpu_freq_tbl_8960_kraitv2_slow,
784 [PVS_NOM] = acpu_freq_tbl_8960_kraitv2_nom,
785 [PVS_FAST] = acpu_freq_tbl_8960_kraitv2_fast,
786};
787
788/* TODO: update the faster table when data is available */
789static struct acpu_level *acpu_freq_tbl_8064[NUM_PVS] __initdata = {
790 [PVS_SLOW] = acpu_freq_tbl_8064_slow,
791 [PVS_NOM] = acpu_freq_tbl_8064_nom,
792 [PVS_FAST] = acpu_freq_tbl_8064_fast,
793 [PVS_FASTER] = acpu_freq_tbl_8064_fast,
794};
795
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700796static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700797{
798 return scalable[cpu].current_speed->khz;
799}
800
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700801/* Get the selected source on primary MUX. */
802static int get_pri_clk_src(struct scalable *sc)
803{
804 uint32_t regval;
805
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700806 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700807 return regval & 0x3;
808}
809
810/* Set the selected source on primary MUX. */
811static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
812{
813 uint32_t regval;
814
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700815 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700816 regval &= ~0x3;
817 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700818 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700819 /* Wait for switch to complete. */
820 mb();
821 udelay(1);
822}
823
824/* Get the selected source on secondary MUX. */
825static int get_sec_clk_src(struct scalable *sc)
826{
827 uint32_t regval;
828
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700829 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 return (regval >> 2) & 0x3;
831}
832
833/* Set the selected source on secondary MUX. */
834static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
835{
836 uint32_t regval;
837
838 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700839 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700840 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700841 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700842
843 /* Program the MUX. */
844 regval &= ~(0x3 << 2);
845 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700846 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700847
848 /* Wait for switch to complete. */
849 mb();
850 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700851
852 /* Re-enable secondary source clock gating. */
853 regval &= ~SECCLKAGD;
854 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855}
856
857/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800858static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700859{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700860 int rc;
861
Matt Wagantallc1021762012-01-31 20:02:02 -0800862 if (!skip_regulators) {
863 if (cpu_is_msm8960()) {
864 rc = rpm_vreg_set_voltage(
865 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
866 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
David Collins9a81d6c2012-03-29 15:11:33 -0700867 2050000,
Matt Wagantallc1021762012-01-31 20:02:02 -0800868 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
869 if (rc)
870 pr_err("%s regulator enable failed (%d)\n",
871 sc->vreg[VREG_HFPLL_A].name, rc);
872 }
873 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
874 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
875 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800876 if (rc)
877 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800878 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800879 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880 /* Disable PLL bypass mode. */
881 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
882
883 /*
884 * H/W requires a 5us delay between disabling the bypass and
885 * de-asserting the reset. Delay 10us just to be safe.
886 */
887 mb();
888 udelay(10);
889
890 /* De-assert active-low PLL reset. */
891 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
892
893 /* Wait for PLL to lock. */
894 mb();
895 udelay(60);
896
897 /* Enable PLL output. */
898 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
899}
900
901/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800902static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700904 int rc;
905
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906 /*
907 * Disable the PLL output, disable test mode, enable
908 * the bypass mode, and assert the reset.
909 */
910 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700911
Matt Wagantallc1021762012-01-31 20:02:02 -0800912 if (!skip_regulators) {
913 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
914 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800915 0, 0);
916 if (rc)
917 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800918 sc->vreg[VREG_HFPLL_B].name, rc);
919
920 if (cpu_is_msm8960()) {
921 rc = rpm_vreg_set_voltage(
922 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
923 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
924 0, 0, 0);
925 if (rc)
926 pr_err("%s regulator enable failed (%d)\n",
927 sc->vreg[VREG_HFPLL_A].name, rc);
928 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800929 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930}
931
932/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
933static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
934{
935 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
936}
937
938/* Return the L2 speed that should be applied. */
939static struct l2_level *compute_l2_level(struct scalable *sc,
940 struct l2_level *vote_l)
941{
942 struct l2_level *new_l;
943 int cpu;
944
945 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700946 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700947
948 /* Find max L2 speed vote. */
949 sc->l2_vote = vote_l;
950 new_l = l2_freq_tbl;
951 for_each_present_cpu(cpu)
952 new_l = max(new_l, scalable[cpu].l2_vote);
953
954 return new_l;
955}
956
957/* Update the bus bandwidth request. */
958static void set_bus_bw(unsigned int bw)
959{
960 int ret;
961
962 /* Bounds check. */
963 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
964 pr_err("invalid bandwidth request (%d)\n", bw);
965 return;
966 }
967
968 /* Update bandwidth if request has changed. This may sleep. */
969 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
970 if (ret)
971 pr_err("bandwidth request failed (%d)\n", ret);
972}
973
974/* Set the CPU or L2 clock speed. */
975static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
976 enum setrate_reason reason)
977{
978 struct core_speed *strt_s = sc->current_speed;
979
980 if (tgt_s == strt_s)
981 return;
982
983 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700984 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700985 * Move to an always-on source running at a frequency that does
986 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700988 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700989 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
990
991 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800992 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700993 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800994 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700995
996 /* Move CPU to HFPLL source. */
997 set_pri_clk_src(sc, tgt_s->pri_src_sel);
998 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700999 /*
Matt Wagantall34c2d962012-02-01 14:30:02 -08001000 * If responding to CPU_DEAD we must be running on another CPU.
1001 * Therefore, we can't access the downed CPU's clock MUX CP15
1002 * registers from here and can't change clock sources. If the
1003 * CPU is collapsed, however, it is still safe to turn off the
1004 * PLL without switching the MUX away from it.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001005 */
1006 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
1007 set_sec_clk_src(sc, tgt_s->sec_src_sel);
1008 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -08001009 hfpll_disable(sc, 0);
1010 } else if (reason == SETRATE_HOTPLUG
1011 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
1012 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001013 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001014 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001015 /*
1016 * If responding to CPU_UP_PREPARE, we can't change CP15
1017 * registers for the CPU that's coming up since we're not
1018 * running on that CPU. That's okay though, since the MUX
1019 * source was not changed on the way down, either.
1020 */
Matt Wagantall34c2d962012-02-01 14:30:02 -08001021 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
1022 hfpll_set_rate(sc, tgt_s);
1023 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001024 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -08001025 } else if (reason == SETRATE_HOTPLUG
1026 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
1027 /* PLL was disabled during hot-unplug. Re-enable it. */
1028 hfpll_set_rate(sc, tgt_s);
1029 hfpll_enable(sc, 0);
1030 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001031 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001032 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
1033 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001034 }
1035
1036 sc->current_speed = tgt_s;
1037}
1038
1039/* Apply any per-cpu voltage increases. */
1040static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1041 unsigned int vdd_dig, enum setrate_reason reason)
1042{
1043 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -07001044 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001045
1046 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001047 * Increase vdd_mem active-set before vdd_dig.
1048 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001049 */
1050 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
1051 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1052 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1053 sc->vreg[VREG_MEM].max_vdd, 0);
1054 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001055 pr_err("%s increase failed (%d)\n",
1056 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001057 return rc;
1058 }
1059 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1060 }
1061
1062 /* Increase vdd_dig active-set vote. */
1063 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
1064 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1065 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1066 sc->vreg[VREG_DIG].max_vdd, 0);
1067 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001068 pr_err("%s increase failed (%d)\n",
1069 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001070 return rc;
1071 }
1072 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1073 }
1074
1075 /*
1076 * Update per-CPU core voltage. Don't do this for the hotplug path for
1077 * which it should already be correct. Attempting to set it is bad
1078 * because we don't know what CPU we are running on at this point, but
1079 * the CPU regulator API requires we call it from the affected CPU.
1080 */
1081 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
1082 && reason != SETRATE_HOTPLUG) {
1083 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1084 sc->vreg[VREG_CORE].max_vdd);
1085 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001086 pr_err("%s increase failed (%d)\n",
1087 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001088 return rc;
1089 }
1090 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1091 }
1092
1093 return rc;
1094}
1095
1096/* Apply any per-cpu voltage decreases. */
1097static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1098 unsigned int vdd_dig, enum setrate_reason reason)
1099{
1100 struct scalable *sc = &scalable[cpu];
1101 int ret;
1102
1103 /*
1104 * Update per-CPU core voltage. This must be called on the CPU
1105 * that's being affected. Don't do this in the hotplug remove path,
1106 * where the rail is off and we're executing on the other CPU.
1107 */
1108 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1109 && reason != SETRATE_HOTPLUG) {
1110 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1111 sc->vreg[VREG_CORE].max_vdd);
1112 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001113 pr_err("%s decrease failed (%d)\n",
1114 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001115 return;
1116 }
1117 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1118 }
1119
1120 /* Decrease vdd_dig active-set vote. */
1121 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1122 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1123 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1124 sc->vreg[VREG_DIG].max_vdd, 0);
1125 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001126 pr_err("%s decrease failed (%d)\n",
1127 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001128 return;
1129 }
1130 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1131 }
1132
1133 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001134 * Decrease vdd_mem active-set after vdd_dig.
1135 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001136 */
1137 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1138 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1139 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1140 sc->vreg[VREG_MEM].max_vdd, 0);
1141 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001142 pr_err("%s decrease failed (%d)\n",
1143 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001144 return;
1145 }
1146 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1147 }
1148}
1149
1150static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1151{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001152 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001153}
1154
1155static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1156{
1157 unsigned int pll_vdd_dig;
1158
Stephen Boydc76158f2011-12-08 12:42:40 -08001159 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001160 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001161 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001162 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1163 else
1164 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1165
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001166 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1167}
1168
Tianyi Gouaded6432012-02-22 14:53:05 -08001169static unsigned int calculate_vdd_core(struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001170{
Tianyi Gouaded6432012-02-22 14:53:05 -08001171 return tgt->vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001172}
1173
1174/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001175static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1176 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177{
1178 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1179 struct l2_level *tgt_l2_l;
1180 struct acpu_level *tgt;
1181 unsigned int vdd_mem, vdd_dig, vdd_core;
1182 unsigned long flags;
1183 int rc = 0;
1184
1185 if (cpu > num_possible_cpus()) {
1186 rc = -EINVAL;
1187 goto out;
1188 }
1189
1190 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1191 mutex_lock(&driver_lock);
1192
1193 strt_acpu_s = scalable[cpu].current_speed;
1194
1195 /* Return early if rate didn't change. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001196 if (rate == strt_acpu_s->khz)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001197 goto out;
1198
1199 /* Find target frequency. */
1200 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1201 if (tgt->speed.khz == rate) {
1202 tgt_acpu_s = &tgt->speed;
1203 break;
1204 }
1205 }
1206 if (tgt->speed.khz == 0) {
1207 rc = -EINVAL;
1208 goto out;
1209 }
1210
1211 /* Calculate voltage requirements for the current CPU. */
1212 vdd_mem = calculate_vdd_mem(tgt);
1213 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gouaded6432012-02-22 14:53:05 -08001214 vdd_core = calculate_vdd_core(tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001215
1216 /* Increase VDD levels if needed. */
1217 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1218 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1219 if (rc)
1220 goto out;
1221 }
1222
1223 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1224 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1225
1226 /* Set the CPU speed. */
1227 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1228
1229 /*
1230 * Update the L2 vote and apply the rate change. A spinlock is
1231 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001232 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001233 * and the driver_lock mutex is not acquired.
1234 */
1235 spin_lock_irqsave(&l2_lock, flags);
1236 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1237 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1238 spin_unlock_irqrestore(&l2_lock, flags);
1239
1240 /* Nothing else to do for power collapse or SWFI. */
1241 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1242 goto out;
1243
1244 /* Update bus bandwith request. */
1245 set_bus_bw(tgt_l2_l->bw_level);
1246
1247 /* Drop VDD levels if we can. */
1248 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1249
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250 pr_debug("ACPU%d speed change complete\n", cpu);
1251
1252out:
1253 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1254 mutex_unlock(&driver_lock);
1255 return rc;
1256}
1257
1258/* Initialize a HFPLL at a given rate and enable it. */
1259static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1260{
1261 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1262
1263 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001264 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265
1266 /* Configure PLL parameters for integer mode. */
1267 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1268 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1269 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1270
1271 /* Program droop controller. */
1272 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1273
1274 /* Set an initial rate and enable the PLL. */
1275 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001276 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001277}
1278
1279/* Voltage regulator initialization. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001280static void __init regulator_init(struct acpu_level *lvl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001281{
1282 int cpu, ret;
1283 struct scalable *sc;
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001284 unsigned int vdd_mem, vdd_dig, vdd_core;
1285
1286 vdd_mem = calculate_vdd_mem(lvl);
1287 vdd_dig = calculate_vdd_dig(lvl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001288
1289 for_each_possible_cpu(cpu) {
1290 sc = &scalable[cpu];
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001291
1292 /* Set initial vdd_mem vote. */
1293 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1294 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1295 sc->vreg[VREG_MEM].max_vdd, 0);
1296 if (ret) {
1297 pr_err("%s initialization failed (%d)\n",
1298 sc->vreg[VREG_MEM].name, ret);
1299 BUG();
1300 }
1301 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1302
1303 /* Set initial vdd_dig vote. */
1304 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1305 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1306 sc->vreg[VREG_DIG].max_vdd, 0);
1307 if (ret) {
1308 pr_err("%s initialization failed (%d)\n",
1309 sc->vreg[VREG_DIG].name, ret);
1310 BUG();
1311 }
1312 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1313
1314 /* Setup Krait CPU regulators and initial core voltage. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001315 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1316 sc->vreg[VREG_CORE].name);
1317 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1318 pr_err("regulator_get(%s) failed (%ld)\n",
1319 sc->vreg[VREG_CORE].name,
1320 PTR_ERR(sc->vreg[VREG_CORE].reg));
1321 BUG();
1322 }
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001323 vdd_core = calculate_vdd_core(lvl);
1324 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001325 sc->vreg[VREG_CORE].max_vdd);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001326 if (ret) {
1327 pr_err("%s initialization failed (%d)\n",
1328 sc->vreg[VREG_CORE].name, ret);
1329 BUG();
1330 }
1331 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001332 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001333 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001334 pr_err("regulator_enable(%s) failed (%d)\n",
1335 sc->vreg[VREG_CORE].name, ret);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001336 BUG();
1337 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001338 }
1339}
1340
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001341/* Set initial rate for a given core. */
1342static void __init init_clock_sources(struct scalable *sc,
1343 struct core_speed *tgt_s)
1344{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001345 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001346
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001347 /* Select PLL8 as AUX source input to the secondary MUX. */
1348 writel_relaxed(0x3, sc->aux_clk_sel);
1349
1350 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001351 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001352 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001353 hfpll_init(sc, tgt_s);
1354
1355 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001356 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001357 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001358 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001359
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001360 /* Switch to the target clock source. */
1361 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001362 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1363 sc->current_speed = tgt_s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001364}
1365
Matt Wagantall8e726c72011-08-06 00:49:28 -07001366static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001367{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001368 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001369 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001370
1371 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1372 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001373}
1374
1375/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001376static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001377{
1378 int ret;
1379
1380 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1381 if (!bus_perf_client) {
1382 pr_err("unable to register bus client\n");
1383 BUG();
1384 }
1385
Stephen Boydcfe192b2011-12-09 21:47:14 -08001386 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001387 if (ret)
1388 pr_err("initial bandwidth request failed (%d)\n", ret);
1389}
1390
1391#ifdef CONFIG_CPU_FREQ_MSM
1392static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1393
1394static void __init cpufreq_table_init(void)
1395{
1396 int cpu;
1397
1398 for_each_possible_cpu(cpu) {
1399 int i, freq_cnt = 0;
1400 /* Construct the freq_table tables from acpu_freq_tbl. */
1401 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1402 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1403 if (acpu_freq_tbl[i].use_for_scaling) {
1404 freq_table[cpu][freq_cnt].index = freq_cnt;
1405 freq_table[cpu][freq_cnt].frequency
1406 = acpu_freq_tbl[i].speed.khz;
1407 freq_cnt++;
1408 }
1409 }
1410 /* freq_table not big enough to store all usable freqs. */
1411 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1412
1413 freq_table[cpu][freq_cnt].index = freq_cnt;
1414 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1415
1416 pr_info("CPU%d: %d scaling frequencies supported.\n",
1417 cpu, freq_cnt);
1418
1419 /* Register table with CPUFreq. */
1420 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1421 }
1422}
1423#else
1424static void __init cpufreq_table_init(void) {}
1425#endif
1426
1427#define HOT_UNPLUG_KHZ STBY_KHZ
1428static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1429 unsigned long action, void *hcpu)
1430{
1431 static int prev_khz[NR_CPUS];
1432 static int prev_pri_src[NR_CPUS];
1433 static int prev_sec_src[NR_CPUS];
1434 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001435
1436 switch (action) {
1437 case CPU_DYING:
1438 case CPU_DYING_FROZEN:
1439 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001440 * On Krait v1 and 8064v1, the primary and secondary muxes must
1441 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001442 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001443 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001444 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1445 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1446 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1447 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1448 }
1449 break;
1450 case CPU_DEAD:
1451 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001452 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001453 /* Fall through. */
1454 case CPU_UP_CANCELED:
1455 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001456 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001457 break;
1458 case CPU_UP_PREPARE:
1459 case CPU_UP_PREPARE_FROZEN:
1460 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001461 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001462 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001463 break;
1464 case CPU_STARTING:
1465 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001466 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001467 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1468 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1469 }
1470 break;
1471 default:
1472 break;
1473 }
1474
1475 return NOTIFY_OK;
1476}
1477
1478static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1479 .notifier_call = acpuclock_cpu_callback,
1480};
1481
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001482static const int krait_needs_vmin(void)
1483{
1484 switch (read_cpuid_id()) {
1485 case 0x511F04D0:
1486 case 0x511F04D1:
1487 case 0x510F06F0:
1488 return 1;
1489 default:
1490 return 0;
1491 };
1492}
1493
Stephen Boydaefb8de2012-01-05 19:05:01 -08001494static void kraitv2_apply_vmin(struct acpu_level *tbl)
1495{
1496 for (; tbl->speed.khz != 0; tbl++)
1497 if (tbl->vdd_core < 1150000)
1498 tbl->vdd_core = 1150000;
1499}
1500
Tianyi Goudff51062012-06-04 20:22:23 -07001501static enum pvs __init get_pvs(void)
1502{
1503 uint32_t pte_efuse, pvs;
1504
1505 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1506 pvs = (pte_efuse >> 10) & 0x7;
1507 if (pvs == 0x7)
1508 pvs = (pte_efuse >> 13) & 0x7;
1509
1510 switch (pvs) {
1511 case 0x0:
1512 case 0x7:
1513 pr_info("ACPU PVS: Slow\n");
1514 return PVS_SLOW;
1515 case 0x1:
1516 pr_info("ACPU PVS: Nominal\n");
1517 return PVS_NOM;
1518 case 0x3:
1519 pr_info("ACPU PVS: Fast\n");
1520 return PVS_FAST;
1521 case 0x4:
1522 if (cpu_is_apq8064()) {
1523 pr_info("ACPU PVS: Faster\n");
1524 return PVS_FASTER;
1525 }
1526 default:
1527 pr_warn("ACPU PVS: Unknown. Defaulting to slow\n");
1528 return PVS_SLOW;
1529 }
1530}
1531
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001532static struct acpu_level * __init select_freq_plan(void)
1533{
1534 struct acpu_level *l, *max_acpu_level = NULL;
1535
1536 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001537 if (cpu_is_msm8960()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001538 enum pvs pvs_id = get_pvs();
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001539
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001540 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001541 if (cpu_is_krait_v1()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001542 acpu_freq_tbl = acpu_freq_tbl_8960_v1[pvs_id];
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001543 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1544 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1545 } else {
Tianyi Goudff51062012-06-04 20:22:23 -07001546 acpu_freq_tbl = acpu_freq_tbl_8960_v2[pvs_id];
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001547 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1548 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1549 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001550 } else if (cpu_is_apq8064()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001551 enum pvs pvs_id = get_pvs();
1552
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001553 scalable = scalable_8064;
Tianyi Goudff51062012-06-04 20:22:23 -07001554 acpu_freq_tbl = acpu_freq_tbl_8064[pvs_id];
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001555 l2_freq_tbl = l2_freq_tbl_8064;
1556 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001557 } else if (cpu_is_msm8627()) {
1558 scalable = scalable_8627;
1559 acpu_freq_tbl = acpu_freq_tbl_8627;
1560 l2_freq_tbl = l2_freq_tbl_8627;
1561 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001562 } else if (cpu_is_msm8930()) {
1563 scalable = scalable_8930;
1564 acpu_freq_tbl = acpu_freq_tbl_8930;
1565 l2_freq_tbl = l2_freq_tbl_8930;
1566 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001567 } else {
1568 BUG();
1569 }
Tianyi Goudff51062012-06-04 20:22:23 -07001570 BUG_ON(!acpu_freq_tbl);
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001571 if (krait_needs_vmin())
1572 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001573
1574 /* Find the max supported scaling frequency. */
1575 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1576 if (l->use_for_scaling)
1577 max_acpu_level = l;
1578 BUG_ON(!max_acpu_level);
1579 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1580
1581 return max_acpu_level;
1582}
1583
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001584static struct acpuclk_data acpuclk_8960_data = {
1585 .set_rate = acpuclk_8960_set_rate,
1586 .get_rate = acpuclk_8960_get_rate,
1587 .power_collapse_khz = STBY_KHZ,
1588 .wait_for_irq_khz = STBY_KHZ,
1589};
1590
Matt Wagantallec57f062011-08-16 23:54:46 -07001591static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001592{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001593 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001594
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001595 regulator_init(max_acpu_level);
Stephen Boydcfe192b2011-12-09 21:47:14 -08001596 bus_init(max_acpu_level->l2_level->bw_level);
1597
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001598 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1599 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001600
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001601 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001602
1603 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001604 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001605
1606 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001607}
Matt Wagantallec57f062011-08-16 23:54:46 -07001608
1609struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1610 .init = acpuclk_8960_init,
1611};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001612
1613struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1614 .init = acpuclk_8960_init,
1615};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001616
1617struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1618 .init = acpuclk_8960_init,
1619};