blob: afa98c194756bac416aeb5398fc8d3f7954dfc61 [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 },
Tianyi Gouc519b722012-06-13 16:37:36 -0700663 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1200000 },
Tianyi Goudff51062012-06-04 20:22:23 -0700664 { 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 },
Tianyi Gouc519b722012-06-13 16:37:36 -0700690 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1150000 },
Tianyi Goudff51062012-06-04 20:22:23 -0700691 { 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. */
Tianyi Gou64307be2012-06-06 14:25:25 -0700718static struct acpu_level acpu_freq_tbl_8930_slow[] = {
719 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
720 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
721 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 975000 },
722 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 975000 },
723 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 1000000 },
Tianyi Goud911dd12012-05-10 21:06:40 -0700724 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 1000000 },
725 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1025000 },
Tianyi Gou64307be2012-06-06 14:25:25 -0700726 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1025000 },
727 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1075000 },
728 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1075000 },
Tianyi Goud911dd12012-05-10 21:06:40 -0700729 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1100000 },
Tianyi Gou64307be2012-06-06 14:25:25 -0700730 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1100000 },
731 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(11), 1125000 },
732 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(11), 1125000 },
733 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
734 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
735 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
736 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
737 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
738 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
739 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800740 { 0, { 0 } }
741};
742
Tianyi Gou64307be2012-06-06 14:25:25 -0700743static struct acpu_level acpu_freq_tbl_8930_nom[] = {
744 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 925000 },
745 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 925000 },
746 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 950000 },
747 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 950000 },
748 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 975000 },
749 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 975000 },
750 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 1000000 },
751 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
752 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1050000 },
753 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1050000 },
754 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1075000 },
755 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1075000 },
756 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(11), 1100000 },
757 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(11), 1100000 },
758 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1150000 },
759 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1150000 },
760 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1175000 },
761 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1175000 },
762 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1200000 },
763 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1200000 },
764 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1212500 },
765 { 0, { 0 } }
766};
767
768static struct acpu_level acpu_freq_tbl_8930_fast[] = {
769 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
770 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
771 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 900000 },
772 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 900000 },
773 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 925000 },
774 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
775 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 950000 },
776 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 950000 },
777 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1000000 },
778 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1000000 },
779 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
780 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
781 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(11), 1050000 },
782 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(11), 1050000 },
783 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
784 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
785 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
786 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1125000 },
787 { 1, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1150000 },
788 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1150000 },
789 { 1, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1162500 },
790 { 0, { 0 } }
791};
Tianyi Goue0b34de2011-12-20 11:20:10 -0800792/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
793#undef L2
794#define L2(x) (&l2_freq_tbl_8627[(x)])
795static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800796 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
797 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
798 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
799 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
800 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
801 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
802 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
803 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
804 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
805 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
806 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
807 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
808 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800809};
810
811/* TODO: Update core voltages when data is available. */
812static struct acpu_level acpu_freq_tbl_8627[] = {
813 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
814 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
815 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
816 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
817 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
818 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
819 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
820 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
821 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
822 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
823 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
824 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
825 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
826 { 0, { 0 } }
827};
828
Tianyi Goudff51062012-06-04 20:22:23 -0700829static struct acpu_level *acpu_freq_tbl_8960_v1[NUM_PVS] __initdata = {
830 [PVS_SLOW] = acpu_freq_tbl_8960_kraitv1_slow,
831 [PVS_NOM] = acpu_freq_tbl_8960_kraitv1_nom_fast,
832 [PVS_FAST] = acpu_freq_tbl_8960_kraitv1_nom_fast,
833};
834
835static struct acpu_level *acpu_freq_tbl_8960_v2[NUM_PVS] __initdata = {
836 [PVS_SLOW] = acpu_freq_tbl_8960_kraitv2_slow,
837 [PVS_NOM] = acpu_freq_tbl_8960_kraitv2_nom,
838 [PVS_FAST] = acpu_freq_tbl_8960_kraitv2_fast,
839};
840
841/* TODO: update the faster table when data is available */
842static struct acpu_level *acpu_freq_tbl_8064[NUM_PVS] __initdata = {
843 [PVS_SLOW] = acpu_freq_tbl_8064_slow,
844 [PVS_NOM] = acpu_freq_tbl_8064_nom,
845 [PVS_FAST] = acpu_freq_tbl_8064_fast,
846 [PVS_FASTER] = acpu_freq_tbl_8064_fast,
847};
848
Tianyi Gou64307be2012-06-06 14:25:25 -0700849static struct acpu_level *acpu_freq_tbl_8930_pvs[NUM_PVS] __initdata = {
850 [PVS_SLOW] = acpu_freq_tbl_8930_slow,
851 [PVS_NOM] = acpu_freq_tbl_8930_nom,
852 [PVS_FAST] = acpu_freq_tbl_8930_fast,
853};
854
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700855static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700856{
857 return scalable[cpu].current_speed->khz;
858}
859
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860/* Get the selected source on primary MUX. */
861static int get_pri_clk_src(struct scalable *sc)
862{
863 uint32_t regval;
864
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700865 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866 return regval & 0x3;
867}
868
869/* Set the selected source on primary MUX. */
870static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
871{
872 uint32_t regval;
873
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700874 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875 regval &= ~0x3;
876 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700877 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 /* Wait for switch to complete. */
879 mb();
880 udelay(1);
881}
882
883/* Get the selected source on secondary MUX. */
884static int get_sec_clk_src(struct scalable *sc)
885{
886 uint32_t regval;
887
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700888 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889 return (regval >> 2) & 0x3;
890}
891
892/* Set the selected source on secondary MUX. */
893static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
894{
895 uint32_t regval;
896
897 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700898 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700899 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700900 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700901
902 /* Program the MUX. */
903 regval &= ~(0x3 << 2);
904 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700905 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906
907 /* Wait for switch to complete. */
908 mb();
909 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700910
911 /* Re-enable secondary source clock gating. */
912 regval &= ~SECCLKAGD;
913 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700914}
915
916/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800917static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700918{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700919 int rc;
920
Matt Wagantallc1021762012-01-31 20:02:02 -0800921 if (!skip_regulators) {
922 if (cpu_is_msm8960()) {
923 rc = rpm_vreg_set_voltage(
924 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
925 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
David Collins9a81d6c2012-03-29 15:11:33 -0700926 2050000,
Matt Wagantallc1021762012-01-31 20:02:02 -0800927 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
928 if (rc)
929 pr_err("%s regulator enable failed (%d)\n",
930 sc->vreg[VREG_HFPLL_A].name, rc);
931 }
932 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
933 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
934 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800935 if (rc)
936 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800937 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800938 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700939 /* Disable PLL bypass mode. */
940 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
941
942 /*
943 * H/W requires a 5us delay between disabling the bypass and
944 * de-asserting the reset. Delay 10us just to be safe.
945 */
946 mb();
947 udelay(10);
948
949 /* De-assert active-low PLL reset. */
950 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
951
952 /* Wait for PLL to lock. */
953 mb();
954 udelay(60);
955
956 /* Enable PLL output. */
957 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
958}
959
960/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800961static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700962{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700963 int rc;
964
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700965 /*
966 * Disable the PLL output, disable test mode, enable
967 * the bypass mode, and assert the reset.
968 */
969 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700970
Matt Wagantallc1021762012-01-31 20:02:02 -0800971 if (!skip_regulators) {
972 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
973 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800974 0, 0);
975 if (rc)
976 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800977 sc->vreg[VREG_HFPLL_B].name, rc);
978
979 if (cpu_is_msm8960()) {
980 rc = rpm_vreg_set_voltage(
981 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
982 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
983 0, 0, 0);
984 if (rc)
985 pr_err("%s regulator enable failed (%d)\n",
986 sc->vreg[VREG_HFPLL_A].name, rc);
987 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800988 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700989}
990
991/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
992static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
993{
994 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
995}
996
997/* Return the L2 speed that should be applied. */
998static struct l2_level *compute_l2_level(struct scalable *sc,
999 struct l2_level *vote_l)
1000{
1001 struct l2_level *new_l;
1002 int cpu;
1003
1004 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -07001005 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001006
1007 /* Find max L2 speed vote. */
1008 sc->l2_vote = vote_l;
1009 new_l = l2_freq_tbl;
1010 for_each_present_cpu(cpu)
1011 new_l = max(new_l, scalable[cpu].l2_vote);
1012
1013 return new_l;
1014}
1015
1016/* Update the bus bandwidth request. */
1017static void set_bus_bw(unsigned int bw)
1018{
1019 int ret;
1020
1021 /* Bounds check. */
1022 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
1023 pr_err("invalid bandwidth request (%d)\n", bw);
1024 return;
1025 }
1026
1027 /* Update bandwidth if request has changed. This may sleep. */
1028 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
1029 if (ret)
1030 pr_err("bandwidth request failed (%d)\n", ret);
1031}
1032
1033/* Set the CPU or L2 clock speed. */
1034static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
1035 enum setrate_reason reason)
1036{
1037 struct core_speed *strt_s = sc->current_speed;
1038
1039 if (tgt_s == strt_s)
1040 return;
1041
1042 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001043 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001044 * Move to an always-on source running at a frequency that does
1045 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001046 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001047 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001048 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
1049
1050 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -08001051 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001052 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001053 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001054
1055 /* Move CPU to HFPLL source. */
1056 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1057 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001058 /*
Matt Wagantall34c2d962012-02-01 14:30:02 -08001059 * If responding to CPU_DEAD we must be running on another CPU.
1060 * Therefore, we can't access the downed CPU's clock MUX CP15
1061 * registers from here and can't change clock sources. If the
1062 * CPU is collapsed, however, it is still safe to turn off the
1063 * PLL without switching the MUX away from it.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001064 */
1065 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
1066 set_sec_clk_src(sc, tgt_s->sec_src_sel);
1067 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -08001068 hfpll_disable(sc, 0);
1069 } else if (reason == SETRATE_HOTPLUG
1070 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
1071 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001072 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001073 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001074 /*
1075 * If responding to CPU_UP_PREPARE, we can't change CP15
1076 * registers for the CPU that's coming up since we're not
1077 * running on that CPU. That's okay though, since the MUX
1078 * source was not changed on the way down, either.
1079 */
Matt Wagantall34c2d962012-02-01 14:30:02 -08001080 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
1081 hfpll_set_rate(sc, tgt_s);
1082 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001083 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Matt Wagantall34c2d962012-02-01 14:30:02 -08001084 } else if (reason == SETRATE_HOTPLUG
1085 && msm_pm_verify_cpu_pc(SCALABLE_TO_CPU(sc))) {
1086 /* PLL was disabled during hot-unplug. Re-enable it. */
1087 hfpll_set_rate(sc, tgt_s);
1088 hfpll_enable(sc, 0);
1089 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001090 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001091 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
1092 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001093 }
1094
1095 sc->current_speed = tgt_s;
1096}
1097
1098/* Apply any per-cpu voltage increases. */
1099static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1100 unsigned int vdd_dig, enum setrate_reason reason)
1101{
1102 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -07001103 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001104
1105 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001106 * Increase vdd_mem active-set before vdd_dig.
1107 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001108 */
1109 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
1110 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1111 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1112 sc->vreg[VREG_MEM].max_vdd, 0);
1113 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001114 pr_err("%s increase failed (%d)\n",
1115 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001116 return rc;
1117 }
1118 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1119 }
1120
1121 /* Increase vdd_dig active-set vote. */
1122 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
1123 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1124 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1125 sc->vreg[VREG_DIG].max_vdd, 0);
1126 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001127 pr_err("%s increase failed (%d)\n",
1128 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001129 return rc;
1130 }
1131 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1132 }
1133
1134 /*
1135 * Update per-CPU core voltage. Don't do this for the hotplug path for
1136 * which it should already be correct. Attempting to set it is bad
1137 * because we don't know what CPU we are running on at this point, but
1138 * the CPU regulator API requires we call it from the affected CPU.
1139 */
1140 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
1141 && reason != SETRATE_HOTPLUG) {
1142 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1143 sc->vreg[VREG_CORE].max_vdd);
1144 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001145 pr_err("%s increase failed (%d)\n",
1146 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001147 return rc;
1148 }
1149 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1150 }
1151
1152 return rc;
1153}
1154
1155/* Apply any per-cpu voltage decreases. */
1156static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1157 unsigned int vdd_dig, enum setrate_reason reason)
1158{
1159 struct scalable *sc = &scalable[cpu];
1160 int ret;
1161
1162 /*
1163 * Update per-CPU core voltage. This must be called on the CPU
1164 * that's being affected. Don't do this in the hotplug remove path,
1165 * where the rail is off and we're executing on the other CPU.
1166 */
1167 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1168 && reason != SETRATE_HOTPLUG) {
1169 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1170 sc->vreg[VREG_CORE].max_vdd);
1171 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001172 pr_err("%s decrease failed (%d)\n",
1173 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001174 return;
1175 }
1176 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1177 }
1178
1179 /* Decrease vdd_dig active-set vote. */
1180 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1181 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1182 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1183 sc->vreg[VREG_DIG].max_vdd, 0);
1184 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001185 pr_err("%s decrease failed (%d)\n",
1186 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001187 return;
1188 }
1189 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1190 }
1191
1192 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001193 * Decrease vdd_mem active-set after vdd_dig.
1194 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195 */
1196 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1197 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1198 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1199 sc->vreg[VREG_MEM].max_vdd, 0);
1200 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001201 pr_err("%s decrease failed (%d)\n",
1202 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001203 return;
1204 }
1205 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1206 }
1207}
1208
1209static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1210{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001211 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001212}
1213
1214static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1215{
1216 unsigned int pll_vdd_dig;
1217
Stephen Boydc76158f2011-12-08 12:42:40 -08001218 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001219 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001220 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001221 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1222 else
1223 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1224
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1226}
1227
Tianyi Gouaded6432012-02-22 14:53:05 -08001228static unsigned int calculate_vdd_core(struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001229{
Tianyi Gouaded6432012-02-22 14:53:05 -08001230 return tgt->vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001231}
1232
1233/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001234static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1235 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001236{
1237 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1238 struct l2_level *tgt_l2_l;
1239 struct acpu_level *tgt;
1240 unsigned int vdd_mem, vdd_dig, vdd_core;
1241 unsigned long flags;
1242 int rc = 0;
1243
1244 if (cpu > num_possible_cpus()) {
1245 rc = -EINVAL;
1246 goto out;
1247 }
1248
1249 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1250 mutex_lock(&driver_lock);
1251
1252 strt_acpu_s = scalable[cpu].current_speed;
1253
1254 /* Return early if rate didn't change. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001255 if (rate == strt_acpu_s->khz)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001256 goto out;
1257
1258 /* Find target frequency. */
1259 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1260 if (tgt->speed.khz == rate) {
1261 tgt_acpu_s = &tgt->speed;
1262 break;
1263 }
1264 }
1265 if (tgt->speed.khz == 0) {
1266 rc = -EINVAL;
1267 goto out;
1268 }
1269
1270 /* Calculate voltage requirements for the current CPU. */
1271 vdd_mem = calculate_vdd_mem(tgt);
1272 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gouaded6432012-02-22 14:53:05 -08001273 vdd_core = calculate_vdd_core(tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001274
1275 /* Increase VDD levels if needed. */
1276 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1277 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1278 if (rc)
1279 goto out;
1280 }
1281
1282 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1283 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1284
1285 /* Set the CPU speed. */
1286 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1287
1288 /*
1289 * Update the L2 vote and apply the rate change. A spinlock is
1290 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001291 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001292 * and the driver_lock mutex is not acquired.
1293 */
1294 spin_lock_irqsave(&l2_lock, flags);
1295 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1296 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1297 spin_unlock_irqrestore(&l2_lock, flags);
1298
1299 /* Nothing else to do for power collapse or SWFI. */
1300 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1301 goto out;
1302
1303 /* Update bus bandwith request. */
1304 set_bus_bw(tgt_l2_l->bw_level);
1305
1306 /* Drop VDD levels if we can. */
1307 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1308
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001309 pr_debug("ACPU%d speed change complete\n", cpu);
1310
1311out:
1312 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1313 mutex_unlock(&driver_lock);
1314 return rc;
1315}
1316
1317/* Initialize a HFPLL at a given rate and enable it. */
1318static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1319{
1320 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1321
1322 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001323 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001324
1325 /* Configure PLL parameters for integer mode. */
1326 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1327 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1328 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1329
1330 /* Program droop controller. */
1331 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1332
1333 /* Set an initial rate and enable the PLL. */
1334 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001335 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001336}
1337
1338/* Voltage regulator initialization. */
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001339static void __init regulator_init(struct acpu_level *lvl)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001340{
1341 int cpu, ret;
1342 struct scalable *sc;
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001343 unsigned int vdd_mem, vdd_dig, vdd_core;
1344
1345 vdd_mem = calculate_vdd_mem(lvl);
1346 vdd_dig = calculate_vdd_dig(lvl);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001347
1348 for_each_possible_cpu(cpu) {
1349 sc = &scalable[cpu];
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001350
1351 /* Set initial vdd_mem vote. */
1352 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1353 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1354 sc->vreg[VREG_MEM].max_vdd, 0);
1355 if (ret) {
1356 pr_err("%s initialization failed (%d)\n",
1357 sc->vreg[VREG_MEM].name, ret);
1358 BUG();
1359 }
1360 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1361
1362 /* Set initial vdd_dig vote. */
1363 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1364 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1365 sc->vreg[VREG_DIG].max_vdd, 0);
1366 if (ret) {
1367 pr_err("%s initialization failed (%d)\n",
1368 sc->vreg[VREG_DIG].name, ret);
1369 BUG();
1370 }
1371 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1372
1373 /* Setup Krait CPU regulators and initial core voltage. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001374 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1375 sc->vreg[VREG_CORE].name);
1376 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1377 pr_err("regulator_get(%s) failed (%ld)\n",
1378 sc->vreg[VREG_CORE].name,
1379 PTR_ERR(sc->vreg[VREG_CORE].reg));
1380 BUG();
1381 }
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001382 vdd_core = calculate_vdd_core(lvl);
1383 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001384 sc->vreg[VREG_CORE].max_vdd);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001385 if (ret) {
1386 pr_err("%s initialization failed (%d)\n",
1387 sc->vreg[VREG_CORE].name, ret);
1388 BUG();
1389 }
1390 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001391 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001392 if (ret) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001393 pr_err("regulator_enable(%s) failed (%d)\n",
1394 sc->vreg[VREG_CORE].name, ret);
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001395 BUG();
1396 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001397 }
1398}
1399
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001400/* Set initial rate for a given core. */
1401static void __init init_clock_sources(struct scalable *sc,
1402 struct core_speed *tgt_s)
1403{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001404 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001405
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001406 /* Select PLL8 as AUX source input to the secondary MUX. */
1407 writel_relaxed(0x3, sc->aux_clk_sel);
1408
1409 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001410 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001411 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001412 hfpll_init(sc, tgt_s);
1413
1414 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001415 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001416 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001417 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001418
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001419 /* Switch to the target clock source. */
1420 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001421 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1422 sc->current_speed = tgt_s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001423}
1424
Matt Wagantall8e726c72011-08-06 00:49:28 -07001425static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001426{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001427 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001428 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001429
1430 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1431 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001432}
1433
1434/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001435static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001436{
1437 int ret;
1438
1439 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1440 if (!bus_perf_client) {
1441 pr_err("unable to register bus client\n");
1442 BUG();
1443 }
1444
Stephen Boydcfe192b2011-12-09 21:47:14 -08001445 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001446 if (ret)
1447 pr_err("initial bandwidth request failed (%d)\n", ret);
1448}
1449
1450#ifdef CONFIG_CPU_FREQ_MSM
1451static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1452
1453static void __init cpufreq_table_init(void)
1454{
1455 int cpu;
1456
1457 for_each_possible_cpu(cpu) {
1458 int i, freq_cnt = 0;
1459 /* Construct the freq_table tables from acpu_freq_tbl. */
1460 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1461 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1462 if (acpu_freq_tbl[i].use_for_scaling) {
1463 freq_table[cpu][freq_cnt].index = freq_cnt;
1464 freq_table[cpu][freq_cnt].frequency
1465 = acpu_freq_tbl[i].speed.khz;
1466 freq_cnt++;
1467 }
1468 }
1469 /* freq_table not big enough to store all usable freqs. */
1470 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1471
1472 freq_table[cpu][freq_cnt].index = freq_cnt;
1473 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1474
1475 pr_info("CPU%d: %d scaling frequencies supported.\n",
1476 cpu, freq_cnt);
1477
1478 /* Register table with CPUFreq. */
1479 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1480 }
1481}
1482#else
1483static void __init cpufreq_table_init(void) {}
1484#endif
1485
1486#define HOT_UNPLUG_KHZ STBY_KHZ
1487static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1488 unsigned long action, void *hcpu)
1489{
1490 static int prev_khz[NR_CPUS];
1491 static int prev_pri_src[NR_CPUS];
1492 static int prev_sec_src[NR_CPUS];
1493 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001494
1495 switch (action) {
1496 case CPU_DYING:
1497 case CPU_DYING_FROZEN:
1498 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001499 * On Krait v1 and 8064v1, the primary and secondary muxes must
1500 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001501 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001502 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001503 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1504 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1505 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1506 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1507 }
1508 break;
1509 case CPU_DEAD:
1510 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001511 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001512 /* Fall through. */
1513 case CPU_UP_CANCELED:
1514 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001515 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001516 break;
1517 case CPU_UP_PREPARE:
1518 case CPU_UP_PREPARE_FROZEN:
1519 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001520 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001521 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001522 break;
1523 case CPU_STARTING:
1524 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001525 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001526 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1527 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1528 }
1529 break;
1530 default:
1531 break;
1532 }
1533
1534 return NOTIFY_OK;
1535}
1536
1537static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1538 .notifier_call = acpuclock_cpu_callback,
1539};
1540
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001541static const int krait_needs_vmin(void)
1542{
1543 switch (read_cpuid_id()) {
1544 case 0x511F04D0:
1545 case 0x511F04D1:
1546 case 0x510F06F0:
1547 return 1;
1548 default:
1549 return 0;
1550 };
1551}
1552
Stephen Boydaefb8de2012-01-05 19:05:01 -08001553static void kraitv2_apply_vmin(struct acpu_level *tbl)
1554{
1555 for (; tbl->speed.khz != 0; tbl++)
1556 if (tbl->vdd_core < 1150000)
1557 tbl->vdd_core = 1150000;
1558}
1559
Tianyi Goudff51062012-06-04 20:22:23 -07001560static enum pvs __init get_pvs(void)
1561{
1562 uint32_t pte_efuse, pvs;
1563
1564 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1565 pvs = (pte_efuse >> 10) & 0x7;
1566 if (pvs == 0x7)
1567 pvs = (pte_efuse >> 13) & 0x7;
1568
1569 switch (pvs) {
1570 case 0x0:
1571 case 0x7:
1572 pr_info("ACPU PVS: Slow\n");
1573 return PVS_SLOW;
1574 case 0x1:
1575 pr_info("ACPU PVS: Nominal\n");
1576 return PVS_NOM;
1577 case 0x3:
1578 pr_info("ACPU PVS: Fast\n");
1579 return PVS_FAST;
1580 case 0x4:
1581 if (cpu_is_apq8064()) {
1582 pr_info("ACPU PVS: Faster\n");
1583 return PVS_FASTER;
1584 }
1585 default:
1586 pr_warn("ACPU PVS: Unknown. Defaulting to slow\n");
1587 return PVS_SLOW;
1588 }
1589}
1590
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001591static struct acpu_level * __init select_freq_plan(void)
1592{
1593 struct acpu_level *l, *max_acpu_level = NULL;
1594
1595 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001596 if (cpu_is_msm8960()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001597 enum pvs pvs_id = get_pvs();
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001598
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001599 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001600 if (cpu_is_krait_v1()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001601 acpu_freq_tbl = acpu_freq_tbl_8960_v1[pvs_id];
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001602 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1603 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1604 } else {
Tianyi Goudff51062012-06-04 20:22:23 -07001605 acpu_freq_tbl = acpu_freq_tbl_8960_v2[pvs_id];
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001606 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1607 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1608 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001609 } else if (cpu_is_apq8064()) {
Tianyi Goudff51062012-06-04 20:22:23 -07001610 enum pvs pvs_id = get_pvs();
1611
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001612 scalable = scalable_8064;
Tianyi Goudff51062012-06-04 20:22:23 -07001613 acpu_freq_tbl = acpu_freq_tbl_8064[pvs_id];
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001614 l2_freq_tbl = l2_freq_tbl_8064;
1615 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001616 } else if (cpu_is_msm8627()) {
1617 scalable = scalable_8627;
1618 acpu_freq_tbl = acpu_freq_tbl_8627;
1619 l2_freq_tbl = l2_freq_tbl_8627;
1620 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001621 } else if (cpu_is_msm8930()) {
Tianyi Gou64307be2012-06-06 14:25:25 -07001622 enum pvs pvs_id = get_pvs();
1623
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001624 scalable = scalable_8930;
Tianyi Gou64307be2012-06-06 14:25:25 -07001625 acpu_freq_tbl = acpu_freq_tbl_8930_pvs[pvs_id];
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001626 l2_freq_tbl = l2_freq_tbl_8930;
1627 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001628 } else {
1629 BUG();
1630 }
Tianyi Goudff51062012-06-04 20:22:23 -07001631 BUG_ON(!acpu_freq_tbl);
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001632 if (krait_needs_vmin())
1633 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001634
1635 /* Find the max supported scaling frequency. */
1636 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1637 if (l->use_for_scaling)
1638 max_acpu_level = l;
1639 BUG_ON(!max_acpu_level);
1640 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1641
1642 return max_acpu_level;
1643}
1644
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001645static struct acpuclk_data acpuclk_8960_data = {
1646 .set_rate = acpuclk_8960_set_rate,
1647 .get_rate = acpuclk_8960_get_rate,
1648 .power_collapse_khz = STBY_KHZ,
1649 .wait_for_irq_khz = STBY_KHZ,
1650};
1651
Matt Wagantallec57f062011-08-16 23:54:46 -07001652static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001653{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001654 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001655
Matt Wagantall7afeb9e2012-03-22 22:08:07 -07001656 regulator_init(max_acpu_level);
Stephen Boydcfe192b2011-12-09 21:47:14 -08001657 bus_init(max_acpu_level->l2_level->bw_level);
1658
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001659 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1660 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001661
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001662 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001663
1664 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001665 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001666
1667 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001668}
Matt Wagantallec57f062011-08-16 23:54:46 -07001669
1670struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1671 .init = acpuclk_8960_init,
1672};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001673
1674struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1675 .init = acpuclk_8960_init,
1676};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001677
1678struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1679 .init = acpuclk_8960_init,
1680};