blob: 23d03efe4090280ca99dd7b58e547b565f53e9ec [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>
30#include <linux/remote_spinlock.h>
31#include <mach/board.h>
32#include <mach/msm_iomap.h>
33#include <asm/mach-types.h>
34#include <mach/socinfo.h>
35
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036#include "smd_private.h"
37#include "acpuclock.h"
38
39#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
40#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
41#define A11S_VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124)
42#define PLLn_MODE(n) (MSM_CLK_CTL_BASE + 0x300 + 28 * (n))
43#define PLLn_L_VAL(n) (MSM_CLK_CTL_BASE + 0x304 + 28 * (n))
44
45#define PLL4_MODE (MSM_CLK_CTL_BASE + 0x374)
46#define PLL4_L_VAL (MSM_CLK_CTL_BASE + 0x378)
47
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070048#define POWER_COLLAPSE_KHZ 19200
49
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050/* Max CPU frequency allowed by hardware while in standby waiting for an irq. */
51#define MAX_WAIT_FOR_IRQ_KHZ 128000
52
53enum {
54 ACPU_PLL_TCXO = -1,
55 ACPU_PLL_0 = 0,
56 ACPU_PLL_1,
57 ACPU_PLL_2,
58 ACPU_PLL_3,
59 ACPU_PLL_4,
60 ACPU_PLL_END,
61};
62
63static const struct pll {
64 void __iomem *mod_reg;
65 const uint32_t l_val_mask;
66} soc_pll[ACPU_PLL_END] = {
67 [ACPU_PLL_0] = {PLLn_MODE(ACPU_PLL_0), 0x3f},
68 [ACPU_PLL_1] = {PLLn_MODE(ACPU_PLL_1), 0x3f},
69 [ACPU_PLL_2] = {PLLn_MODE(ACPU_PLL_2), 0x3f},
70 [ACPU_PLL_3] = {PLLn_MODE(ACPU_PLL_3), 0x3f},
71 [ACPU_PLL_4] = {PLL4_MODE, 0x3ff},
72};
73
74struct clock_state {
75 struct clkctl_acpu_speed *current_speed;
76 struct mutex lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070077 uint32_t max_speed_delta_khz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078 struct clk *ebi1_clk;
79};
80
81#define PLL_BASE 7
82
83struct shared_pll_control {
84 uint32_t version;
85 struct {
86 /* Denotes if the PLL is ON. Technically, this can be read
87 * directly from the PLL registers, but this feild is here,
88 * so let's use it.
89 */
90 uint32_t on;
91 /* One bit for each processor core. The application processor
92 * is allocated bit position 1. All other bits should be
93 * considered as votes from other processors.
94 */
95 uint32_t votes;
96 } pll[PLL_BASE + ACPU_PLL_END];
97};
98
99struct clkctl_acpu_speed {
100 unsigned int use_for_scaling;
101 unsigned int a11clk_khz;
102 int pll;
103 unsigned int a11clk_src_sel;
104 unsigned int a11clk_src_div;
105 unsigned int ahbclk_khz;
106 unsigned int ahbclk_div;
107 int vdd;
108 unsigned int axiclk_khz;
109 unsigned long lpj; /* loops_per_jiffy */
110 /* Pointers in acpu_freq_tbl[] for max up/down steppings. */
111 struct clkctl_acpu_speed *down[ACPU_PLL_END];
112 struct clkctl_acpu_speed *up[ACPU_PLL_END];
113};
114
115static remote_spinlock_t pll_lock;
116static struct shared_pll_control *pll_control;
117static struct clock_state drv_state = { 0 };
118static struct clkctl_acpu_speed *acpu_freq_tbl;
119
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700120/*
121 * ACPU freq tables used for different PLLs frequency combinations. The
122 * correct table is selected during init.
123 *
124 * Table stepping up/down entries are calculated during boot to choose the
125 * largest frequency jump that's less than max_speed_delta_khz on each PLL.
126 */
127
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530128/* 7627 with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = {
130 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
131 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
132 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
133 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
134 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530135 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
136 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
137 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
138 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
140};
141
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530142/* 7627 with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = {
144 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
145 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
146 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
147 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
148 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530149 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
150 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
151 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
152 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700153 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
154};
155
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530156/* 7627 with GSM capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700157static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = {
158 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
159 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
160 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
161 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 },
162 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530163 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
164 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
165 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
166 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
168};
169
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530170/* 7627 with CDMA capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = {
172 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
173 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
174 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
175 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
176 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530177 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
178 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
179 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
180 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
182};
183
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530184/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530186 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
187 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
188 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
189 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
190 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
191 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
192 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
193 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
194 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
195 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700196 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
197};
198
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530199/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530201 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
202 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
203 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
204 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Trilok Soniabb750b2011-07-13 16:47:18 +0530205 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
206 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
207 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
208 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530209 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
210 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
212};
213
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530214/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Sonif597e242011-06-06 12:37:16 +0530215static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = {
216 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
217 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
218 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
219 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
220 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
221 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
222 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
223 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
224 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
225 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
226 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
227};
228
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530229/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Sonid7b05e52011-08-17 18:09:08 +0530230static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008[] = {
231 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
232 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
233 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
234 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
235 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
236 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
237 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
238 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
239 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
240 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
241 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
242};
243
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530244/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530245static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_25a[] = {
Trilok Soni54d35c42011-07-14 17:47:50 +0530246 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
247 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
248 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
249 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
250 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
251 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530252 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530253 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
254 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
255 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
256};
257
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530258/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530259static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = {
260 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
261 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
262 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
263 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
264 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
265 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
266 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
267 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
268 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
269 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
270 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
271};
272
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530273/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530274static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = {
275 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
276 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
277 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
278 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
279 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
280 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
281 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
282 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
283 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
284 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
285 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
286};
287
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530288/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530289static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = {
290 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
291 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
292 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
293 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
294 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
295 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
296 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
297 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
298 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
299 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
300 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
301};
302
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530303/* 7x27aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530304static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = {
305 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
306 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
307 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
308 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
309 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
310 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
311 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
312 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
313 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
314 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
315 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
316};
317
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530318/* 7x25a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530319static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_25a[] = {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530320 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
321 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
322 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
323 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
324 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 },
325 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530326 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530327 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
328 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
329 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
330};
331
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700332#define PLL_0_MHZ 0
333#define PLL_196_MHZ 10
334#define PLL_245_MHZ 12
Trilok Soni9bb022c2011-10-31 18:25:19 +0530335#define PLL_589_MHZ 30
336#define PLL_737_MHZ 38
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700337#define PLL_800_MHZ 41
338#define PLL_960_MHZ 50
Trilok Sonif597e242011-06-06 12:37:16 +0530339#define PLL_1008_MHZ 52
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700340#define PLL_1200_MHZ 62
341
342#define PLL_CONFIG(m0, m1, m2, m4) { \
343 PLL_##m0##_MHZ, PLL_##m1##_MHZ, PLL_##m2##_MHZ, PLL_##m4##_MHZ, \
344 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
345}
346
347struct pll_freq_tbl_map {
348 unsigned int pll0_l;
349 unsigned int pll1_l;
350 unsigned int pll2_l;
351 unsigned int pll4_l;
352 struct clkctl_acpu_speed *tbl;
353};
354
355static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700356 PLL_CONFIG(960, 196, 1200, 0),
357 PLL_CONFIG(960, 245, 1200, 0),
358 PLL_CONFIG(960, 196, 800, 0),
359 PLL_CONFIG(960, 245, 800, 0),
360 PLL_CONFIG(960, 245, 1200, 800),
361 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530362 PLL_CONFIG(960, 245, 1200, 1008),
Trilok Sonid7b05e52011-08-17 18:09:08 +0530363 PLL_CONFIG(960, 196, 1200, 1008),
Trilok Soni9bb022c2011-10-31 18:25:19 +0530364 PLL_CONFIG(960, 737, 1200, 800),
365 PLL_CONFIG(960, 589, 1200, 800),
366 PLL_CONFIG(960, 737, 1200, 1008),
367 PLL_CONFIG(960, 589, 1200, 1008),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700368 { 0, 0, 0, 0, 0 }
369};
370
371#ifdef CONFIG_CPU_FREQ_MSM
372static struct cpufreq_frequency_table freq_table[20];
373
374static void __init cpufreq_table_init(void)
375{
376 unsigned int i;
377 unsigned int freq_cnt = 0;
378
379 /* Construct the freq_table table from acpu_freq_tbl since the
380 * freq_table values need to match frequencies specified in
381 * acpu_freq_tbl and acpu_freq_tbl needs to be fixed up 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[freq_cnt].index = freq_cnt;
387 freq_table[freq_cnt].frequency
388 = acpu_freq_tbl[i].a11clk_khz;
389 freq_cnt++;
390 }
391 }
392
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[freq_cnt].index = freq_cnt;
397 freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
398
399 pr_info("%d scaling frequencies supported.\n", freq_cnt);
400}
401#endif
402
403static void pll_enable(void __iomem *addr, unsigned on)
404{
405 if (on) {
406 writel_relaxed(2, addr);
407 mb();
408 udelay(5);
409 writel_relaxed(6, addr);
410 mb();
411 udelay(50);
412 writel_relaxed(7, addr);
413 } else {
414 writel_relaxed(0, addr);
415 }
416}
417
418static int pc_pll_request(unsigned id, unsigned on)
419{
420 int res = 0;
421 on = !!on;
422
423 if (on)
424 pr_debug("Enabling PLL %d\n", id);
425 else
426 pr_debug("Disabling PLL %d\n", id);
427
428 if (id >= ACPU_PLL_END)
429 return -EINVAL;
430
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530431 remote_spin_lock(&pll_lock);
432 if (on) {
433 pll_control->pll[PLL_BASE + id].votes |= 2;
434 if (!pll_control->pll[PLL_BASE + id].on) {
435 pll_enable(soc_pll[id].mod_reg, 1);
436 pll_control->pll[PLL_BASE + id].on = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700437 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700438 } else {
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530439 pll_control->pll[PLL_BASE + id].votes &= ~2;
440 if (pll_control->pll[PLL_BASE + id].on
441 && !pll_control->pll[PLL_BASE + id].votes) {
442 pll_enable(soc_pll[id].mod_reg, 0);
443 pll_control->pll[PLL_BASE + id].on = 0;
444 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700445 }
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530446 remote_spin_unlock(&pll_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700447
448 if (on)
449 pr_debug("PLL enabled\n");
450 else
451 pr_debug("PLL disabled\n");
452
453 return res;
454}
455
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700456static int acpuclk_set_vdd_level(int vdd)
457{
458 uint32_t current_vdd;
459
Pankaj Kumar9406a3b2011-12-23 18:07:15 +0530460 /*
461 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
462 * VDD switching support.
463 */
464 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
465 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
466 return 0;
467
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700468 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
469
470 pr_debug("Switching VDD from %u mV -> %d mV\n",
471 current_vdd, vdd);
472
473 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
474 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700475 udelay(62);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700476 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
477 pr_err("VDD set failed\n");
478 return -EIO;
479 }
480
481 pr_debug("VDD switched\n");
482
483 return 0;
484}
485
486/* Set proper dividers for the given clock speed. */
487static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
488{
489 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
490
491 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
492
493 /* AHB_CLK_DIV */
494 clk_div = (reg_clksel >> 1) & 0x03;
495 /* CLK_SEL_SRC1NO */
496 src_sel = reg_clksel & 1;
497
498 /*
499 * If the new clock divider is higher than the previous, then
500 * program the divider before switching the clock
501 */
502 if (hunt_s->ahbclk_div > clk_div) {
503 reg_clksel &= ~(0x3 << 1);
504 reg_clksel |= (hunt_s->ahbclk_div << 1);
505 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
506 }
507
508 /* Program clock source and divider */
509 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
510 reg_clkctl &= ~(0xFF << (8 * src_sel));
511 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
512 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
513 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
514
515 /* Program clock source selection */
516 reg_clksel ^= 1;
517 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
518
519 /*
520 * If the new clock divider is lower than the previous, then
521 * program the divider after switching the clock
522 */
523 if (hunt_s->ahbclk_div < clk_div) {
524 reg_clksel &= ~(0x3 << 1);
525 reg_clksel |= (hunt_s->ahbclk_div << 1);
526 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
527 }
528}
529
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530530static int acpuclk_7627_set_rate(int cpu, unsigned long rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700531 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700532{
533 uint32_t reg_clkctl;
534 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
535 int res, rc = 0;
536 unsigned int plls_enabled = 0, pll;
537
538 if (reason == SETRATE_CPUFREQ)
539 mutex_lock(&drv_state.lock);
540
541 strt_s = cur_s = drv_state.current_speed;
542
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700543 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700544 if (cur_s == NULL) {
545 rc = -ENOENT;
546 goto out;
547 }
548
549 if (rate == cur_s->a11clk_khz)
550 goto out;
551
552 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
553 if (tgt_s->a11clk_khz == rate)
554 break;
555 }
556
557 if (tgt_s->a11clk_khz == 0) {
558 rc = -EINVAL;
559 goto out;
560 }
561
562 /* Choose the highest speed at or below 'rate' with same PLL. */
563 if (reason != SETRATE_CPUFREQ
564 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
565 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
566 tgt_s--;
567 }
568
569 if (strt_s->pll != ACPU_PLL_TCXO)
570 plls_enabled |= 1 << strt_s->pll;
571
572 if (reason == SETRATE_CPUFREQ) {
573 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
574 rc = pc_pll_request(tgt_s->pll, 1);
575 if (rc < 0) {
576 pr_err("PLL%d enable failed (%d)\n",
577 tgt_s->pll, rc);
578 goto out;
579 }
580 plls_enabled |= 1 << tgt_s->pll;
581 }
582 }
583 /* Need to do this when coming out of power collapse since some modem
584 * firmwares reset the VDD when the application processor enters power
585 * collapse. */
586 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
587 /* Increase VDD if needed. */
588 if (tgt_s->vdd > cur_s->vdd) {
589 rc = acpuclk_set_vdd_level(tgt_s->vdd);
590 if (rc < 0) {
591 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
592 goto out;
593 }
594 }
595 }
596
597 /* Set wait states for CPU inbetween frequency changes */
598 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
599 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
600 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
601
602 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
603 strt_s->a11clk_khz, tgt_s->a11clk_khz);
604
605 while (cur_s != tgt_s) {
606 /*
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530607 * Always jump to target freq if within max_speed_delta_khz,
608 * regardless of PLL. If differnece is greater, use the
609 * predefined steppings in the table.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700610 */
611 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
612 if (d > drv_state.max_speed_delta_khz) {
613
614 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
615 /* Step up: jump to target PLL as early as
616 * possible so indexing using TCXO (up[-1])
617 * never occurs. */
618 if (likely(cur_s->up[tgt_s->pll]))
619 cur_s = cur_s->up[tgt_s->pll];
620 else
621 cur_s = cur_s->up[cur_s->pll];
622 } else {
623 /* Step down: stay on current PLL as long as
624 * possible so indexing using TCXO (down[-1])
625 * never occurs. */
626 if (likely(cur_s->down[cur_s->pll]))
627 cur_s = cur_s->down[cur_s->pll];
628 else
629 cur_s = cur_s->down[tgt_s->pll];
630 }
631
632 if (cur_s == NULL) { /* This should not happen. */
633 pr_err("No stepping frequencies found. "
634 "strt_s:%u tgt_s:%u\n",
635 strt_s->a11clk_khz, tgt_s->a11clk_khz);
636 rc = -EINVAL;
637 goto out;
638 }
639
640 } else {
641 cur_s = tgt_s;
642 }
643
644 pr_debug("STEP khz = %u, pll = %d\n",
645 cur_s->a11clk_khz, cur_s->pll);
646
647 if (cur_s->pll != ACPU_PLL_TCXO
648 && !(plls_enabled & (1 << cur_s->pll))) {
649 rc = pc_pll_request(cur_s->pll, 1);
650 if (rc < 0) {
651 pr_err("PLL%d enable failed (%d)\n",
652 cur_s->pll, rc);
653 goto out;
654 }
655 plls_enabled |= 1 << cur_s->pll;
656 }
657
658 acpuclk_set_div(cur_s);
659 drv_state.current_speed = cur_s;
660 /* Re-adjust lpj for the new clock speed. */
661 loops_per_jiffy = cur_s->lpj;
662 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700663 udelay(50);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700664 }
665
666 /* Nothing else to do for SWFI. */
667 if (reason == SETRATE_SWFI)
668 goto out;
669
670 /* Change the AXI bus frequency if we can. */
671 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
672 res = clk_set_rate(drv_state.ebi1_clk,
673 tgt_s->axiclk_khz * 1000);
674 if (res < 0)
675 pr_warning("Setting AXI min rate failed (%d)\n", res);
676 }
677
678 /* Disable PLLs we are not using anymore. */
679 if (tgt_s->pll != ACPU_PLL_TCXO)
680 plls_enabled &= ~(1 << tgt_s->pll);
681 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
682 if (plls_enabled & (1 << pll)) {
683 res = pc_pll_request(pll, 0);
684 if (res < 0)
685 pr_warning("PLL%d disable failed (%d)\n",
686 pll, res);
687 }
688
689 /* Nothing else to do for power collapse. */
690 if (reason == SETRATE_PC)
691 goto out;
692
693 /* Drop VDD level if we can. */
694 if (tgt_s->vdd < strt_s->vdd) {
695 res = acpuclk_set_vdd_level(tgt_s->vdd);
696 if (res < 0)
697 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
698 }
699
700 pr_debug("ACPU speed change complete\n");
701out:
702 if (reason == SETRATE_CPUFREQ)
703 mutex_unlock(&drv_state.lock);
704 return rc;
705}
706
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700707static void __init acpuclk_hw_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708{
709 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530710 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700711 int res;
712
713 /*
714 * Determine the rate of ACPU clock
715 */
716
717 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
718 /* CLK_SRC0_SEL */
719 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
720 /* CLK_SRC0_DIV */
721 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
722 } else {
723 /* CLK_SRC1_SEL */
724 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
725 /* CLK_SRC1_DIV */
726 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
727 }
728
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700729 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
730 if (speed->a11clk_src_sel == sel
731 && (speed->a11clk_src_div == div))
732 break;
733 }
734 if (speed->a11clk_khz == 0) {
735 pr_err("Error - ACPU clock reports invalid speed\n");
736 return;
737 }
738
739 drv_state.current_speed = speed;
740 if (speed->pll != ACPU_PLL_TCXO)
741 if (pc_pll_request(speed->pll, 1))
742 pr_warning("Failed to vote for boot PLL\n");
743
Trilok Soni7d6c8652011-07-14 15:35:07 +0530744 /* Fix div2 to 2 for 7x27/5a(aa) targets */
745 if (!cpu_is_msm7x27()) {
746 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
747 reg_clksel &= ~(0x3 << 14);
748 reg_clksel |= (0x1 << 14);
749 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
750 }
751
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700752 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
753 if (res < 0)
754 pr_warning("Setting AXI min rate failed (%d)\n", res);
755 res = clk_enable(drv_state.ebi1_clk);
756 if (res < 0)
757 pr_warning("Enabling AXI clock failed (%d)\n", res);
758
759 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
760}
761
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530762static unsigned long acpuclk_7627_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700763{
764 WARN_ONCE(drv_state.current_speed == NULL,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700765 "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700766 if (drv_state.current_speed)
767 return drv_state.current_speed->a11clk_khz;
768 else
769 return 0;
770}
771
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700772/*----------------------------------------------------------------------------
773 * Clock driver initialization
774 *---------------------------------------------------------------------------*/
775
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700776static void __init acpu_freq_tbl_fixup(void)
777{
778 unsigned long pll0_l, pll1_l, pll2_l, pll4_l;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 struct pll_freq_tbl_map *lst;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700780
781 /* Wait for the PLLs to be initialized and then read their frequency.
782 */
783 do {
784 pll0_l = readl_relaxed(PLLn_L_VAL(0)) &
785 soc_pll[ACPU_PLL_0].l_val_mask;
786 cpu_relax();
787 udelay(50);
788 } while (pll0_l == 0);
789 do {
790 pll1_l = readl_relaxed(PLLn_L_VAL(1)) &
791 soc_pll[ACPU_PLL_1].l_val_mask;
792 cpu_relax();
793 udelay(50);
794 } while (pll1_l == 0);
795 do {
796 pll2_l = readl_relaxed(PLLn_L_VAL(2)) &
797 soc_pll[ACPU_PLL_2].l_val_mask;
798 cpu_relax();
799 udelay(50);
800 } while (pll2_l == 0);
801
802 pr_info("L val: PLL0: %d, PLL1: %d, PLL2: %d\n",
803 (int)pll0_l, (int)pll1_l, (int)pll2_l);
804
805 if (!cpu_is_msm7x27() && !cpu_is_msm7x25a()) {
806 do {
807 pll4_l = readl_relaxed(PLL4_L_VAL) &
808 soc_pll[ACPU_PLL_4].l_val_mask;
809 cpu_relax();
810 udelay(50);
811 } while (pll4_l == 0);
812 pr_info("L val: PLL4: %d\n", (int)pll4_l);
813 } else {
814 pll4_l = 0;
815 }
816
Trilok Soni54d35c42011-07-14 17:47:50 +0530817 /* Fix the tables for 7x25a variant to not conflict with 7x27 ones */
818 if (cpu_is_msm7x25a()) {
819 if (pll1_l == PLL_245_MHZ) {
820 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530821 pll0_960_pll1_245_pll2_1200_25a;
Trilok Soni9bb022c2011-10-31 18:25:19 +0530822 } else if (pll1_l == PLL_737_MHZ) {
823 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530824 pll0_960_pll1_737_pll2_1200_25a;
Trilok Soni54d35c42011-07-14 17:47:50 +0530825 }
826 } else {
827 /* Select the right table to use. */
828 for (lst = acpu_freq_tbl_list; lst->tbl != 0; lst++) {
829 if (lst->pll0_l == pll0_l && lst->pll1_l == pll1_l
830 && lst->pll2_l == pll2_l
831 && lst->pll4_l == pll4_l) {
832 acpu_freq_tbl = lst->tbl;
833 break;
834 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700835 }
836 }
837
838 if (acpu_freq_tbl == NULL) {
839 pr_crit("Unknown PLL configuration!\n");
840 BUG();
841 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700842}
843
844/*
845 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
846 * before entering a wait for irq low-power mode. Find a suitable rate.
847 */
848static unsigned long __init find_wait_for_irq_khz(void)
849{
850 unsigned long found_khz = 0;
851 int i;
852
853 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
854 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
855 found_khz = acpu_freq_tbl[i].a11clk_khz;
856
857 return found_khz;
858}
859
860/* Initalize the lpj field in the acpu_freq_tbl. */
861static void __init lpj_init(void)
862{
863 int i;
864 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
865 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
866 acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy,
867 base_clk->a11clk_khz,
868 acpu_freq_tbl[i].a11clk_khz);
869 }
870}
871
872static void __init precompute_stepping(void)
873{
874 int i, step_idx;
875
876#define cur_freq acpu_freq_tbl[i].a11clk_khz
877#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
878#define cur_pll acpu_freq_tbl[i].pll
879#define step_pll acpu_freq_tbl[step_idx].pll
880
881 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
882
883 /* Calculate max "up" step for each destination PLL */
884 step_idx = i + 1;
885 while (step_freq && (step_freq - cur_freq)
886 <= drv_state.max_speed_delta_khz) {
887 acpu_freq_tbl[i].up[step_pll] =
888 &acpu_freq_tbl[step_idx];
889 step_idx++;
890 }
891 if (step_idx == (i + 1) && step_freq) {
892 pr_crit("Delta between freqs %u KHz and %u KHz is"
893 " too high!\n", cur_freq, step_freq);
894 BUG();
895 }
896
897 /* Calculate max "down" step for each destination PLL */
898 step_idx = i - 1;
899 while (step_idx >= 0 && (cur_freq - step_freq)
900 <= drv_state.max_speed_delta_khz) {
901 acpu_freq_tbl[i].down[step_pll] =
902 &acpu_freq_tbl[step_idx];
903 step_idx--;
904 }
905 if (step_idx == (i - 1) && i > 0) {
906 pr_crit("Delta between freqs %u KHz and %u KHz is"
907 " too high!\n", cur_freq, step_freq);
908 BUG();
909 }
910 }
911}
912
913static void __init print_acpu_freq_tbl(void)
914{
915 struct clkctl_acpu_speed *t;
916 short down_idx[ACPU_PLL_END];
917 short up_idx[ACPU_PLL_END];
918 int i, j;
919
920#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
921 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
922 "D0 D1 D2 D4 U0 U1 U2 U4\n");
923
924 t = &acpu_freq_tbl[0];
925 for (i = 0; t->a11clk_khz != 0; i++) {
926
927 for (j = 0; j < ACPU_PLL_END; j++) {
928 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
929 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
930 }
931
932 pr_info("%2d %7d %3d %3d %7d %4d %7d "
933 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
934 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
935 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
936 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
937 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
938
939 t++;
940 }
941}
942
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700943static void shared_pll_control_init(void)
944{
945#define PLL_REMOTE_SPINLOCK_ID "S:7"
946 unsigned smem_size;
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530947
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700948 remote_spin_lock_init(&pll_lock, PLL_REMOTE_SPINLOCK_ID);
949 pll_control = smem_get_entry(SMEM_CLKREGIM_SOURCES, &smem_size);
950
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530951 if (!pll_control) {
952 pr_err("Can't find shared PLL control data structure!\n");
953 BUG();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700954 /* There might be more PLLs than what the application processor knows
955 * about. But the index used for each PLL is guaranteed to remain the
956 * same. */
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530957 } else if (smem_size < sizeof(struct shared_pll_control)) {
958 pr_err("Shared PLL control data"
959 "structure too small!\n");
960 BUG();
961 } else if (pll_control->version != 0xCCEE0001) {
962 pr_err("Shared PLL control version mismatch!\n");
963 BUG();
964 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700965 pr_info("Shared PLL control available.\n");
966 return;
967 }
968
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969}
970
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530971static struct acpuclk_data acpuclk_7627_data = {
972 .set_rate = acpuclk_7627_set_rate,
973 .get_rate = acpuclk_7627_get_rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700974 .power_collapse_khz = POWER_COLLAPSE_KHZ,
Matt Wagantallec57f062011-08-16 23:54:46 -0700975 .switch_time_us = 50,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700976};
977
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530978static int __init acpuclk_7627_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700979{
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700980 pr_info("%s()\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700981
982 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
983 BUG_ON(IS_ERR(drv_state.ebi1_clk));
984
985 mutex_init(&drv_state.lock);
986 shared_pll_control_init();
Matt Wagantallec57f062011-08-16 23:54:46 -0700987 drv_state.max_speed_delta_khz = soc_data->max_speed_delta_khz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988 acpu_freq_tbl_fixup();
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530989 acpuclk_7627_data.wait_for_irq_khz = find_wait_for_irq_khz();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700990 precompute_stepping();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700991 acpuclk_hw_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700992 lpj_init();
993 print_acpu_freq_tbl();
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530994 acpuclk_register(&acpuclk_7627_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700995
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700996#ifdef CONFIG_CPU_FREQ_MSM
997 cpufreq_table_init();
998 cpufreq_frequency_table_get_attr(freq_table, smp_processor_id());
999#endif
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001000 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001001}
Matt Wagantallec57f062011-08-16 23:54:46 -07001002
Matt Wagantallec57f062011-08-16 23:54:46 -07001003struct acpuclk_soc_data acpuclk_7x27_soc_data __initdata = {
1004 .max_speed_delta_khz = 400000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301005 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -07001006};
1007
1008struct acpuclk_soc_data acpuclk_7x27a_soc_data __initdata = {
1009 .max_speed_delta_khz = 400000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301010 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -07001011};
1012
1013struct acpuclk_soc_data acpuclk_7x27aa_soc_data __initdata = {
1014 .max_speed_delta_khz = 504000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301015 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -07001016};