blob: c4409ff61f3bb7d03cea9289f23ffd21a6c719ff [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 {
52 ACPU_PLL_TCXO = -1,
53 ACPU_PLL_0 = 0,
54 ACPU_PLL_1,
55 ACPU_PLL_2,
56 ACPU_PLL_3,
57 ACPU_PLL_4,
58 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;
90 unsigned long lpj; /* loops_per_jiffy */
91 /* Pointers in acpu_freq_tbl[] for max up/down steppings. */
92 struct clkctl_acpu_speed *down[ACPU_PLL_END];
93 struct clkctl_acpu_speed *up[ACPU_PLL_END];
94};
95
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096static struct clock_state drv_state = { 0 };
97static struct clkctl_acpu_speed *acpu_freq_tbl;
98
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099/*
100 * ACPU freq tables used for different PLLs frequency combinations. The
101 * correct table is selected during init.
102 *
103 * Table stepping up/down entries are calculated during boot to choose the
104 * largest frequency jump that's less than max_speed_delta_khz on each PLL.
105 */
106
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530107/* 7627 with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = {
109 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
110 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
111 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
112 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
113 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530114 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
115 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
116 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
117 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
119};
120
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530121/* 7627 with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700122static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = {
123 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
124 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
125 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
126 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
127 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530128 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
129 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
130 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
131 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
133};
134
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530135/* 7627 with GSM capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700136static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = {
137 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
138 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
139 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
140 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 },
141 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530142 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
143 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
144 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
145 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
147};
148
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530149/* 7627 with CDMA capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = {
151 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
152 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
153 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
154 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
155 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530156 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
157 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
158 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
159 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
161};
162
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530163/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530165 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
166 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
167 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
168 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530169 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530170 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
171 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
172 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
173 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
174 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
176};
177
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530178/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530180 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
181 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
182 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
183 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Trilok Soniabb750b2011-07-13 16:47:18 +0530184 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
185 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
186 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
187 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530188 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
189 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
191};
192
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530193/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Sonif597e242011-06-06 12:37:16 +0530194static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = {
195 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
196 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
197 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
198 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530199 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonif597e242011-06-06 12:37:16 +0530200 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
201 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
202 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
203 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
204 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
205 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
206};
207
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530208/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Sonid7b05e52011-08-17 18:09:08 +0530209static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008[] = {
210 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
211 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
212 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
213 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530214 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530215 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
216 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
217 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
218 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
219 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
220 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
221};
222
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530223/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530224static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_25a[] = {
Trilok Soni54d35c42011-07-14 17:47:50 +0530225 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
226 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
227 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
228 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530229 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530230 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530231 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530232 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
233 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
234 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
235};
236
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530237/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530238static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = {
239 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
240 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
241 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
242 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530243 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530244 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
245 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
246 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
247 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
248 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
249 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
250};
251
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530252/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530253static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = {
254 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
255 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
256 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
257 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
258 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
259 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
260 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
261 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
262 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
263 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
264 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
265};
266
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530267/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530268static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = {
269 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
270 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
271 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
272 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530273 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530274 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
275 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
276 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
277 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
278 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
279 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
280};
281
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530282/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530283static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = {
284 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
285 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
286 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
287 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530288 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530289 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
290 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
291 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 },
292 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
293 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
294 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
295};
296
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530297/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530298static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_25a[] = {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530299 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
300 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
301 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
302 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530303 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530304 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530305 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530306 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
307 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
308 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} }
309};
310
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700311#define PLL_CONFIG(m0, m1, m2, m4) { \
Pankaj Kumar3912c982011-12-07 16:59:03 +0530312 m0, m1, m2, m4, \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700313 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
314}
315
316struct pll_freq_tbl_map {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530317 unsigned int pll0_rate;
318 unsigned int pll1_rate;
319 unsigned int pll2_rate;
320 unsigned int pll4_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700321 struct clkctl_acpu_speed *tbl;
322};
323
324static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700325 PLL_CONFIG(960, 196, 1200, 0),
326 PLL_CONFIG(960, 245, 1200, 0),
327 PLL_CONFIG(960, 196, 800, 0),
328 PLL_CONFIG(960, 245, 800, 0),
329 PLL_CONFIG(960, 245, 1200, 800),
330 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530331 PLL_CONFIG(960, 245, 1200, 1008),
Trilok Sonid7b05e52011-08-17 18:09:08 +0530332 PLL_CONFIG(960, 196, 1200, 1008),
Trilok Soni9bb022c2011-10-31 18:25:19 +0530333 PLL_CONFIG(960, 737, 1200, 800),
334 PLL_CONFIG(960, 589, 1200, 800),
335 PLL_CONFIG(960, 737, 1200, 1008),
336 PLL_CONFIG(960, 589, 1200, 1008),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700337 { 0, 0, 0, 0, 0 }
338};
339
340#ifdef CONFIG_CPU_FREQ_MSM
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530341static struct cpufreq_frequency_table freq_table[NR_CPUS][20];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700342
343static void __init cpufreq_table_init(void)
344{
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530345 int cpu;
346 for_each_possible_cpu(cpu) {
347 unsigned int i, freq_cnt = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700348
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530349 /* Construct the freq_table table from acpu_freq_tbl since
350 * the freq_table values need to match frequencies specified
351 * in acpu_freq_tbl and acpu_freq_tbl needs to be fixed up
352 * during init.
353 */
354 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
355 && freq_cnt < ARRAY_SIZE(*freq_table)-1; i++) {
356 if (acpu_freq_tbl[i].use_for_scaling) {
357 freq_table[cpu][freq_cnt].index = freq_cnt;
358 freq_table[cpu][freq_cnt].frequency
359 = acpu_freq_tbl[i].a11clk_khz;
360 freq_cnt++;
361 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700362 }
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530363
364 /* freq_table not big enough to store all usable freqs. */
365 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
366
367 freq_table[cpu][freq_cnt].index = freq_cnt;
368 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
369 /* Register table with CPUFreq. */
370 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
371 pr_info("CPU%d: %d scaling frequencies supported.\n",
372 cpu, freq_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700373 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700374}
375#endif
376
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700377static int acpuclk_set_vdd_level(int vdd)
378{
379 uint32_t current_vdd;
380
Pankaj Kumar9406a3b2011-12-23 18:07:15 +0530381 /*
382 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
383 * VDD switching support.
384 */
385 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
386 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
387 return 0;
388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700389 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
390
391 pr_debug("Switching VDD from %u mV -> %d mV\n",
392 current_vdd, vdd);
393
394 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
395 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700396 udelay(62);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700397 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
398 pr_err("VDD set failed\n");
399 return -EIO;
400 }
401
402 pr_debug("VDD switched\n");
403
404 return 0;
405}
406
407/* Set proper dividers for the given clock speed. */
408static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
409{
410 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
411
412 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
413
414 /* AHB_CLK_DIV */
415 clk_div = (reg_clksel >> 1) & 0x03;
416 /* CLK_SEL_SRC1NO */
417 src_sel = reg_clksel & 1;
418
419 /*
420 * If the new clock divider is higher than the previous, then
421 * program the divider before switching the clock
422 */
423 if (hunt_s->ahbclk_div > clk_div) {
424 reg_clksel &= ~(0x3 << 1);
425 reg_clksel |= (hunt_s->ahbclk_div << 1);
426 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
427 }
428
429 /* Program clock source and divider */
430 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
431 reg_clkctl &= ~(0xFF << (8 * src_sel));
432 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
433 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
434 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
435
436 /* Program clock source selection */
437 reg_clksel ^= 1;
438 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
439
440 /*
441 * If the new clock divider is lower than the previous, then
442 * program the divider after switching the clock
443 */
444 if (hunt_s->ahbclk_div < clk_div) {
445 reg_clksel &= ~(0x3 << 1);
446 reg_clksel |= (hunt_s->ahbclk_div << 1);
447 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
448 }
449}
450
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530451static int acpuclk_7627_set_rate(int cpu, unsigned long rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700452 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700453{
454 uint32_t reg_clkctl;
455 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
456 int res, rc = 0;
457 unsigned int plls_enabled = 0, pll;
458
459 if (reason == SETRATE_CPUFREQ)
460 mutex_lock(&drv_state.lock);
461
462 strt_s = cur_s = drv_state.current_speed;
463
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700464 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700465 if (cur_s == NULL) {
466 rc = -ENOENT;
467 goto out;
468 }
469
470 if (rate == cur_s->a11clk_khz)
471 goto out;
472
473 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
474 if (tgt_s->a11clk_khz == rate)
475 break;
476 }
477
478 if (tgt_s->a11clk_khz == 0) {
479 rc = -EINVAL;
480 goto out;
481 }
482
483 /* Choose the highest speed at or below 'rate' with same PLL. */
484 if (reason != SETRATE_CPUFREQ
485 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
486 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
487 tgt_s--;
488 }
489
490 if (strt_s->pll != ACPU_PLL_TCXO)
491 plls_enabled |= 1 << strt_s->pll;
492
493 if (reason == SETRATE_CPUFREQ) {
494 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530495 rc = clk_prepare_enable(pll_clk[tgt_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700496 if (rc < 0) {
497 pr_err("PLL%d enable failed (%d)\n",
498 tgt_s->pll, rc);
499 goto out;
500 }
501 plls_enabled |= 1 << tgt_s->pll;
502 }
503 }
504 /* Need to do this when coming out of power collapse since some modem
505 * firmwares reset the VDD when the application processor enters power
506 * collapse. */
507 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
508 /* Increase VDD if needed. */
509 if (tgt_s->vdd > cur_s->vdd) {
510 rc = acpuclk_set_vdd_level(tgt_s->vdd);
511 if (rc < 0) {
512 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
513 goto out;
514 }
515 }
516 }
517
518 /* Set wait states for CPU inbetween frequency changes */
519 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
520 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
521 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
522
523 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
524 strt_s->a11clk_khz, tgt_s->a11clk_khz);
525
526 while (cur_s != tgt_s) {
527 /*
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530528 * Always jump to target freq if within max_speed_delta_khz,
529 * regardless of PLL. If differnece is greater, use the
530 * predefined steppings in the table.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700531 */
532 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
533 if (d > drv_state.max_speed_delta_khz) {
534
535 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
536 /* Step up: jump to target PLL as early as
537 * possible so indexing using TCXO (up[-1])
538 * never occurs. */
539 if (likely(cur_s->up[tgt_s->pll]))
540 cur_s = cur_s->up[tgt_s->pll];
541 else
542 cur_s = cur_s->up[cur_s->pll];
543 } else {
544 /* Step down: stay on current PLL as long as
545 * possible so indexing using TCXO (down[-1])
546 * never occurs. */
547 if (likely(cur_s->down[cur_s->pll]))
548 cur_s = cur_s->down[cur_s->pll];
549 else
550 cur_s = cur_s->down[tgt_s->pll];
551 }
552
553 if (cur_s == NULL) { /* This should not happen. */
554 pr_err("No stepping frequencies found. "
555 "strt_s:%u tgt_s:%u\n",
556 strt_s->a11clk_khz, tgt_s->a11clk_khz);
557 rc = -EINVAL;
558 goto out;
559 }
560
561 } else {
562 cur_s = tgt_s;
563 }
564
565 pr_debug("STEP khz = %u, pll = %d\n",
566 cur_s->a11clk_khz, cur_s->pll);
567
568 if (cur_s->pll != ACPU_PLL_TCXO
569 && !(plls_enabled & (1 << cur_s->pll))) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530570 rc = clk_prepare_enable(pll_clk[cur_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700571 if (rc < 0) {
572 pr_err("PLL%d enable failed (%d)\n",
573 cur_s->pll, rc);
574 goto out;
575 }
576 plls_enabled |= 1 << cur_s->pll;
577 }
578
579 acpuclk_set_div(cur_s);
580 drv_state.current_speed = cur_s;
581 /* Re-adjust lpj for the new clock speed. */
582 loops_per_jiffy = cur_s->lpj;
583 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700584 udelay(50);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700585 }
586
587 /* Nothing else to do for SWFI. */
588 if (reason == SETRATE_SWFI)
589 goto out;
590
591 /* Change the AXI bus frequency if we can. */
592 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
593 res = clk_set_rate(drv_state.ebi1_clk,
594 tgt_s->axiclk_khz * 1000);
595 if (res < 0)
596 pr_warning("Setting AXI min rate failed (%d)\n", res);
597 }
598
599 /* Disable PLLs we are not using anymore. */
600 if (tgt_s->pll != ACPU_PLL_TCXO)
601 plls_enabled &= ~(1 << tgt_s->pll);
602 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
Pankaj Kumar3912c982011-12-07 16:59:03 +0530603 if (plls_enabled & (1 << pll))
604 clk_disable_unprepare(pll_clk[pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700605
606 /* Nothing else to do for power collapse. */
607 if (reason == SETRATE_PC)
608 goto out;
609
610 /* Drop VDD level if we can. */
611 if (tgt_s->vdd < strt_s->vdd) {
612 res = acpuclk_set_vdd_level(tgt_s->vdd);
613 if (res < 0)
614 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
615 }
616
617 pr_debug("ACPU speed change complete\n");
618out:
619 if (reason == SETRATE_CPUFREQ)
620 mutex_unlock(&drv_state.lock);
621 return rc;
622}
623
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700624static void __init acpuclk_hw_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700625{
626 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530627 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700628 int res;
629
630 /*
631 * Determine the rate of ACPU clock
632 */
633
634 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
635 /* CLK_SRC0_SEL */
636 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
637 /* CLK_SRC0_DIV */
638 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
639 } else {
640 /* CLK_SRC1_SEL */
641 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
642 /* CLK_SRC1_DIV */
643 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
644 }
645
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700646 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
647 if (speed->a11clk_src_sel == sel
648 && (speed->a11clk_src_div == div))
649 break;
650 }
651 if (speed->a11clk_khz == 0) {
652 pr_err("Error - ACPU clock reports invalid speed\n");
653 return;
654 }
655
656 drv_state.current_speed = speed;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530657 if (speed->pll != ACPU_PLL_TCXO) {
658 if (clk_prepare_enable(pll_clk[speed->pll].clk))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700659 pr_warning("Failed to vote for boot PLL\n");
Pankaj Kumar3912c982011-12-07 16:59:03 +0530660 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700661
Trilok Soni7d6c8652011-07-14 15:35:07 +0530662 /* Fix div2 to 2 for 7x27/5a(aa) targets */
663 if (!cpu_is_msm7x27()) {
664 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
665 reg_clksel &= ~(0x3 << 14);
666 reg_clksel |= (0x1 << 14);
667 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
668 }
669
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700670 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
671 if (res < 0)
672 pr_warning("Setting AXI min rate failed (%d)\n", res);
Pankaj Kumar19095912012-01-11 18:09:13 +0530673 res = clk_prepare_enable(drv_state.ebi1_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700674 if (res < 0)
675 pr_warning("Enabling AXI clock failed (%d)\n", res);
676
677 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
678}
679
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530680static unsigned long acpuclk_7627_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700681{
682 WARN_ONCE(drv_state.current_speed == NULL,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700683 "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700684 if (drv_state.current_speed)
685 return drv_state.current_speed->a11clk_khz;
686 else
687 return 0;
688}
689
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690/*----------------------------------------------------------------------------
691 * Clock driver initialization
692 *---------------------------------------------------------------------------*/
Pankaj Kumar3912c982011-12-07 16:59:03 +0530693#define MHZ 1000000
694static void __init select_freq_plan(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700695{
Pankaj Kumar3912c982011-12-07 16:59:03 +0530696 unsigned long pll_mhz[ACPU_PLL_END];
697 struct pll_freq_tbl_map *t;
698 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700699
Pankaj Kumar3912c982011-12-07 16:59:03 +0530700 /* Get PLL clocks */
701 for (i = 0; i < ACPU_PLL_END; i++) {
702 if (pll_clk[i].name) {
703 pll_clk[i].clk = clk_get_sys("acpu", pll_clk[i].name);
704 if (IS_ERR(pll_clk[i].clk)) {
705 pll_mhz[i] = 0;
706 continue;
707 }
708 /* Get PLL's Rate */
709 pll_mhz[i] = clk_get_rate(pll_clk[i].clk)/MHZ;
710 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700711 }
712
Pankaj Kumar3912c982011-12-07 16:59:03 +0530713 /*
714 * For the pll configuration used in acpuclock table e.g.
715 * pll0_960_pll1_245_pll2_1200" is same for 7627 and
716 * 7625a (as pll0,pll1,pll2) having same rates, but frequency
717 * table is different for both targets.
718 *
719 * Hence below for loop will not be able to select correct
720 * table based on PLL rates as rates are same. Hence we need
721 * to add this cpu check for selecting the correct acpuclock table.
722 */
Trilok Soni54d35c42011-07-14 17:47:50 +0530723 if (cpu_is_msm7x25a()) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530724 if (pll_mhz[ACPU_PLL_1] == 245) {
Trilok Soni54d35c42011-07-14 17:47:50 +0530725 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530726 pll0_960_pll1_245_pll2_1200_25a;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530727 } else if (pll_mhz[ACPU_PLL_1] == 737) {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530728 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530729 pll0_960_pll1_737_pll2_1200_25a;
Trilok Soni54d35c42011-07-14 17:47:50 +0530730 }
731 } else {
732 /* Select the right table to use. */
Pankaj Kumar3912c982011-12-07 16:59:03 +0530733 for (t = acpu_freq_tbl_list; t->tbl != 0; t++) {
734 if (t->pll0_rate == pll_mhz[ACPU_PLL_0]
735 && t->pll1_rate == pll_mhz[ACPU_PLL_1]
736 && t->pll2_rate == pll_mhz[ACPU_PLL_2]
737 && t->pll4_rate == pll_mhz[ACPU_PLL_4]) {
738 acpu_freq_tbl = t->tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +0530739 break;
740 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700741 }
742 }
743
744 if (acpu_freq_tbl == NULL) {
745 pr_crit("Unknown PLL configuration!\n");
746 BUG();
747 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700748}
749
750/*
751 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
752 * before entering a wait for irq low-power mode. Find a suitable rate.
753 */
754static unsigned long __init find_wait_for_irq_khz(void)
755{
756 unsigned long found_khz = 0;
757 int i;
758
759 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
760 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
761 found_khz = acpu_freq_tbl[i].a11clk_khz;
762
763 return found_khz;
764}
765
766/* Initalize the lpj field in the acpu_freq_tbl. */
767static void __init lpj_init(void)
768{
769 int i;
770 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
771 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
772 acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy,
773 base_clk->a11clk_khz,
774 acpu_freq_tbl[i].a11clk_khz);
775 }
776}
777
778static void __init precompute_stepping(void)
779{
780 int i, step_idx;
781
782#define cur_freq acpu_freq_tbl[i].a11clk_khz
783#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
784#define cur_pll acpu_freq_tbl[i].pll
785#define step_pll acpu_freq_tbl[step_idx].pll
786
787 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
788
789 /* Calculate max "up" step for each destination PLL */
790 step_idx = i + 1;
791 while (step_freq && (step_freq - cur_freq)
792 <= drv_state.max_speed_delta_khz) {
793 acpu_freq_tbl[i].up[step_pll] =
794 &acpu_freq_tbl[step_idx];
795 step_idx++;
796 }
797 if (step_idx == (i + 1) && step_freq) {
798 pr_crit("Delta between freqs %u KHz and %u KHz is"
799 " too high!\n", cur_freq, step_freq);
800 BUG();
801 }
802
803 /* Calculate max "down" step for each destination PLL */
804 step_idx = i - 1;
805 while (step_idx >= 0 && (cur_freq - step_freq)
806 <= drv_state.max_speed_delta_khz) {
807 acpu_freq_tbl[i].down[step_pll] =
808 &acpu_freq_tbl[step_idx];
809 step_idx--;
810 }
811 if (step_idx == (i - 1) && i > 0) {
812 pr_crit("Delta between freqs %u KHz and %u KHz is"
813 " too high!\n", cur_freq, step_freq);
814 BUG();
815 }
816 }
817}
818
819static void __init print_acpu_freq_tbl(void)
820{
821 struct clkctl_acpu_speed *t;
822 short down_idx[ACPU_PLL_END];
823 short up_idx[ACPU_PLL_END];
824 int i, j;
825
826#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
827 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
828 "D0 D1 D2 D4 U0 U1 U2 U4\n");
829
830 t = &acpu_freq_tbl[0];
831 for (i = 0; t->a11clk_khz != 0; i++) {
832
833 for (j = 0; j < ACPU_PLL_END; j++) {
834 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
835 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
836 }
837
838 pr_info("%2d %7d %3d %3d %7d %4d %7d "
839 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
840 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
841 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
842 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
843 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
844
845 t++;
846 }
847}
848
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700849
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530850static struct acpuclk_data acpuclk_7627_data = {
851 .set_rate = acpuclk_7627_set_rate,
852 .get_rate = acpuclk_7627_get_rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700853 .power_collapse_khz = POWER_COLLAPSE_KHZ,
Matt Wagantallec57f062011-08-16 23:54:46 -0700854 .switch_time_us = 50,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700855};
856
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530857static int __init acpuclk_7627_init(struct acpuclk_soc_data *soc_data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700858{
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700859 pr_info("%s()\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700860
861 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
862 BUG_ON(IS_ERR(drv_state.ebi1_clk));
863
864 mutex_init(&drv_state.lock);
Matt Wagantallec57f062011-08-16 23:54:46 -0700865 drv_state.max_speed_delta_khz = soc_data->max_speed_delta_khz;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530866 select_freq_plan();
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530867 acpuclk_7627_data.wait_for_irq_khz = find_wait_for_irq_khz();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700868 precompute_stepping();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700869 acpuclk_hw_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700870 lpj_init();
871 print_acpu_freq_tbl();
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530872 acpuclk_register(&acpuclk_7627_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700873
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700874#ifdef CONFIG_CPU_FREQ_MSM
875 cpufreq_table_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700876#endif
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700877 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878}
Matt Wagantallec57f062011-08-16 23:54:46 -0700879
Matt Wagantallec57f062011-08-16 23:54:46 -0700880struct acpuclk_soc_data acpuclk_7x27_soc_data __initdata = {
881 .max_speed_delta_khz = 400000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530882 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -0700883};
884
885struct acpuclk_soc_data acpuclk_7x27a_soc_data __initdata = {
886 .max_speed_delta_khz = 400000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530887 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -0700888};
889
890struct acpuclk_soc_data acpuclk_7x27aa_soc_data __initdata = {
891 .max_speed_delta_khz = 504000,
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530892 .init = acpuclk_7627_init,
Matt Wagantallec57f062011-08-16 23:54:46 -0700893};