blob: ee0b73bfe1849258c3f66cf04defb7ed2a1da501 [file] [log] [blame]
Stephen Boydaefb8de2012-01-05 19:05:01 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#define pr_fmt(fmt) "%s: " fmt, __func__
14
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/io.h>
18#include <linux/delay.h>
19#include <linux/mutex.h>
20#include <linux/err.h>
21#include <linux/errno.h>
22#include <linux/cpufreq.h>
23#include <linux/cpu.h>
24#include <linux/regulator/consumer.h>
25
26#include <asm/mach-types.h>
27#include <asm/cpu.h>
28
29#include <mach/board.h>
30#include <mach/msm_iomap.h>
31#include <mach/rpm-regulator.h>
32#include <mach/msm_bus.h>
33#include <mach/msm_bus_board.h>
34#include <mach/socinfo.h>
Stephen Boyd469ed3e2011-09-29 16:41:19 -070035#include <mach/msm-krait-l2-accessors.h>
Matt Wagantallcb12c392011-10-19 10:32:07 -070036#include <mach/rpm-regulator.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070037
38#include "acpuclock.h"
39
40/*
41 * Source IDs.
42 * These must be negative to not overlap with the source IDs
43 * used by the 8x60 local clock driver.
44 */
45#define PLL_8 0
46#define HFPLL -1
47#define QSB -2
48
49/* Mux source selects. */
50#define PRI_SRC_SEL_SEC_SRC 0
51#define PRI_SRC_SEL_HFPLL 1
52#define PRI_SRC_SEL_HFPLL_DIV2 2
53#define SEC_SRC_SEL_QSB 0
Matt Wagantall65e5e4b2011-10-27 16:52:10 -070054#define SEC_SRC_SEL_AUX 2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055
56/* HFPLL registers offsets. */
57#define HFPLL_MODE 0x00
58#define HFPLL_CONFIG_CTL 0x04
59#define HFPLL_L_VAL 0x08
60#define HFPLL_M_VAL 0x0C
61#define HFPLL_N_VAL 0x10
62#define HFPLL_DROOP_CTL 0x14
63
64/* CP15 L2 indirect addresses. */
65#define L2CPMR_IADDR 0x500
66#define L2CPUCPMR_IADDR 0x501
67
68#define STBY_KHZ 1
69
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070#define HFPLL_LOW_VDD_PLL_L_MAX 0x28
71
72#define SECCLKAGD BIT(4)
73
Matt Wagantalla518f8f2011-10-17 13:24:53 -070074/* PTE EFUSE register. */
75#define QFPROM_PTE_EFUSE_ADDR (MSM_QFPROM_BASE + 0x00C0)
76
Tianyi Gou50705682012-02-21 17:51:50 -080077/* Corner type vreg VDD values */
78#define LVL_NONE RPM_VREG_CORNER_NONE
79#define LVL_LOW RPM_VREG_CORNER_LOW
80#define LVL_NOM RPM_VREG_CORNER_NOMINAL
81#define LVL_HIGH RPM_VREG_CORNER_HIGH
82
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070083enum scalables {
84 CPU0 = 0,
85 CPU1,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -070086 CPU2,
87 CPU3,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088 L2,
89 NUM_SCALABLES
90};
91
92enum vregs {
93 VREG_CORE,
94 VREG_MEM,
95 VREG_DIG,
Matt Wagantallcb12c392011-10-19 10:32:07 -070096 VREG_HFPLL_A,
97 VREG_HFPLL_B,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098 NUM_VREG
99};
100
Tianyi Gou50705682012-02-21 17:51:50 -0800101enum hfpll_vdd_levels {
102 HFPLL_VDD_NONE,
103 HFPLL_VDD_LOW,
104 HFPLL_VDD_NOM
105};
106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107struct vreg {
108 const char name[15];
109 const unsigned int max_vdd;
110 const int rpm_vreg_voter;
111 const int rpm_vreg_id;
112 struct regulator *reg;
113 unsigned int cur_vdd;
114};
115
116struct core_speed {
117 unsigned int khz;
118 int src;
119 unsigned int pri_src_sel;
120 unsigned int sec_src_sel;
121 unsigned int pll_l_val;
122};
123
124struct l2_level {
125 struct core_speed speed;
126 unsigned int vdd_dig;
127 unsigned int vdd_mem;
128 unsigned int bw_level;
129};
130
131struct acpu_level {
132 unsigned int use_for_scaling;
133 struct core_speed speed;
134 struct l2_level *l2_level;
135 unsigned int vdd_core;
136};
137
138struct scalable {
139 void * __iomem const hfpll_base;
140 void * __iomem const aux_clk_sel;
141 const uint32_t l2cpmr_iaddr;
142 struct core_speed *current_speed;
143 struct l2_level *l2_vote;
144 struct vreg vreg[NUM_VREG];
145 bool first_set_call;
Tianyi Gou50705682012-02-21 17:51:50 -0800146 unsigned int *hfpll_vdd_tbl;
147};
148
149static unsigned int hfpll_vdd_tbl_8960[] = {
150 [HFPLL_VDD_NONE] = 0,
151 [HFPLL_VDD_LOW] = 850000,
152 [HFPLL_VDD_NOM] = 1050000
153};
154
155static unsigned int hfpll_vdd_tbl_8064[] = {
156 [HFPLL_VDD_NONE] = 0,
157 [HFPLL_VDD_LOW] = 945000,
158 [HFPLL_VDD_NOM] = 1050000
159};
160
161static unsigned int hfpll_vdd_dig_tbl_8930[] = {
162 [HFPLL_VDD_NONE] = LVL_NONE,
163 [HFPLL_VDD_LOW] = LVL_LOW,
164 [HFPLL_VDD_NOM] = LVL_NOM
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165};
166
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700167static struct scalable scalable_8960[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168 [CPU0] = {
169 .hfpll_base = MSM_HFPLL_BASE + 0x200,
Tianyi Gou50705682012-02-21 17:51:50 -0800170 .hfpll_vdd_tbl = hfpll_vdd_tbl_8960,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
172 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800173 .vreg[VREG_CORE] = { "krait0", 1300000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
175 RPM_VREG_VOTER1,
176 RPM_VREG_ID_PM8921_L24 },
177 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
178 RPM_VREG_VOTER1,
179 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800180 .vreg[VREG_HFPLL_A] = { "hfpll0_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700181 RPM_VREG_VOTER1,
182 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800183 .vreg[VREG_HFPLL_B] = { "hfpll0_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700184 RPM_VREG_VOTER1,
185 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186 },
187 [CPU1] = {
188 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800189 .hfpll_vdd_tbl = hfpll_vdd_tbl_8960,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
191 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800192 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800193 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194 RPM_VREG_VOTER2,
195 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800196 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197 RPM_VREG_VOTER2,
198 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800199 .vreg[VREG_HFPLL_A] = { "hfpll1_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700200 RPM_VREG_VOTER2,
201 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800202 .vreg[VREG_HFPLL_B] = { "hfpll1_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700203 RPM_VREG_VOTER2,
204 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205 },
206 [L2] = {
207 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800208 .hfpll_vdd_tbl = hfpll_vdd_tbl_8960,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700209 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
210 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800211 .vreg[VREG_HFPLL_A] = { "hfpll_l2_s8", 2100000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700212 RPM_VREG_VOTER6,
213 RPM_VREG_ID_PM8921_S8 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800214 .vreg[VREG_HFPLL_B] = { "hfpll_l2_l23", 1800000,
Matt Wagantallcb12c392011-10-19 10:32:07 -0700215 RPM_VREG_VOTER6,
216 RPM_VREG_ID_PM8921_L23 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217 },
218};
219
Stephen Boyd7ad84752011-08-05 14:04:28 -0700220static DEFINE_MUTEX(driver_lock);
221static DEFINE_SPINLOCK(l2_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700222
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700223static struct scalable scalable_8064[] = {
224 [CPU0] = {
225 .hfpll_base = MSM_HFPLL_BASE + 0x200,
Tianyi Gou50705682012-02-21 17:51:50 -0800226 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700227 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
228 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800229 .vreg[VREG_CORE] = { "krait0", 1300000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700230 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
231 RPM_VREG_VOTER1,
232 RPM_VREG_ID_PM8921_L24 },
233 .vreg[VREG_DIG] = { "krait0_dig", 1150000,
234 RPM_VREG_VOTER1,
235 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800236 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800237 RPM_VREG_VOTER1,
238 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700239 },
240 [CPU1] = {
241 .hfpll_base = MSM_HFPLL_BASE + 0x240,
Tianyi Gou50705682012-02-21 17:51:50 -0800242 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700243 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
244 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800245 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800246 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700247 RPM_VREG_VOTER2,
248 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800249 .vreg[VREG_DIG] = { "krait1_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700250 RPM_VREG_VOTER2,
251 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800252 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800253 RPM_VREG_VOTER2,
254 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700255 },
256 [CPU2] = {
257 .hfpll_base = MSM_HFPLL_BASE + 0x280,
Tianyi Gou50705682012-02-21 17:51:50 -0800258 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700259 .aux_clk_sel = MSM_ACC2_BASE + 0x014,
260 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800261 .vreg[VREG_CORE] = { "krait2", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800262 .vreg[VREG_MEM] = { "krait2_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700263 RPM_VREG_VOTER4,
264 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800265 .vreg[VREG_DIG] = { "krait2_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700266 RPM_VREG_VOTER4,
267 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800268 .vreg[VREG_HFPLL_B] = { "hfpll2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800269 RPM_VREG_VOTER4,
270 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700271 },
272 [CPU3] = {
273 .hfpll_base = MSM_HFPLL_BASE + 0x2C0,
Tianyi Gou50705682012-02-21 17:51:50 -0800274 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700275 .aux_clk_sel = MSM_ACC3_BASE + 0x014,
276 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
Tianyi Goud750d742012-03-02 14:38:58 -0800277 .vreg[VREG_CORE] = { "krait3", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800278 .vreg[VREG_MEM] = { "krait3_mem", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700279 RPM_VREG_VOTER5,
280 RPM_VREG_ID_PM8921_L24 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800281 .vreg[VREG_DIG] = { "krait3_dig", 1150000,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700282 RPM_VREG_VOTER5,
283 RPM_VREG_ID_PM8921_S3 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800284 .vreg[VREG_HFPLL_B] = { "hfpll3", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800285 RPM_VREG_VOTER5,
286 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700287 },
288 [L2] = {
289 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800290 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700291 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
292 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800293 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800294 RPM_VREG_VOTER6,
295 RPM_VREG_ID_PM8921_LVS7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700296 },
297};
298
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800299static struct scalable scalable_8930[] = {
300 [CPU0] = {
301 .hfpll_base = MSM_HFPLL_BASE + 0x200,
Tianyi Gou50705682012-02-21 17:51:50 -0800302 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800303 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
304 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
305 .vreg[VREG_CORE] = { "krait0", 1300000 },
306 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
307 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800308 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800309 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800310 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800311 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
312 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800313 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800314 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800315 RPM_VREG_ID_PM8038_L23 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800316 },
317 [CPU1] = {
318 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800319 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800320 .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,
Tianyi Gou50705682012-02-21 17:51:50 -0800349 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800350 .aux_clk_sel = MSM_ACC0_BASE + 0x014,
351 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
352 .vreg[VREG_CORE] = { "krait0", 1300000 },
353 .vreg[VREG_MEM] = { "krait0_mem", 1150000,
354 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800355 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800356 .vreg[VREG_DIG] = { "krait0_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800357 RPM_VREG_VOTER1,
Tianyi Gou50705682012-02-21 17:51:50 -0800358 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
359 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800360 .vreg[VREG_HFPLL_B] = { "hfpll0", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800361 RPM_VREG_VOTER1,
Tianyi Goufff00402012-01-23 14:36:20 -0800362 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800363 },
364 [CPU1] = {
365 .hfpll_base = MSM_HFPLL_BASE + 0x300,
Tianyi Gou50705682012-02-21 17:51:50 -0800366 .hfpll_vdd_tbl = hfpll_vdd_tbl_8064,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800367 .aux_clk_sel = MSM_ACC1_BASE + 0x014,
368 .l2cpmr_iaddr = L2CPUCPMR_IADDR,
369 .vreg[VREG_CORE] = { "krait1", 1300000 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800370 .vreg[VREG_MEM] = { "krait1_mem", 1150000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800371 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800372 RPM_VREG_ID_PM8038_L24 },
Tianyi Gou50705682012-02-21 17:51:50 -0800373 .vreg[VREG_DIG] = { "krait1_dig", LVL_HIGH,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800374 RPM_VREG_VOTER2,
Tianyi Gou50705682012-02-21 17:51:50 -0800375 RPM_VREG_ID_PM8038_VDD_DIG_CORNER
376 },
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800377 .vreg[VREG_HFPLL_B] = { "hfpll1", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800378 RPM_VREG_VOTER2,
Tianyi Goufff00402012-01-23 14:36:20 -0800379 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800380 },
381 [L2] = {
382 .hfpll_base = MSM_HFPLL_BASE + 0x400,
Tianyi Gou50705682012-02-21 17:51:50 -0800383 .hfpll_vdd_tbl = hfpll_vdd_dig_tbl_8930,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800384 .aux_clk_sel = MSM_APCS_GCC_BASE + 0x028,
385 .l2cpmr_iaddr = L2CPMR_IADDR,
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800386 .vreg[VREG_HFPLL_B] = { "hfpll_l2", 1800000,
Tianyi Goue0b34de2011-12-20 11:20:10 -0800387 RPM_VREG_VOTER6,
Tianyi Goufff00402012-01-23 14:36:20 -0800388 RPM_VREG_ID_PM8038_L23 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800389 },
390};
391
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700392static struct scalable *scalable;
393static struct l2_level *l2_freq_tbl;
394static struct acpu_level *acpu_freq_tbl;
395static int l2_freq_tbl_size;
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700396
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700397/* Instantaneous bandwidth requests in MB/s. */
398#define BW_MBPS(_bw) \
399 { \
400 .vectors = (struct msm_bus_vectors[]){ \
401 {\
402 .src = MSM_BUS_MASTER_AMPSS_M0, \
403 .dst = MSM_BUS_SLAVE_EBI_CH0, \
404 .ib = (_bw) * 1000000UL, \
405 .ab = (_bw) * 100000UL, \
406 }, \
407 { \
408 .src = MSM_BUS_MASTER_AMPSS_M1, \
409 .dst = MSM_BUS_SLAVE_EBI_CH0, \
410 .ib = (_bw) * 1000000UL, \
411 .ab = (_bw) * 100000UL, \
412 }, \
413 }, \
414 .num_paths = 2, \
415 }
416static struct msm_bus_paths bw_level_tbl[] = {
Stephen Boydf2770c32011-12-07 18:52:30 -0800417 [0] = BW_MBPS(640), /* At least 80 MHz on bus. */
418 [1] = BW_MBPS(1064), /* At least 133 MHz on bus. */
419 [2] = BW_MBPS(1600), /* At least 200 MHz on bus. */
420 [3] = BW_MBPS(2128), /* At least 266 MHz on bus. */
421 [4] = BW_MBPS(3200), /* At least 400 MHz on bus. */
422 [5] = BW_MBPS(3600), /* At least 450 MHz on bus. */
423 [6] = BW_MBPS(3936), /* At least 492 MHz on bus. */
Tianyi Goud750d742012-03-02 14:38:58 -0800424 [7] = BW_MBPS(4264), /* At least 533 MHz on bus. */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700425};
426
427static struct msm_bus_scale_pdata bus_client_pdata = {
428 .usecase = bw_level_tbl,
429 .num_usecases = ARRAY_SIZE(bw_level_tbl),
430 .active_only = 1,
431 .name = "acpuclock",
432};
433
434static uint32_t bus_perf_client;
435
436/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800437#define L2(x) (&l2_freq_tbl_8960_kraitv1[(x)])
438static struct l2_level l2_freq_tbl_8960_kraitv1[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700439 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700440 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700441 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 1 },
442 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 1 },
443 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 1 },
444 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
445 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 2 },
446 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 2 },
Matt Wagantalle64d56a2011-07-14 19:35:27 -0700447 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 2 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700448 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
449 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
450 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700451};
452
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800453static struct acpu_level acpu_freq_tbl_8960_kraitv1_slow[] = {
454 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
455 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
456 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
457 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
458 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
459 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
460 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
461 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
462 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
463 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
464 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
465 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
466 { 0, { 0 } }
467};
468
469static struct acpu_level acpu_freq_tbl_8960_kraitv1_nom_fast[] = {
470 { 0, {STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 862500 },
471 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 862500 },
472 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 862500 },
473 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 887500 },
474 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 900000 },
475 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 925000 },
476 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 925000 },
477 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 937500 },
478 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 962500 },
479 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1012500 },
480 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1025000 },
481 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1025000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700482 { 0, { 0 } }
483};
484
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800485#undef L2
486#define L2(x) (&l2_freq_tbl_8960_kraitv2[(x)])
487static struct l2_level l2_freq_tbl_8960_kraitv2[] = {
488 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
489 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800490 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
491 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
492 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800493 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Stephen Boydf2770c32011-12-07 18:52:30 -0800494 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
495 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
496 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
497 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
498 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
499 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 6 },
500 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 6 },
501 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 6 },
502 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 6 },
503 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 6 },
504 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 6 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800505 [17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 6 },
506 [18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 6 },
507 [19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 6 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800508};
509
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800510static struct acpu_level acpu_freq_tbl_8960_kraitv2_slow[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800511 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
512 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800513 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
514 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
515 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
516 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
517 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
518 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
519 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
520 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
521 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
522 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
523 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
524 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
525 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1175000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800526 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800527 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1200000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800528 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1200000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800529 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1225000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800530 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1225000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800531 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1237500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800532 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1237500 },
533 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1250000 },
Stephen Boyd5766f682011-12-27 19:21:08 -0800534 { 0, { 0 } }
535};
536
537static struct acpu_level acpu_freq_tbl_8960_kraitv2_nom[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800538 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
539 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800540 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 925000 },
541 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 925000 },
542 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 950000 },
543 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 950000 },
544 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 975000 },
545 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 975000 },
546 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1025000 },
547 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1025000 },
548 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1050000 },
549 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1050000 },
550 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1075000 },
551 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1075000 },
552 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1125000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800553 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800554 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1150000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800555 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1150000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800556 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1175000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800557 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1175000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800558 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1187500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800559 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1187500 },
560 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1200000 },
Stephen Boyd9d0fab12011-12-08 10:56:06 -0800561 { 0, { 0 } }
562};
563
Stephen Boyd5766f682011-12-27 19:21:08 -0800564static struct acpu_level acpu_freq_tbl_8960_kraitv2_fast[] = {
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800565 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 850000 },
566 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 850000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800567 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 875000 },
568 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 875000 },
569 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 900000 },
570 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 900000 },
571 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 925000 },
572 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 925000 },
573 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 975000 },
574 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 975000 },
575 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1000000 },
576 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1000000 },
577 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1025000 },
578 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1025000 },
579 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1075000 },
Stephen Boyd327ac3c2012-01-11 23:09:18 -0800580 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1075000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800581 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1100000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800582 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(16), 1100000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800583 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(16), 1125000 },
Stephen Boyd14466452012-02-04 12:00:00 -0800584 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(16), 1125000 },
Stephen Boyd3b61e702012-01-26 16:47:37 -0800585 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(16), 1137500 },
Stephen Boyd14466452012-02-04 12:00:00 -0800586 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(16), 1137500 },
587 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(16), 1150000 },
Stephen Boyd1be9bf62011-11-21 10:51:46 -0800588 { 0, { 0 } }
589};
590
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700591/* TODO: Update vdd_dig and vdd_mem when voltage data is available. */
592#undef L2
593#define L2(x) (&l2_freq_tbl_8064[(x)])
594static struct l2_level l2_freq_tbl_8064[] = {
595 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, 1050000, 1050000, 0 },
Tianyi Goud750d742012-03-02 14:38:58 -0800596 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, 1050000, 1050000, 1 },
597 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, 1050000, 1050000, 2 },
598 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, 1050000, 1050000, 2 },
599 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, 1050000, 1050000, 2 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700600 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, 1050000, 1050000, 2 },
Tianyi Goud750d742012-03-02 14:38:58 -0800601 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, 1050000, 1050000, 4 },
602 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, 1050000, 1050000, 4 },
603 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, 1150000, 1150000, 4 },
604 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 4 },
605 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 4 },
606 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 7 },
607 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 7 },
608 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 7 },
609 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 7 },
610 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 7 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700611};
612
613/* TODO: Update core voltages when data is available. */
614static struct acpu_level acpu_freq_tbl_8064[] = {
Tianyi Goud750d742012-03-02 14:38:58 -0800615 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 950000 },
616 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 950000 },
617 { 0, { 432000, HFPLL, 2, 0, 0x20 }, L2(7), 975000 },
618 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(7), 975000 },
619 { 0, { 540000, HFPLL, 2, 0, 0x28 }, L2(7), 1000000 },
620 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(7), 1000000 },
621 { 0, { 648000, HFPLL, 1, 0, 0x18 }, L2(7), 1025000 },
622 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(7), 1025000 },
623 { 0, { 756000, HFPLL, 1, 0, 0x1C }, L2(7), 1075000 },
624 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(7), 1075000 },
625 { 0, { 864000, HFPLL, 1, 0, 0x20 }, L2(7), 1100000 },
626 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(7), 1100000 },
627 { 0, { 972000, HFPLL, 1, 0, 0x24 }, L2(7), 1125000 },
628 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(7), 1125000 },
629 { 0, { 1080000, HFPLL, 1, 0, 0x28 }, L2(15), 1175000 },
630 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(15), 1175000 },
631 { 0, { 1188000, HFPLL, 1, 0, 0x2C }, L2(15), 1200000 },
632 { 1, { 1242000, HFPLL, 1, 0, 0x2E }, L2(15), 1200000 },
633 { 0, { 1296000, HFPLL, 1, 0, 0x30 }, L2(15), 1225000 },
634 { 1, { 1350000, HFPLL, 1, 0, 0x32 }, L2(15), 1225000 },
635 { 0, { 1404000, HFPLL, 1, 0, 0x34 }, L2(15), 1237500 },
636 { 1, { 1458000, HFPLL, 1, 0, 0x36 }, L2(15), 1237500 },
637 { 1, { 1512000, HFPLL, 1, 0, 0x38 }, L2(15), 1250000 },
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700638 { 0, { 0 } }
639};
640
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800641/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
642#undef L2
643#define L2(x) (&l2_freq_tbl_8930[(x)])
644static struct l2_level l2_freq_tbl_8930[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800645 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
646 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
647 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
648 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
649 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 1 },
650 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
651 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
652 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 2 },
653 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 2 },
654 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
655 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 3 },
656 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 3 },
657 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 3 },
658 [13] = { { 1026000, HFPLL, 1, 0, 0x26 }, LVL_HIGH, 1150000, 4 },
659 [14] = { { 1080000, HFPLL, 1, 0, 0x28 }, LVL_HIGH, 1150000, 4 },
660 [15] = { { 1134000, HFPLL, 1, 0, 0x2A }, LVL_HIGH, 1150000, 4 },
661 [16] = { { 1188000, HFPLL, 1, 0, 0x2C }, LVL_HIGH, 1150000, 4 },
Tianyi Gou7c6b81f2011-12-07 23:09:08 -0800662};
663
664/* TODO: Update core voltages when data is available. */
665static struct acpu_level acpu_freq_tbl_8930[] = {
666 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
667 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
668 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(6), 925000 },
669 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(6), 925000 },
670 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(6), 937500 },
671 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(6), 962500 },
672 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(6), 987500 },
673 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(6), 1000000 },
674 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(11), 1025000 },
675 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(11), 1062500 },
676 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(11), 1062500 },
677 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(11), 1087500 },
678 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(16), 1100000 },
679 { 1, { 1026000, HFPLL, 1, 0, 0x26 }, L2(16), 1100000 },
680 { 1, { 1080000, HFPLL, 1, 0, 0x28 }, L2(16), 1100000 },
681 { 1, { 1134000, HFPLL, 1, 0, 0x2A }, L2(16), 1100000 },
682 { 1, { 1188000, HFPLL, 1, 0, 0x2C }, L2(16), 1125000 },
683 { 0, { 0 } }
684};
685
Tianyi Goue0b34de2011-12-20 11:20:10 -0800686/* TODO: Update vdd_dig, vdd_mem and bw when data is available. */
687#undef L2
688#define L2(x) (&l2_freq_tbl_8627[(x)])
689static struct l2_level l2_freq_tbl_8627[] = {
Tianyi Gou50705682012-02-21 17:51:50 -0800690 [0] = { {STBY_KHZ, QSB, 0, 0, 0x00 }, LVL_NOM, 1050000, 0 },
691 [1] = { { 384000, PLL_8, 0, 2, 0x00 }, LVL_NOM, 1050000, 1 },
692 [2] = { { 432000, HFPLL, 2, 0, 0x20 }, LVL_NOM, 1050000, 1 },
693 [3] = { { 486000, HFPLL, 2, 0, 0x24 }, LVL_NOM, 1050000, 1 },
694 [4] = { { 540000, HFPLL, 2, 0, 0x28 }, LVL_NOM, 1050000, 2 },
695 [5] = { { 594000, HFPLL, 1, 0, 0x16 }, LVL_NOM, 1050000, 2 },
696 [6] = { { 648000, HFPLL, 1, 0, 0x18 }, LVL_NOM, 1050000, 2 },
697 [7] = { { 702000, HFPLL, 1, 0, 0x1A }, LVL_NOM, 1050000, 3 },
698 [8] = { { 756000, HFPLL, 1, 0, 0x1C }, LVL_HIGH, 1150000, 3 },
699 [9] = { { 810000, HFPLL, 1, 0, 0x1E }, LVL_HIGH, 1150000, 3 },
700 [10] = { { 864000, HFPLL, 1, 0, 0x20 }, LVL_HIGH, 1150000, 4 },
701 [11] = { { 918000, HFPLL, 1, 0, 0x22 }, LVL_HIGH, 1150000, 4 },
702 [12] = { { 972000, HFPLL, 1, 0, 0x24 }, LVL_HIGH, 1150000, 4 },
Tianyi Goue0b34de2011-12-20 11:20:10 -0800703};
704
705/* TODO: Update core voltages when data is available. */
706static struct acpu_level acpu_freq_tbl_8627[] = {
707 { 0, { STBY_KHZ, QSB, 0, 0, 0x00 }, L2(0), 900000 },
708 { 1, { 384000, PLL_8, 0, 2, 0x00 }, L2(1), 900000 },
709 { 1, { 432000, HFPLL, 2, 0, 0x20 }, L2(5), 925000 },
710 { 1, { 486000, HFPLL, 2, 0, 0x24 }, L2(5), 925000 },
711 { 1, { 540000, HFPLL, 2, 0, 0x28 }, L2(5), 937500 },
712 { 1, { 594000, HFPLL, 1, 0, 0x16 }, L2(5), 962500 },
713 { 1, { 648000, HFPLL, 1, 0, 0x18 }, L2(9), 987500 },
714 { 1, { 702000, HFPLL, 1, 0, 0x1A }, L2(9), 1000000 },
715 { 1, { 756000, HFPLL, 1, 0, 0x1C }, L2(9), 1025000 },
716 { 1, { 810000, HFPLL, 1, 0, 0x1E }, L2(9), 1062500 },
717 { 1, { 864000, HFPLL, 1, 0, 0x20 }, L2(12), 1062500 },
718 { 1, { 918000, HFPLL, 1, 0, 0x22 }, L2(12), 1087500 },
719 { 1, { 972000, HFPLL, 1, 0, 0x24 }, L2(12), 1100000 },
720 { 0, { 0 } }
721};
722
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700723static unsigned long acpuclk_8960_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700724{
725 return scalable[cpu].current_speed->khz;
726}
727
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700728/* Get the selected source on primary MUX. */
729static int get_pri_clk_src(struct scalable *sc)
730{
731 uint32_t regval;
732
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700733 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734 return regval & 0x3;
735}
736
737/* Set the selected source on primary MUX. */
738static void set_pri_clk_src(struct scalable *sc, uint32_t pri_src_sel)
739{
740 uint32_t regval;
741
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700742 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700743 regval &= ~0x3;
744 regval |= (pri_src_sel & 0x3);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700745 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700746 /* Wait for switch to complete. */
747 mb();
748 udelay(1);
749}
750
751/* Get the selected source on secondary MUX. */
752static int get_sec_clk_src(struct scalable *sc)
753{
754 uint32_t regval;
755
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700756 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757 return (regval >> 2) & 0x3;
758}
759
760/* Set the selected source on secondary MUX. */
761static void set_sec_clk_src(struct scalable *sc, uint32_t sec_src_sel)
762{
763 uint32_t regval;
764
765 /* Disable secondary source clock gating during switch. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700766 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700767 regval |= SECCLKAGD;
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700768 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700769
770 /* Program the MUX. */
771 regval &= ~(0x3 << 2);
772 regval |= ((sec_src_sel & 0x3) << 2);
Stephen Boyd469ed3e2011-09-29 16:41:19 -0700773 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700774
775 /* Wait for switch to complete. */
776 mb();
777 udelay(1);
Stephen Boyd753b5092011-10-17 19:14:12 -0700778
779 /* Re-enable secondary source clock gating. */
780 regval &= ~SECCLKAGD;
781 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782}
783
784/* Enable an already-configured HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800785static void hfpll_enable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700786{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700787 int rc;
788
Matt Wagantallc1021762012-01-31 20:02:02 -0800789 if (!skip_regulators) {
790 if (cpu_is_msm8960()) {
791 rc = rpm_vreg_set_voltage(
792 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
793 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
794 2100000,
795 sc->vreg[VREG_HFPLL_A].max_vdd, 0);
796 if (rc)
797 pr_err("%s regulator enable failed (%d)\n",
798 sc->vreg[VREG_HFPLL_A].name, rc);
799 }
800 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
801 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 1800000,
802 sc->vreg[VREG_HFPLL_B].max_vdd, 0);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800803 if (rc)
804 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800805 sc->vreg[VREG_HFPLL_B].name, rc);
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800806 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700807 /* Disable PLL bypass mode. */
808 writel_relaxed(0x2, sc->hfpll_base + HFPLL_MODE);
809
810 /*
811 * H/W requires a 5us delay between disabling the bypass and
812 * de-asserting the reset. Delay 10us just to be safe.
813 */
814 mb();
815 udelay(10);
816
817 /* De-assert active-low PLL reset. */
818 writel_relaxed(0x6, sc->hfpll_base + HFPLL_MODE);
819
820 /* Wait for PLL to lock. */
821 mb();
822 udelay(60);
823
824 /* Enable PLL output. */
825 writel_relaxed(0x7, sc->hfpll_base + HFPLL_MODE);
826}
827
828/* Disable a HFPLL for power-savings or while its being reprogrammed. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800829static void hfpll_disable(struct scalable *sc, bool skip_regulators)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830{
Matt Wagantallcb12c392011-10-19 10:32:07 -0700831 int rc;
832
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700833 /*
834 * Disable the PLL output, disable test mode, enable
835 * the bypass mode, and assert the reset.
836 */
837 writel_relaxed(0, sc->hfpll_base + HFPLL_MODE);
Matt Wagantallcb12c392011-10-19 10:32:07 -0700838
Matt Wagantallc1021762012-01-31 20:02:02 -0800839 if (!skip_regulators) {
840 rc = rpm_vreg_set_voltage(sc->vreg[VREG_HFPLL_B].rpm_vreg_id,
841 sc->vreg[VREG_HFPLL_B].rpm_vreg_voter, 0,
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800842 0, 0);
843 if (rc)
844 pr_err("%s regulator enable failed (%d)\n",
Matt Wagantallc1021762012-01-31 20:02:02 -0800845 sc->vreg[VREG_HFPLL_B].name, rc);
846
847 if (cpu_is_msm8960()) {
848 rc = rpm_vreg_set_voltage(
849 sc->vreg[VREG_HFPLL_A].rpm_vreg_id,
850 sc->vreg[VREG_HFPLL_A].rpm_vreg_voter,
851 0, 0, 0);
852 if (rc)
853 pr_err("%s regulator enable failed (%d)\n",
854 sc->vreg[VREG_HFPLL_A].name, rc);
855 }
Matt Wagantall4dd373d2012-01-23 12:38:18 -0800856 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700857}
858
859/* Program the HFPLL rate. Assumes HFPLL is already disabled. */
860static void hfpll_set_rate(struct scalable *sc, struct core_speed *tgt_s)
861{
862 writel_relaxed(tgt_s->pll_l_val, sc->hfpll_base + HFPLL_L_VAL);
863}
864
865/* Return the L2 speed that should be applied. */
866static struct l2_level *compute_l2_level(struct scalable *sc,
867 struct l2_level *vote_l)
868{
869 struct l2_level *new_l;
870 int cpu;
871
872 /* Bounds check. */
Vikram Mulukutlaa00149c2011-07-21 18:43:26 -0700873 BUG_ON(vote_l >= (l2_freq_tbl + l2_freq_tbl_size));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874
875 /* Find max L2 speed vote. */
876 sc->l2_vote = vote_l;
877 new_l = l2_freq_tbl;
878 for_each_present_cpu(cpu)
879 new_l = max(new_l, scalable[cpu].l2_vote);
880
881 return new_l;
882}
883
884/* Update the bus bandwidth request. */
885static void set_bus_bw(unsigned int bw)
886{
887 int ret;
888
889 /* Bounds check. */
890 if (bw >= ARRAY_SIZE(bw_level_tbl)) {
891 pr_err("invalid bandwidth request (%d)\n", bw);
892 return;
893 }
894
895 /* Update bandwidth if request has changed. This may sleep. */
896 ret = msm_bus_scale_client_update_request(bus_perf_client, bw);
897 if (ret)
898 pr_err("bandwidth request failed (%d)\n", ret);
899}
900
901/* Set the CPU or L2 clock speed. */
902static void set_speed(struct scalable *sc, struct core_speed *tgt_s,
903 enum setrate_reason reason)
904{
905 struct core_speed *strt_s = sc->current_speed;
906
907 if (tgt_s == strt_s)
908 return;
909
910 if (strt_s->src == HFPLL && tgt_s->src == HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911 /*
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700912 * Move to an always-on source running at a frequency that does
913 * not require an elevated CPU voltage. PLL8 is used here.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700914 */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -0700915 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
917
918 /* Program CPU HFPLL. */
Matt Wagantallc1021762012-01-31 20:02:02 -0800919 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700920 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800921 hfpll_enable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922
923 /* Move CPU to HFPLL source. */
924 set_pri_clk_src(sc, tgt_s->pri_src_sel);
925 } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926 /*
927 * If responding to CPU_DEAD we must be running on another
928 * CPU. Therefore, we can't access the downed CPU's CP15
929 * clock MUX registers from here and can't change clock sources.
930 * Just turn off the PLL- since the CPU is down already, halting
931 * its clock should be safe.
932 */
933 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2]) {
934 set_sec_clk_src(sc, tgt_s->sec_src_sel);
935 set_pri_clk_src(sc, tgt_s->pri_src_sel);
936 }
Matt Wagantallc1021762012-01-31 20:02:02 -0800937 hfpll_disable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700938 } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) {
939 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -0800940 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700941 /*
942 * If responding to CPU_UP_PREPARE, we can't change CP15
943 * registers for the CPU that's coming up since we're not
944 * running on that CPU. That's okay though, since the MUX
945 * source was not changed on the way down, either.
946 */
947 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
948 set_pri_clk_src(sc, tgt_s->pri_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950 if (reason != SETRATE_HOTPLUG || sc == &scalable[L2])
951 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700952 }
953
954 sc->current_speed = tgt_s;
955}
956
957/* Apply any per-cpu voltage increases. */
958static int increase_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
959 unsigned int vdd_dig, enum setrate_reason reason)
960{
961 struct scalable *sc = &scalable[cpu];
Saravana Kannan9dcb89f2011-09-26 19:02:22 -0700962 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700963
964 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -0700965 * Increase vdd_mem active-set before vdd_dig.
966 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700967 */
968 if (vdd_mem > sc->vreg[VREG_MEM].cur_vdd) {
969 rc = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
970 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
971 sc->vreg[VREG_MEM].max_vdd, 0);
972 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800973 pr_err("%s increase failed (%d)\n",
974 sc->vreg[VREG_MEM].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975 return rc;
976 }
977 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
978 }
979
980 /* Increase vdd_dig active-set vote. */
981 if (vdd_dig > sc->vreg[VREG_DIG].cur_vdd) {
982 rc = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
983 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
984 sc->vreg[VREG_DIG].max_vdd, 0);
985 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -0800986 pr_err("%s increase failed (%d)\n",
987 sc->vreg[VREG_DIG].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988 return rc;
989 }
990 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
991 }
992
993 /*
994 * Update per-CPU core voltage. Don't do this for the hotplug path for
995 * which it should already be correct. Attempting to set it is bad
996 * because we don't know what CPU we are running on at this point, but
997 * the CPU regulator API requires we call it from the affected CPU.
998 */
999 if (vdd_core > sc->vreg[VREG_CORE].cur_vdd
1000 && reason != SETRATE_HOTPLUG) {
1001 rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1002 sc->vreg[VREG_CORE].max_vdd);
1003 if (rc) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001004 pr_err("%s increase failed (%d)\n",
1005 sc->vreg[VREG_CORE].name, rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001006 return rc;
1007 }
1008 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1009 }
1010
1011 return rc;
1012}
1013
1014/* Apply any per-cpu voltage decreases. */
1015static void decrease_vdd(int cpu, unsigned int vdd_core, unsigned int vdd_mem,
1016 unsigned int vdd_dig, enum setrate_reason reason)
1017{
1018 struct scalable *sc = &scalable[cpu];
1019 int ret;
1020
1021 /*
1022 * Update per-CPU core voltage. This must be called on the CPU
1023 * that's being affected. Don't do this in the hotplug remove path,
1024 * where the rail is off and we're executing on the other CPU.
1025 */
1026 if (vdd_core < sc->vreg[VREG_CORE].cur_vdd
1027 && reason != SETRATE_HOTPLUG) {
1028 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core,
1029 sc->vreg[VREG_CORE].max_vdd);
1030 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001031 pr_err("%s decrease failed (%d)\n",
1032 sc->vreg[VREG_CORE].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001033 return;
1034 }
1035 sc->vreg[VREG_CORE].cur_vdd = vdd_core;
1036 }
1037
1038 /* Decrease vdd_dig active-set vote. */
1039 if (vdd_dig < sc->vreg[VREG_DIG].cur_vdd) {
1040 ret = rpm_vreg_set_voltage(sc->vreg[VREG_DIG].rpm_vreg_id,
1041 sc->vreg[VREG_DIG].rpm_vreg_voter, vdd_dig,
1042 sc->vreg[VREG_DIG].max_vdd, 0);
1043 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001044 pr_err("%s decrease failed (%d)\n",
1045 sc->vreg[VREG_DIG].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001046 return;
1047 }
1048 sc->vreg[VREG_DIG].cur_vdd = vdd_dig;
1049 }
1050
1051 /*
Matt Wagantallabd55f02011-09-12 11:45:54 -07001052 * Decrease vdd_mem active-set after vdd_dig.
1053 * vdd_mem should be >= vdd_dig.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001054 */
1055 if (vdd_mem < sc->vreg[VREG_MEM].cur_vdd) {
1056 ret = rpm_vreg_set_voltage(sc->vreg[VREG_MEM].rpm_vreg_id,
1057 sc->vreg[VREG_MEM].rpm_vreg_voter, vdd_mem,
1058 sc->vreg[VREG_MEM].max_vdd, 0);
1059 if (ret) {
Matt Wagantalld7a2d542012-02-15 00:23:52 -08001060 pr_err("%s decrease failed (%d)\n",
1061 sc->vreg[VREG_MEM].name, ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001062 return;
1063 }
1064 sc->vreg[VREG_MEM].cur_vdd = vdd_mem;
1065 }
1066}
1067
1068static unsigned int calculate_vdd_mem(struct acpu_level *tgt)
1069{
Matt Wagantallabd55f02011-09-12 11:45:54 -07001070 return tgt->l2_level->vdd_mem;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001071}
1072
1073static unsigned int calculate_vdd_dig(struct acpu_level *tgt)
1074{
1075 unsigned int pll_vdd_dig;
1076
Stephen Boydc76158f2011-12-08 12:42:40 -08001077 if (tgt->l2_level->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001078 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001079 else if (tgt->l2_level->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001080 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1081 else
1082 pll_vdd_dig = scalable[L2].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1083
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001084 return max(tgt->l2_level->vdd_dig, pll_vdd_dig);
1085}
1086
Tianyi Gou50705682012-02-21 17:51:50 -08001087static unsigned int calculate_vdd_core(int cpu, struct acpu_level *tgt)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001088{
1089 unsigned int pll_vdd_core;
1090
Stephen Boydc76158f2011-12-08 12:42:40 -08001091 if (tgt->speed.src != HFPLL)
Tianyi Gou50705682012-02-21 17:51:50 -08001092 pll_vdd_core = scalable[cpu].hfpll_vdd_tbl[HFPLL_VDD_NONE];
Stephen Boydc76158f2011-12-08 12:42:40 -08001093 else if (tgt->speed.pll_l_val > HFPLL_LOW_VDD_PLL_L_MAX)
Tianyi Gou50705682012-02-21 17:51:50 -08001094 pll_vdd_core = scalable[cpu].hfpll_vdd_tbl[HFPLL_VDD_NOM];
1095 else
1096 pll_vdd_core = scalable[cpu].hfpll_vdd_tbl[HFPLL_VDD_LOW];
1097
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001098 return max(tgt->vdd_core, pll_vdd_core);
1099}
1100
1101/* Set the CPU's clock rate and adjust the L2 rate, if appropriate. */
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001102static int acpuclk_8960_set_rate(int cpu, unsigned long rate,
1103 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001104{
1105 struct core_speed *strt_acpu_s, *tgt_acpu_s;
1106 struct l2_level *tgt_l2_l;
1107 struct acpu_level *tgt;
1108 unsigned int vdd_mem, vdd_dig, vdd_core;
1109 unsigned long flags;
1110 int rc = 0;
1111
1112 if (cpu > num_possible_cpus()) {
1113 rc = -EINVAL;
1114 goto out;
1115 }
1116
1117 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1118 mutex_lock(&driver_lock);
1119
1120 strt_acpu_s = scalable[cpu].current_speed;
1121
1122 /* Return early if rate didn't change. */
1123 if (rate == strt_acpu_s->khz && scalable[cpu].first_set_call == false)
1124 goto out;
1125
1126 /* Find target frequency. */
1127 for (tgt = acpu_freq_tbl; tgt->speed.khz != 0; tgt++) {
1128 if (tgt->speed.khz == rate) {
1129 tgt_acpu_s = &tgt->speed;
1130 break;
1131 }
1132 }
1133 if (tgt->speed.khz == 0) {
1134 rc = -EINVAL;
1135 goto out;
1136 }
1137
1138 /* Calculate voltage requirements for the current CPU. */
1139 vdd_mem = calculate_vdd_mem(tgt);
1140 vdd_dig = calculate_vdd_dig(tgt);
Tianyi Gou50705682012-02-21 17:51:50 -08001141 vdd_core = calculate_vdd_core(cpu, tgt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001142
1143 /* Increase VDD levels if needed. */
1144 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) {
1145 rc = increase_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1146 if (rc)
1147 goto out;
1148 }
1149
1150 pr_debug("Switching from ACPU%d rate %u KHz -> %u KHz\n",
1151 cpu, strt_acpu_s->khz, tgt_acpu_s->khz);
1152
1153 /* Set the CPU speed. */
1154 set_speed(&scalable[cpu], tgt_acpu_s, reason);
1155
1156 /*
1157 * Update the L2 vote and apply the rate change. A spinlock is
1158 * necessary to ensure L2 rate is calulated and set atomically,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001159 * even if acpuclk_8960_set_rate() is called from an atomic context
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001160 * and the driver_lock mutex is not acquired.
1161 */
1162 spin_lock_irqsave(&l2_lock, flags);
1163 tgt_l2_l = compute_l2_level(&scalable[cpu], tgt->l2_level);
1164 set_speed(&scalable[L2], &tgt_l2_l->speed, reason);
1165 spin_unlock_irqrestore(&l2_lock, flags);
1166
1167 /* Nothing else to do for power collapse or SWFI. */
1168 if (reason == SETRATE_PC || reason == SETRATE_SWFI)
1169 goto out;
1170
1171 /* Update bus bandwith request. */
1172 set_bus_bw(tgt_l2_l->bw_level);
1173
1174 /* Drop VDD levels if we can. */
1175 decrease_vdd(cpu, vdd_core, vdd_mem, vdd_dig, reason);
1176
1177 scalable[cpu].first_set_call = false;
1178 pr_debug("ACPU%d speed change complete\n", cpu);
1179
1180out:
1181 if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG)
1182 mutex_unlock(&driver_lock);
1183 return rc;
1184}
1185
1186/* Initialize a HFPLL at a given rate and enable it. */
1187static void __init hfpll_init(struct scalable *sc, struct core_speed *tgt_s)
1188{
1189 pr_debug("Initializing HFPLL%d\n", sc - scalable);
1190
1191 /* Disable the PLL for re-programming. */
Stephen Boyd4b72cfb2012-02-14 11:45:53 -08001192 hfpll_disable(sc, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001193
1194 /* Configure PLL parameters for integer mode. */
1195 writel_relaxed(0x7845C665, sc->hfpll_base + HFPLL_CONFIG_CTL);
1196 writel_relaxed(0, sc->hfpll_base + HFPLL_M_VAL);
1197 writel_relaxed(1, sc->hfpll_base + HFPLL_N_VAL);
1198
1199 /* Program droop controller. */
1200 writel_relaxed(0x0108C000, sc->hfpll_base + HFPLL_DROOP_CTL);
1201
1202 /* Set an initial rate and enable the PLL. */
1203 hfpll_set_rate(sc, tgt_s);
Matt Wagantallc1021762012-01-31 20:02:02 -08001204 hfpll_enable(sc, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001205}
1206
1207/* Voltage regulator initialization. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001208static void __init regulator_init(int set_vdd)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001209{
1210 int cpu, ret;
1211 struct scalable *sc;
1212
1213 for_each_possible_cpu(cpu) {
1214 sc = &scalable[cpu];
1215 sc->vreg[VREG_CORE].reg = regulator_get(NULL,
1216 sc->vreg[VREG_CORE].name);
1217 if (IS_ERR(sc->vreg[VREG_CORE].reg)) {
1218 pr_err("regulator_get(%s) failed (%ld)\n",
1219 sc->vreg[VREG_CORE].name,
1220 PTR_ERR(sc->vreg[VREG_CORE].reg));
1221 BUG();
1222 }
1223
1224 ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg,
Stephen Boydcfe192b2011-12-09 21:47:14 -08001225 set_vdd,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001226 sc->vreg[VREG_CORE].max_vdd);
1227 if (ret)
1228 pr_err("regulator_set_voltage(%s) failed"
1229 " (%d)\n", sc->vreg[VREG_CORE].name, ret);
1230
1231 ret = regulator_enable(sc->vreg[VREG_CORE].reg);
1232 if (ret)
1233 pr_err("regulator_enable(%s) failed (%d)\n",
1234 sc->vreg[VREG_CORE].name, ret);
1235 }
1236}
1237
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001238/* Set initial rate for a given core. */
1239static void __init init_clock_sources(struct scalable *sc,
1240 struct core_speed *tgt_s)
1241{
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001242 uint32_t regval;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001243
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001244 /* Select PLL8 as AUX source input to the secondary MUX. */
1245 writel_relaxed(0x3, sc->aux_clk_sel);
1246
1247 /* Switch away from the HFPLL while it's re-initialized. */
Matt Wagantall65e5e4b2011-10-27 16:52:10 -07001248 set_sec_clk_src(sc, SEC_SRC_SEL_AUX);
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001249 set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250 hfpll_init(sc, tgt_s);
1251
1252 /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001253 regval = get_l2_indirect_reg(sc->l2cpmr_iaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001254 regval &= ~(0x3 << 6);
Stephen Boyd469ed3e2011-09-29 16:41:19 -07001255 set_l2_indirect_reg(sc->l2cpmr_iaddr, regval);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001256
Matt Wagantall6ba92d82011-10-27 16:51:26 -07001257 /* Switch to the target clock source. */
1258 set_sec_clk_src(sc, tgt_s->sec_src_sel);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001259 set_pri_clk_src(sc, tgt_s->pri_src_sel);
1260 sc->current_speed = tgt_s;
1261
1262 /*
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001263 * Set this flag so that the first call to acpuclk_8960_set_rate() can
1264 * drop voltages and set initial bus bandwidth requests.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265 */
1266 sc->first_set_call = true;
1267}
1268
Matt Wagantall8e726c72011-08-06 00:49:28 -07001269static void __init per_cpu_init(void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001270{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001271 struct acpu_level *max_acpu_level = data;
Matt Wagantall8e726c72011-08-06 00:49:28 -07001272 int cpu = smp_processor_id();
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001273
1274 init_clock_sources(&scalable[cpu], &max_acpu_level->speed);
1275 scalable[cpu].l2_vote = max_acpu_level->l2_level;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001276}
1277
1278/* Register with bus driver. */
Stephen Boydcfe192b2011-12-09 21:47:14 -08001279static void __init bus_init(unsigned int init_bw)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001280{
1281 int ret;
1282
1283 bus_perf_client = msm_bus_scale_register_client(&bus_client_pdata);
1284 if (!bus_perf_client) {
1285 pr_err("unable to register bus client\n");
1286 BUG();
1287 }
1288
Stephen Boydcfe192b2011-12-09 21:47:14 -08001289 ret = msm_bus_scale_client_update_request(bus_perf_client, init_bw);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001290 if (ret)
1291 pr_err("initial bandwidth request failed (%d)\n", ret);
1292}
1293
1294#ifdef CONFIG_CPU_FREQ_MSM
1295static struct cpufreq_frequency_table freq_table[NR_CPUS][30];
1296
1297static void __init cpufreq_table_init(void)
1298{
1299 int cpu;
1300
1301 for_each_possible_cpu(cpu) {
1302 int i, freq_cnt = 0;
1303 /* Construct the freq_table tables from acpu_freq_tbl. */
1304 for (i = 0; acpu_freq_tbl[i].speed.khz != 0
1305 && freq_cnt < ARRAY_SIZE(*freq_table); i++) {
1306 if (acpu_freq_tbl[i].use_for_scaling) {
1307 freq_table[cpu][freq_cnt].index = freq_cnt;
1308 freq_table[cpu][freq_cnt].frequency
1309 = acpu_freq_tbl[i].speed.khz;
1310 freq_cnt++;
1311 }
1312 }
1313 /* freq_table not big enough to store all usable freqs. */
1314 BUG_ON(acpu_freq_tbl[i].speed.khz != 0);
1315
1316 freq_table[cpu][freq_cnt].index = freq_cnt;
1317 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
1318
1319 pr_info("CPU%d: %d scaling frequencies supported.\n",
1320 cpu, freq_cnt);
1321
1322 /* Register table with CPUFreq. */
1323 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
1324 }
1325}
1326#else
1327static void __init cpufreq_table_init(void) {}
1328#endif
1329
1330#define HOT_UNPLUG_KHZ STBY_KHZ
1331static int __cpuinit acpuclock_cpu_callback(struct notifier_block *nfb,
1332 unsigned long action, void *hcpu)
1333{
1334 static int prev_khz[NR_CPUS];
1335 static int prev_pri_src[NR_CPUS];
1336 static int prev_sec_src[NR_CPUS];
1337 int cpu = (int)hcpu;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001338
1339 switch (action) {
1340 case CPU_DYING:
1341 case CPU_DYING_FROZEN:
1342 /*
Matt Wagantall53c33b82012-02-08 10:43:55 -08001343 * On Krait v1 and 8064v1, the primary and secondary muxes must
1344 * be set to QSB before L2 power collapse and restored after.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001345 */
Matt Wagantall53c33b82012-02-08 10:43:55 -08001346 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001347 prev_sec_src[cpu] = get_sec_clk_src(&scalable[cpu]);
1348 prev_pri_src[cpu] = get_pri_clk_src(&scalable[cpu]);
1349 set_sec_clk_src(&scalable[cpu], SEC_SRC_SEL_QSB);
1350 set_pri_clk_src(&scalable[cpu], PRI_SRC_SEL_SEC_SRC);
1351 }
1352 break;
1353 case CPU_DEAD:
1354 case CPU_DEAD_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001355 prev_khz[cpu] = acpuclk_8960_get_rate(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001356 /* Fall through. */
1357 case CPU_UP_CANCELED:
1358 case CPU_UP_CANCELED_FROZEN:
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001359 acpuclk_8960_set_rate(cpu, HOT_UNPLUG_KHZ, SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001360 break;
1361 case CPU_UP_PREPARE:
1362 case CPU_UP_PREPARE_FROZEN:
1363 if (WARN_ON(!prev_khz[cpu]))
Stephen Boydf7e53c12011-12-19 16:37:15 -08001364 return NOTIFY_BAD;
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001365 acpuclk_8960_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001366 break;
1367 case CPU_STARTING:
1368 case CPU_STARTING_FROZEN:
Matt Wagantall53c33b82012-02-08 10:43:55 -08001369 if (cpu_is_krait_v1() || cpu_is_apq8064()) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001370 set_sec_clk_src(&scalable[cpu], prev_sec_src[cpu]);
1371 set_pri_clk_src(&scalable[cpu], prev_pri_src[cpu]);
1372 }
1373 break;
1374 default:
1375 break;
1376 }
1377
1378 return NOTIFY_OK;
1379}
1380
1381static struct notifier_block __cpuinitdata acpuclock_cpu_notifier = {
1382 .notifier_call = acpuclock_cpu_callback,
1383};
1384
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001385static const int krait_needs_vmin(void)
1386{
1387 switch (read_cpuid_id()) {
1388 case 0x511F04D0:
1389 case 0x511F04D1:
1390 case 0x510F06F0:
1391 return 1;
1392 default:
1393 return 0;
1394 };
1395}
1396
Stephen Boydaefb8de2012-01-05 19:05:01 -08001397static void kraitv2_apply_vmin(struct acpu_level *tbl)
1398{
1399 for (; tbl->speed.khz != 0; tbl++)
1400 if (tbl->vdd_core < 1150000)
1401 tbl->vdd_core = 1150000;
1402}
1403
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001404static struct acpu_level * __init select_freq_plan(void)
1405{
1406 struct acpu_level *l, *max_acpu_level = NULL;
1407
1408 /* Select frequency tables. */
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001409 if (cpu_is_msm8960()) {
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001410 uint32_t pte_efuse, pvs;
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001411 struct acpu_level *v1, *v2;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001412
1413 pte_efuse = readl_relaxed(QFPROM_PTE_EFUSE_ADDR);
1414 pvs = (pte_efuse >> 10) & 0x7;
1415 if (pvs == 0x7)
1416 pvs = (pte_efuse >> 13) & 0x7;
1417
1418 switch (pvs) {
1419 case 0x0:
1420 case 0x7:
1421 pr_info("ACPU PVS: Slow\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001422 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1423 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001424 break;
1425 case 0x1:
1426 pr_info("ACPU PVS: Nominal\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001427 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001428 v2 = acpu_freq_tbl_8960_kraitv2_nom;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001429 break;
1430 case 0x3:
1431 pr_info("ACPU PVS: Fast\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001432 v1 = acpu_freq_tbl_8960_kraitv1_nom_fast;
Stephen Boyd5766f682011-12-27 19:21:08 -08001433 v2 = acpu_freq_tbl_8960_kraitv2_fast;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001434 break;
1435 default:
1436 pr_warn("ACPU PVS: Unknown. Defaulting to slow.\n");
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001437 v1 = acpu_freq_tbl_8960_kraitv1_slow;
1438 v2 = acpu_freq_tbl_8960_kraitv2_slow;
Matt Wagantalla518f8f2011-10-17 13:24:53 -07001439 break;
1440 }
1441
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001442 scalable = scalable_8960;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001443 if (cpu_is_krait_v1()) {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001444 acpu_freq_tbl = v1;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001445 l2_freq_tbl = l2_freq_tbl_8960_kraitv1;
1446 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv1);
1447 } else {
Stephen Boyd9d0fab12011-12-08 10:56:06 -08001448 acpu_freq_tbl = v2;
Stephen Boyd1be9bf62011-11-21 10:51:46 -08001449 l2_freq_tbl = l2_freq_tbl_8960_kraitv2;
1450 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8960_kraitv2);
1451 }
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001452 } else if (cpu_is_apq8064()) {
1453 scalable = scalable_8064;
1454 acpu_freq_tbl = acpu_freq_tbl_8064;
1455 l2_freq_tbl = l2_freq_tbl_8064;
1456 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8064);
Tianyi Goue0b34de2011-12-20 11:20:10 -08001457 } else if (cpu_is_msm8627()) {
1458 scalable = scalable_8627;
1459 acpu_freq_tbl = acpu_freq_tbl_8627;
1460 l2_freq_tbl = l2_freq_tbl_8627;
1461 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8627);
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001462 } else if (cpu_is_msm8930()) {
1463 scalable = scalable_8930;
1464 acpu_freq_tbl = acpu_freq_tbl_8930;
1465 l2_freq_tbl = l2_freq_tbl_8930;
1466 l2_freq_tbl_size = ARRAY_SIZE(l2_freq_tbl_8930);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001467 } else {
1468 BUG();
1469 }
Stephen Boyd9674f5f2012-01-11 23:04:18 -08001470 if (krait_needs_vmin())
1471 kraitv2_apply_vmin(acpu_freq_tbl);
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001472
1473 /* Find the max supported scaling frequency. */
1474 for (l = acpu_freq_tbl; l->speed.khz != 0; l++)
1475 if (l->use_for_scaling)
1476 max_acpu_level = l;
1477 BUG_ON(!max_acpu_level);
1478 pr_info("Max ACPU freq: %u KHz\n", max_acpu_level->speed.khz);
1479
1480 return max_acpu_level;
1481}
1482
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001483static struct acpuclk_data acpuclk_8960_data = {
1484 .set_rate = acpuclk_8960_set_rate,
1485 .get_rate = acpuclk_8960_get_rate,
1486 .power_collapse_khz = STBY_KHZ,
1487 .wait_for_irq_khz = STBY_KHZ,
1488};
1489
Matt Wagantallec57f062011-08-16 23:54:46 -07001490static int __init acpuclk_8960_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001491{
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001492 struct acpu_level *max_acpu_level = select_freq_plan();
Stephen Boydcfe192b2011-12-09 21:47:14 -08001493
1494 regulator_init(max_acpu_level->vdd_core);
1495 bus_init(max_acpu_level->l2_level->bw_level);
1496
Matt Wagantall6b013ca2011-10-12 14:15:45 -07001497 init_clock_sources(&scalable[L2], &max_acpu_level->l2_level->speed);
1498 on_each_cpu(per_cpu_init, max_acpu_level, true);
Matt Wagantall8e726c72011-08-06 00:49:28 -07001499
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001500 cpufreq_table_init();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001501
1502 acpuclk_register(&acpuclk_8960_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001503 register_hotcpu_notifier(&acpuclock_cpu_notifier);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001504
1505 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001506}
Matt Wagantallec57f062011-08-16 23:54:46 -07001507
1508struct acpuclk_soc_data acpuclk_8960_soc_data __initdata = {
1509 .init = acpuclk_8960_init,
1510};
Tianyi Gou7c6b81f2011-12-07 23:09:08 -08001511
1512struct acpuclk_soc_data acpuclk_8930_soc_data __initdata = {
1513 .init = acpuclk_8960_init,
1514};
Vikram Mulukutlabc2e9572011-11-04 03:41:38 -07001515
1516struct acpuclk_soc_data acpuclk_8064_soc_data __initdata = {
1517 .init = acpuclk_8960_init,
1518};