blob: 687033cc2340f85bfd85b32e76c22c15526d3bd4 [file] [log] [blame]
Matt Wagantalld1af38e2011-08-06 01:38:02 -07001/*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 * MSM architecture clock driver
3 *
4 * Copyright (C) 2007 Google, Inc.
Pankaj Kumarc9136b32012-01-02 18:46:13 +05305 * Copyright (c) 2007-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006 * Author: San Mehat <san@android.com>
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/version.h>
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/errno.h>
23#include <linux/string.h>
24#include <linux/delay.h>
25#include <linux/clk.h>
26#include <linux/cpufreq.h>
27#include <linux/mutex.h>
28#include <linux/io.h>
29#include <linux/sort.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030#include <mach/board.h>
31#include <mach/msm_iomap.h>
32#include <asm/mach-types.h>
33#include <mach/socinfo.h>
34
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035#include "smd_private.h"
36#include "acpuclock.h"
37
38#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
39#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
40#define A11S_VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070043#define POWER_COLLAPSE_KHZ 19200
44
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070045/* Max CPU frequency allowed by hardware while in standby waiting for an irq. */
46#define MAX_WAIT_FOR_IRQ_KHZ 128000
47
Pankaj Kumar3912c982011-12-07 16:59:03 +053048/**
49 * enum - For acpuclock PLL IDs
50 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051enum {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052 ACPU_PLL_0 = 0,
53 ACPU_PLL_1,
54 ACPU_PLL_2,
55 ACPU_PLL_3,
56 ACPU_PLL_4,
Pankaj Kumar0249bed2012-03-08 15:20:54 +053057 ACPU_PLL_TCXO,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058 ACPU_PLL_END,
59};
60
Pankaj Kumar3912c982011-12-07 16:59:03 +053061struct acpu_clk_src {
62 struct clk *clk;
63 const char *name;
64};
65
66static struct acpu_clk_src pll_clk[ACPU_PLL_END] = {
67 [ACPU_PLL_0] = { .name = "pll0_clk" },
68 [ACPU_PLL_1] = { .name = "pll1_clk" },
69 [ACPU_PLL_2] = { .name = "pll2_clk" },
70 [ACPU_PLL_4] = { .name = "pll4_clk" },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071};
72
73struct clock_state {
74 struct clkctl_acpu_speed *current_speed;
75 struct mutex lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076 uint32_t max_speed_delta_khz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077 struct clk *ebi1_clk;
78};
79
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080struct clkctl_acpu_speed {
81 unsigned int use_for_scaling;
82 unsigned int a11clk_khz;
83 int pll;
84 unsigned int a11clk_src_sel;
85 unsigned int a11clk_src_div;
86 unsigned int ahbclk_khz;
87 unsigned int ahbclk_div;
88 int vdd;
89 unsigned int axiclk_khz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090 /* Pointers in acpu_freq_tbl[] for max up/down steppings. */
91 struct clkctl_acpu_speed *down[ACPU_PLL_END];
92 struct clkctl_acpu_speed *up[ACPU_PLL_END];
93};
94
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095static struct clock_state drv_state = { 0 };
96static struct clkctl_acpu_speed *acpu_freq_tbl;
97
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098/*
99 * ACPU freq tables used for different PLLs frequency combinations. The
100 * correct table is selected during init.
101 *
102 * Table stepping up/down entries are calculated during boot to choose the
103 * largest frequency jump that's less than max_speed_delta_khz on each PLL.
104 */
105
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530106/* 7627 with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = {
108 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
109 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
110 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
111 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
112 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530113 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
114 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
115 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
116 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530117 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118};
119
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530120/* 7627 with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = {
122 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
123 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
124 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
125 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
126 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530127 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
128 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
129 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
130 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530131 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132};
133
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530134/* 7627 with GSM capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = {
136 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
137 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
138 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
139 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 },
140 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530141 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
142 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
143 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
144 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530145 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146};
147
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530148/* 7627 with CDMA capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700149static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = {
150 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
151 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
152 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
153 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
154 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530155 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
156 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
157 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
158 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530159 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160};
161
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530162/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530164 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
165 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
166 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
167 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530168 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530169 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
170 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
171 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
172 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
173 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530174 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175};
176
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530177/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530179 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
180 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
181 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
182 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Trilok Soniabb750b2011-07-13 16:47:18 +0530183 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
184 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
185 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
186 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530187 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
188 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530189 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190};
191
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530192/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Sonif597e242011-06-06 12:37:16 +0530193static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = {
194 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
195 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
196 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
197 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530198 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonif597e242011-06-06 12:37:16 +0530199 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
200 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
201 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
202 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
203 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Pankaj Kumar94528702012-03-02 16:00:33 +0530204 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Sonif597e242011-06-06 12:37:16 +0530205};
206
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530207/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Sonid7b05e52011-08-17 18:09:08 +0530208static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008[] = {
209 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
210 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
211 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
212 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530213 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530214 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
215 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
216 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
217 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
218 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Pankaj Kumar94528702012-03-02 16:00:33 +0530219 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Sonid7b05e52011-08-17 18:09:08 +0530220};
221
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530222/* 8625 PLL4 @ 1209MHz with GSM capable modem */
223static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1209[] = {
224 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
225 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
226 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
227 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
228 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
229 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
230 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
231 { 0, 604800, ACPU_PLL_4, 6, 1, 75600, 3, 6, 200000 },
232 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 7, 200000},
233 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
234};
235
236/* 8625 PLL4 @ 1209MHz with CDMA capable modem */
237static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1209[] = {
238 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
239 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
240 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
241 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
242 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
243 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
244 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
245 { 0, 604800, ACPU_PLL_4, 6, 1, 75600, 3, 6, 200000 },
246 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 7, 200000},
247 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
248};
249
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530250/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530251static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_25a[] = {
Trilok Soni54d35c42011-07-14 17:47:50 +0530252 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
253 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
254 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
255 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530256 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530257 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530258 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530259 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
260 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530261 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Soni54d35c42011-07-14 17:47:50 +0530262};
263
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530264/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530265static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = {
266 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
267 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
268 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
269 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530270 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530271 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
272 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
273 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
274 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
275 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530276 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530277};
278
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530279/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530280static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = {
281 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
282 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
283 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
284 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
285 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
286 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
287 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
288 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
289 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
290 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530291 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530292};
293
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530294/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530295static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = {
296 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
297 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
298 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
299 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530300 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530301 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
302 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
303 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
304 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
305 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Pankaj Kumar94528702012-03-02 16:00:33 +0530306 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530307};
308
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530309/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530310static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = {
311 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
312 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
313 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
314 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530315 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530316 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
317 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
318 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
319 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
320 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Pankaj Kumar94528702012-03-02 16:00:33 +0530321 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530322};
323
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530324/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530325static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_25a[] = {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530326 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
327 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
328 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
329 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530330 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530331 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530332 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530333 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
334 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Pankaj Kumar94528702012-03-02 16:00:33 +0530335 { 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530336};
337
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700338#define PLL_CONFIG(m0, m1, m2, m4) { \
Pankaj Kumar3912c982011-12-07 16:59:03 +0530339 m0, m1, m2, m4, \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700340 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
341}
342
343struct pll_freq_tbl_map {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530344 unsigned int pll0_rate;
345 unsigned int pll1_rate;
346 unsigned int pll2_rate;
347 unsigned int pll4_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700348 struct clkctl_acpu_speed *tbl;
349};
350
351static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700352 PLL_CONFIG(960, 196, 1200, 0),
353 PLL_CONFIG(960, 245, 1200, 0),
354 PLL_CONFIG(960, 196, 800, 0),
355 PLL_CONFIG(960, 245, 800, 0),
356 PLL_CONFIG(960, 245, 1200, 800),
357 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530358 PLL_CONFIG(960, 245, 1200, 1008),
Trilok Sonid7b05e52011-08-17 18:09:08 +0530359 PLL_CONFIG(960, 196, 1200, 1008),
Trilok Soni9bb022c2011-10-31 18:25:19 +0530360 PLL_CONFIG(960, 737, 1200, 800),
361 PLL_CONFIG(960, 589, 1200, 800),
362 PLL_CONFIG(960, 737, 1200, 1008),
363 PLL_CONFIG(960, 589, 1200, 1008),
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530364 PLL_CONFIG(960, 245, 1200, 1209),
365 PLL_CONFIG(960, 196, 1200, 1209),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700366 { 0, 0, 0, 0, 0 }
367};
368
369#ifdef CONFIG_CPU_FREQ_MSM
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530370static struct cpufreq_frequency_table freq_table[NR_CPUS][20];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700371
372static void __init cpufreq_table_init(void)
373{
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530374 int cpu;
375 for_each_possible_cpu(cpu) {
376 unsigned int i, freq_cnt = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700377
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530378 /* Construct the freq_table table from acpu_freq_tbl since
379 * the freq_table values need to match frequencies specified
380 * in acpu_freq_tbl and acpu_freq_tbl needs to be fixed up
381 * during init.
382 */
383 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
384 && freq_cnt < ARRAY_SIZE(*freq_table)-1; i++) {
385 if (acpu_freq_tbl[i].use_for_scaling) {
386 freq_table[cpu][freq_cnt].index = freq_cnt;
387 freq_table[cpu][freq_cnt].frequency
388 = acpu_freq_tbl[i].a11clk_khz;
389 freq_cnt++;
390 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700391 }
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530392
393 /* freq_table not big enough to store all usable freqs. */
394 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
395
396 freq_table[cpu][freq_cnt].index = freq_cnt;
397 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
398 /* Register table with CPUFreq. */
399 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
400 pr_info("CPU%d: %d scaling frequencies supported.\n",
401 cpu, freq_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700402 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700403}
404#endif
405
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700406static int acpuclk_set_vdd_level(int vdd)
407{
408 uint32_t current_vdd;
409
Pankaj Kumar9406a3b2011-12-23 18:07:15 +0530410 /*
411 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
412 * VDD switching support.
413 */
414 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
415 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
416 return 0;
417
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700418 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
419
420 pr_debug("Switching VDD from %u mV -> %d mV\n",
421 current_vdd, vdd);
422
423 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
424 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700425 udelay(62);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
427 pr_err("VDD set failed\n");
428 return -EIO;
429 }
430
431 pr_debug("VDD switched\n");
432
433 return 0;
434}
435
436/* Set proper dividers for the given clock speed. */
437static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
438{
439 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
440
441 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
442
443 /* AHB_CLK_DIV */
444 clk_div = (reg_clksel >> 1) & 0x03;
445 /* CLK_SEL_SRC1NO */
446 src_sel = reg_clksel & 1;
447
448 /*
449 * If the new clock divider is higher than the previous, then
450 * program the divider before switching the clock
451 */
452 if (hunt_s->ahbclk_div > clk_div) {
453 reg_clksel &= ~(0x3 << 1);
454 reg_clksel |= (hunt_s->ahbclk_div << 1);
455 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
456 }
457
458 /* Program clock source and divider */
459 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
460 reg_clkctl &= ~(0xFF << (8 * src_sel));
461 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
462 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
463 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
464
465 /* Program clock source selection */
466 reg_clksel ^= 1;
467 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
468
469 /*
470 * If the new clock divider is lower than the previous, then
471 * program the divider after switching the clock
472 */
473 if (hunt_s->ahbclk_div < clk_div) {
474 reg_clksel &= ~(0x3 << 1);
475 reg_clksel |= (hunt_s->ahbclk_div << 1);
476 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
477 }
478}
479
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530480static int acpuclk_7627_set_rate(int cpu, unsigned long rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700481 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700482{
483 uint32_t reg_clkctl;
484 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
485 int res, rc = 0;
486 unsigned int plls_enabled = 0, pll;
487
488 if (reason == SETRATE_CPUFREQ)
489 mutex_lock(&drv_state.lock);
490
491 strt_s = cur_s = drv_state.current_speed;
492
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700493 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700494 if (cur_s == NULL) {
495 rc = -ENOENT;
496 goto out;
497 }
498
499 if (rate == cur_s->a11clk_khz)
500 goto out;
501
502 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
503 if (tgt_s->a11clk_khz == rate)
504 break;
505 }
506
507 if (tgt_s->a11clk_khz == 0) {
508 rc = -EINVAL;
509 goto out;
510 }
511
512 /* Choose the highest speed at or below 'rate' with same PLL. */
513 if (reason != SETRATE_CPUFREQ
514 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
515 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
516 tgt_s--;
517 }
518
519 if (strt_s->pll != ACPU_PLL_TCXO)
520 plls_enabled |= 1 << strt_s->pll;
521
522 if (reason == SETRATE_CPUFREQ) {
523 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530524 rc = clk_prepare_enable(pll_clk[tgt_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525 if (rc < 0) {
526 pr_err("PLL%d enable failed (%d)\n",
527 tgt_s->pll, rc);
528 goto out;
529 }
530 plls_enabled |= 1 << tgt_s->pll;
531 }
532 }
533 /* Need to do this when coming out of power collapse since some modem
534 * firmwares reset the VDD when the application processor enters power
535 * collapse. */
536 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
537 /* Increase VDD if needed. */
538 if (tgt_s->vdd > cur_s->vdd) {
539 rc = acpuclk_set_vdd_level(tgt_s->vdd);
540 if (rc < 0) {
541 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
542 goto out;
543 }
544 }
545 }
546
547 /* Set wait states for CPU inbetween frequency changes */
548 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
549 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
550 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
551
552 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
553 strt_s->a11clk_khz, tgt_s->a11clk_khz);
554
555 while (cur_s != tgt_s) {
556 /*
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530557 * Always jump to target freq if within max_speed_delta_khz,
558 * regardless of PLL. If differnece is greater, use the
559 * predefined steppings in the table.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700560 */
561 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
562 if (d > drv_state.max_speed_delta_khz) {
563
564 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
565 /* Step up: jump to target PLL as early as
566 * possible so indexing using TCXO (up[-1])
567 * never occurs. */
568 if (likely(cur_s->up[tgt_s->pll]))
569 cur_s = cur_s->up[tgt_s->pll];
570 else
571 cur_s = cur_s->up[cur_s->pll];
572 } else {
573 /* Step down: stay on current PLL as long as
574 * possible so indexing using TCXO (down[-1])
575 * never occurs. */
576 if (likely(cur_s->down[cur_s->pll]))
577 cur_s = cur_s->down[cur_s->pll];
578 else
579 cur_s = cur_s->down[tgt_s->pll];
580 }
581
582 if (cur_s == NULL) { /* This should not happen. */
583 pr_err("No stepping frequencies found. "
584 "strt_s:%u tgt_s:%u\n",
585 strt_s->a11clk_khz, tgt_s->a11clk_khz);
586 rc = -EINVAL;
587 goto out;
588 }
589
590 } else {
591 cur_s = tgt_s;
592 }
593
594 pr_debug("STEP khz = %u, pll = %d\n",
595 cur_s->a11clk_khz, cur_s->pll);
596
597 if (cur_s->pll != ACPU_PLL_TCXO
598 && !(plls_enabled & (1 << cur_s->pll))) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530599 rc = clk_prepare_enable(pll_clk[cur_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700600 if (rc < 0) {
601 pr_err("PLL%d enable failed (%d)\n",
602 cur_s->pll, rc);
603 goto out;
604 }
605 plls_enabled |= 1 << cur_s->pll;
606 }
607
608 acpuclk_set_div(cur_s);
609 drv_state.current_speed = cur_s;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700610 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700611 udelay(50);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700612 }
613
614 /* Nothing else to do for SWFI. */
615 if (reason == SETRATE_SWFI)
616 goto out;
617
618 /* Change the AXI bus frequency if we can. */
619 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
620 res = clk_set_rate(drv_state.ebi1_clk,
621 tgt_s->axiclk_khz * 1000);
622 if (res < 0)
623 pr_warning("Setting AXI min rate failed (%d)\n", res);
624 }
625
626 /* Disable PLLs we are not using anymore. */
627 if (tgt_s->pll != ACPU_PLL_TCXO)
628 plls_enabled &= ~(1 << tgt_s->pll);
629 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
Pankaj Kumar3912c982011-12-07 16:59:03 +0530630 if (plls_enabled & (1 << pll))
631 clk_disable_unprepare(pll_clk[pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700632
633 /* Nothing else to do for power collapse. */
634 if (reason == SETRATE_PC)
635 goto out;
636
637 /* Drop VDD level if we can. */
638 if (tgt_s->vdd < strt_s->vdd) {
639 res = acpuclk_set_vdd_level(tgt_s->vdd);
640 if (res < 0)
641 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
642 }
643
644 pr_debug("ACPU speed change complete\n");
645out:
646 if (reason == SETRATE_CPUFREQ)
647 mutex_unlock(&drv_state.lock);
648 return rc;
649}
650
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700651static void __init acpuclk_hw_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700652{
653 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530654 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700655 int res;
656
657 /*
658 * Determine the rate of ACPU clock
659 */
660
661 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
662 /* CLK_SRC0_SEL */
663 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
664 /* CLK_SRC0_DIV */
665 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
666 } else {
667 /* CLK_SRC1_SEL */
668 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
669 /* CLK_SRC1_DIV */
670 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
671 }
672
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700673 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
674 if (speed->a11clk_src_sel == sel
675 && (speed->a11clk_src_div == div))
676 break;
677 }
678 if (speed->a11clk_khz == 0) {
679 pr_err("Error - ACPU clock reports invalid speed\n");
680 return;
681 }
682
683 drv_state.current_speed = speed;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530684 if (speed->pll != ACPU_PLL_TCXO) {
685 if (clk_prepare_enable(pll_clk[speed->pll].clk))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700686 pr_warning("Failed to vote for boot PLL\n");
Pankaj Kumar3912c982011-12-07 16:59:03 +0530687 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700688
Trilok Soni7d6c8652011-07-14 15:35:07 +0530689 /* Fix div2 to 2 for 7x27/5a(aa) targets */
690 if (!cpu_is_msm7x27()) {
691 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
692 reg_clksel &= ~(0x3 << 14);
693 reg_clksel |= (0x1 << 14);
694 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
695 }
696
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700697 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
698 if (res < 0)
699 pr_warning("Setting AXI min rate failed (%d)\n", res);
Pankaj Kumar19095912012-01-11 18:09:13 +0530700 res = clk_prepare_enable(drv_state.ebi1_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700701 if (res < 0)
702 pr_warning("Enabling AXI clock failed (%d)\n", res);
703
704 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
705}
706
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530707static unsigned long acpuclk_7627_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708{
709 WARN_ONCE(drv_state.current_speed == NULL,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700710 "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700711 if (drv_state.current_speed)
712 return drv_state.current_speed->a11clk_khz;
713 else
714 return 0;
715}
716
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700717/*----------------------------------------------------------------------------
718 * Clock driver initialization
719 *---------------------------------------------------------------------------*/
Pankaj Kumar3912c982011-12-07 16:59:03 +0530720#define MHZ 1000000
721static void __init select_freq_plan(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700722{
Pankaj Kumar3912c982011-12-07 16:59:03 +0530723 unsigned long pll_mhz[ACPU_PLL_END];
724 struct pll_freq_tbl_map *t;
725 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700726
Pankaj Kumar3912c982011-12-07 16:59:03 +0530727 /* Get PLL clocks */
728 for (i = 0; i < ACPU_PLL_END; i++) {
729 if (pll_clk[i].name) {
730 pll_clk[i].clk = clk_get_sys("acpu", pll_clk[i].name);
731 if (IS_ERR(pll_clk[i].clk)) {
732 pll_mhz[i] = 0;
733 continue;
734 }
735 /* Get PLL's Rate */
736 pll_mhz[i] = clk_get_rate(pll_clk[i].clk)/MHZ;
737 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700738 }
739
Pankaj Kumar3912c982011-12-07 16:59:03 +0530740 /*
741 * For the pll configuration used in acpuclock table e.g.
742 * pll0_960_pll1_245_pll2_1200" is same for 7627 and
743 * 7625a (as pll0,pll1,pll2) having same rates, but frequency
744 * table is different for both targets.
745 *
746 * Hence below for loop will not be able to select correct
747 * table based on PLL rates as rates are same. Hence we need
748 * to add this cpu check for selecting the correct acpuclock table.
749 */
Trilok Soni54d35c42011-07-14 17:47:50 +0530750 if (cpu_is_msm7x25a()) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530751 if (pll_mhz[ACPU_PLL_1] == 245) {
Trilok Soni54d35c42011-07-14 17:47:50 +0530752 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530753 pll0_960_pll1_245_pll2_1200_25a;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530754 } else if (pll_mhz[ACPU_PLL_1] == 737) {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530755 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530756 pll0_960_pll1_737_pll2_1200_25a;
Trilok Soni54d35c42011-07-14 17:47:50 +0530757 }
758 } else {
759 /* Select the right table to use. */
Pankaj Kumar3912c982011-12-07 16:59:03 +0530760 for (t = acpu_freq_tbl_list; t->tbl != 0; t++) {
761 if (t->pll0_rate == pll_mhz[ACPU_PLL_0]
762 && t->pll1_rate == pll_mhz[ACPU_PLL_1]
763 && t->pll2_rate == pll_mhz[ACPU_PLL_2]
764 && t->pll4_rate == pll_mhz[ACPU_PLL_4]) {
765 acpu_freq_tbl = t->tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +0530766 break;
767 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768 }
769 }
770
771 if (acpu_freq_tbl == NULL) {
772 pr_crit("Unknown PLL configuration!\n");
773 BUG();
774 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700775}
776
777/*
778 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
779 * before entering a wait for irq low-power mode. Find a suitable rate.
780 */
781static unsigned long __init find_wait_for_irq_khz(void)
782{
783 unsigned long found_khz = 0;
784 int i;
785
786 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
787 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
788 found_khz = acpu_freq_tbl[i].a11clk_khz;
789
790 return found_khz;
791}
792
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700793static void __init precompute_stepping(void)
794{
795 int i, step_idx;
796
797#define cur_freq acpu_freq_tbl[i].a11clk_khz
798#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
799#define cur_pll acpu_freq_tbl[i].pll
800#define step_pll acpu_freq_tbl[step_idx].pll
801
802 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
803
804 /* Calculate max "up" step for each destination PLL */
805 step_idx = i + 1;
806 while (step_freq && (step_freq - cur_freq)
807 <= drv_state.max_speed_delta_khz) {
808 acpu_freq_tbl[i].up[step_pll] =
809 &acpu_freq_tbl[step_idx];
810 step_idx++;
811 }
812 if (step_idx == (i + 1) && step_freq) {
813 pr_crit("Delta between freqs %u KHz and %u KHz is"
814 " too high!\n", cur_freq, step_freq);
815 BUG();
816 }
817
818 /* Calculate max "down" step for each destination PLL */
819 step_idx = i - 1;
820 while (step_idx >= 0 && (cur_freq - step_freq)
821 <= drv_state.max_speed_delta_khz) {
822 acpu_freq_tbl[i].down[step_pll] =
823 &acpu_freq_tbl[step_idx];
824 step_idx--;
825 }
826 if (step_idx == (i - 1) && i > 0) {
827 pr_crit("Delta between freqs %u KHz and %u KHz is"
828 " too high!\n", cur_freq, step_freq);
829 BUG();
830 }
831 }
832}
833
834static void __init print_acpu_freq_tbl(void)
835{
836 struct clkctl_acpu_speed *t;
837 short down_idx[ACPU_PLL_END];
838 short up_idx[ACPU_PLL_END];
839 int i, j;
840
841#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
842 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
843 "D0 D1 D2 D4 U0 U1 U2 U4\n");
844
845 t = &acpu_freq_tbl[0];
846 for (i = 0; t->a11clk_khz != 0; i++) {
847
848 for (j = 0; j < ACPU_PLL_END; j++) {
849 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
850 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
851 }
852
853 pr_info("%2d %7d %3d %3d %7d %4d %7d "
854 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
855 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
856 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
857 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
858 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
859
860 t++;
861 }
862}
863
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530865static struct acpuclk_data acpuclk_7627_data = {
866 .set_rate = acpuclk_7627_set_rate,
867 .get_rate = acpuclk_7627_get_rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700868 .power_collapse_khz = POWER_COLLAPSE_KHZ,
Matt Wagantallec57f062011-08-16 23:54:46 -0700869 .switch_time_us = 50,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700870};
871
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530872static int __init acpuclk_7627_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700873{
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700874 pr_info("%s()\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700875
876 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
877 BUG_ON(IS_ERR(drv_state.ebi1_clk));
878
879 mutex_init(&drv_state.lock);
Matt Wagantallec57f062011-08-16 23:54:46 -0700880 drv_state.max_speed_delta_khz = soc_data->max_speed_delta_khz;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530881 select_freq_plan();
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530882 acpuclk_7627_data.wait_for_irq_khz = find_wait_for_irq_khz();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700883 precompute_stepping();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700884 acpuclk_hw_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700885 print_acpu_freq_tbl();
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530886 acpuclk_register(&acpuclk_7627_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700887
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700888#ifdef CONFIG_CPU_FREQ_MSM
889 cpufreq_table_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700890#endif
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700891 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700892}
Matt Wagantallec57f062011-08-16 23:54:46 -0700893
Matt Wagantallec57f062011-08-16 23:54:46 -0700894struct acpuclk_soc_data acpuclk_7x27_soc_data __initdata = {
895 .max_speed_delta_khz = 400000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530896 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -0700897};
898
899struct acpuclk_soc_data acpuclk_7x27a_soc_data __initdata = {
900 .max_speed_delta_khz = 400000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530901 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -0700902};
903
904struct acpuclk_soc_data acpuclk_7x27aa_soc_data __initdata = {
905 .max_speed_delta_khz = 504000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530906 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -0700907};
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530908
909struct acpuclk_soc_data acpuclk_8625_soc_data __initdata = {
910 /* TODO: Need to update speed delta from H/w Team */
911 .max_speed_delta_khz = 604800,
912 .init = acpuclk_7627_init,
913};