blob: 4facc76570e2698589dbccac367efcbee7c9cf31 [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>
Matt Wagantallbf430eb2012-03-22 11:45:49 -070021#include <linux/module.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#include <linux/init.h>
23#include <linux/errno.h>
24#include <linux/string.h>
25#include <linux/delay.h>
26#include <linux/clk.h>
27#include <linux/cpufreq.h>
28#include <linux/mutex.h>
29#include <linux/io.h>
30#include <linux/sort.h>
Matt Wagantallbf430eb2012-03-22 11:45:49 -070031#include <linux/platform_device.h>
32
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033#include <mach/board.h>
34#include <mach/msm_iomap.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035#include <mach/socinfo.h>
Taniya Dasc43e6872012-03-21 16:41:14 +053036#include <asm/mach-types.h>
37#include <asm/cpu.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039#include "smd_private.h"
40#include "acpuclock.h"
Kaushal Kumar86473f02012-06-28 19:35:58 +053041#include "clock.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
44#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
45#define A11S_VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046
Kaushal Kumar86473f02012-06-28 19:35:58 +053047#define PLL4_L_VAL_ADDR (MSM_CLK_CTL_BASE + 0x378)
48#define PLL4_M_VAL_ADDR (MSM_CLK_CTL_BASE + 0x37C)
49#define PLL4_N_VAL_ADDR (MSM_CLK_CTL_BASE + 0x380)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070051#define POWER_COLLAPSE_KHZ 19200
52
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053/* Max CPU frequency allowed by hardware while in standby waiting for an irq. */
54#define MAX_WAIT_FOR_IRQ_KHZ 128000
55
Pankaj Kumar3912c982011-12-07 16:59:03 +053056/**
57 * enum - For acpuclock PLL IDs
58 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059enum {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060 ACPU_PLL_0 = 0,
61 ACPU_PLL_1,
62 ACPU_PLL_2,
63 ACPU_PLL_3,
64 ACPU_PLL_4,
Pankaj Kumar0249bed2012-03-08 15:20:54 +053065 ACPU_PLL_TCXO,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 ACPU_PLL_END,
67};
68
Pankaj Kumar3912c982011-12-07 16:59:03 +053069struct acpu_clk_src {
70 struct clk *clk;
71 const char *name;
72};
73
Kaushal Kumar86473f02012-06-28 19:35:58 +053074struct pll_config {
75 unsigned int l;
76 unsigned int m;
77 unsigned int n;
78};
79
Pankaj Kumar3912c982011-12-07 16:59:03 +053080static struct acpu_clk_src pll_clk[ACPU_PLL_END] = {
81 [ACPU_PLL_0] = { .name = "pll0_clk" },
82 [ACPU_PLL_1] = { .name = "pll1_clk" },
83 [ACPU_PLL_2] = { .name = "pll2_clk" },
84 [ACPU_PLL_4] = { .name = "pll4_clk" },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085};
86
Kaushal Kumar86473f02012-06-28 19:35:58 +053087static struct pll_config pll4_cfg_tbl[] = {
88 { 36, 1, 2 }, /* 700.8 MHz */
89 { 52, 1, 2 }, /* 1008 MHz */
90 { 63, 0, 1 }, /* 1209.6 MHz */
91 { 73, 0, 1 }, /* 1401.6 MHz */
92};
93
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094struct clock_state {
95 struct clkctl_acpu_speed *current_speed;
96 struct mutex lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097 uint32_t max_speed_delta_khz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098 struct clk *ebi1_clk;
99};
100
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700101struct clkctl_acpu_speed {
102 unsigned int use_for_scaling;
103 unsigned int a11clk_khz;
104 int pll;
105 unsigned int a11clk_src_sel;
106 unsigned int a11clk_src_div;
107 unsigned int ahbclk_khz;
108 unsigned int ahbclk_div;
109 int vdd;
110 unsigned int axiclk_khz;
Kaushal Kumar86473f02012-06-28 19:35:58 +0530111 struct pll_config *pll_rate;
Taniya Dasc43e6872012-03-21 16:41:14 +0530112 unsigned long lpj; /* loops_per_jiffy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700113 /* Pointers in acpu_freq_tbl[] for max up/down steppings. */
114 struct clkctl_acpu_speed *down[ACPU_PLL_END];
115 struct clkctl_acpu_speed *up[ACPU_PLL_END];
116};
117
Kaushal Kumar86473f02012-06-28 19:35:58 +0530118static bool dynamic_reprogram;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119static struct clock_state drv_state = { 0 };
120static struct clkctl_acpu_speed *acpu_freq_tbl;
121
Kaushal Kumar86473f02012-06-28 19:35:58 +0530122/* Switch to this when reprogramming PLL4 */
123static struct clkctl_acpu_speed *backup_s;
124
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125/*
126 * ACPU freq tables used for different PLLs frequency combinations. The
127 * correct table is selected during init.
128 *
129 * Table stepping up/down entries are calculated during boot to choose the
130 * largest frequency jump that's less than max_speed_delta_khz on each PLL.
131 */
132
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530133/* 7627 with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = {
135 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
136 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
137 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
138 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
139 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530140 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
141 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
142 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
143 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530144 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700145};
146
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530147/* 7627 with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = {
149 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
150 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
151 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
152 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
153 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530154 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
155 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
156 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
157 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530158 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159};
160
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530161/* 7627 with GSM capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = {
163 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
164 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
165 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
166 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 },
167 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530168 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
169 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
170 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
171 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530172 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173};
174
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530175/* 7627 with CDMA capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = {
177 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
178 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
179 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
180 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
181 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530182 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
183 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
184 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
185 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530186 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187};
188
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530189/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530191 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
192 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
193 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
194 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530195 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530196 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
197 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
198 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530199 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530200 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530201 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202};
203
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530204/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530206 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
207 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
208 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
209 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Trilok Soniabb750b2011-07-13 16:47:18 +0530210 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
211 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
212 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
213 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530214 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530215 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530216 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217};
218
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530219/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Sonif597e242011-06-06 12:37:16 +0530220static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = {
221 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
222 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
223 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
224 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530225 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonif597e242011-06-06 12:37:16 +0530226 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
227 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530228 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
229 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Sonif597e242011-06-06 12:37:16 +0530230 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530231 { 0 }
Trilok Sonif597e242011-06-06 12:37:16 +0530232};
233
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530234/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Sonid7b05e52011-08-17 18:09:08 +0530235static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008[] = {
236 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
237 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
238 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
239 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530240 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530241 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
242 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530243 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
244 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530245 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530246 { 0 }
Trilok Sonid7b05e52011-08-17 18:09:08 +0530247};
248
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530249/* 8625 PLL4 @ 1209MHz with GSM capable modem */
250static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1209[] = {
251 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
Trilok Soni266a1502012-08-03 20:25:48 +0530252 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 0, 61440 },
253 { 0, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 1, 61440 },
254 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
255 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 2, 122880 },
256 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
257 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
258 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
259 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
260 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
261 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530262 { 0 }
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530263};
264
265/* 8625 PLL4 @ 1209MHz with CDMA capable modem */
266static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1209[] = {
267 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
268 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
Trilok Soni266a1502012-08-03 20:25:48 +0530269 { 0, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530270 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Trilok Soni266a1502012-08-03 20:25:48 +0530271 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
272 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
273 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
274 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
275 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
276 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530277 { 0 }
278};
279
280/* 8625 PLL4 @ 1401.6MHz with GSM capable modem */
281static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1401[] = {
282 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
283 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 0, 61440 },
284 { 0, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 1, 61440 },
285 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
286 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 2, 122880 },
287 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
288 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
289 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
290 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
291 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
292 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
293 { 1, 1401600, ACPU_PLL_4, 6, 0, 175000, 3, 7, 200000, &pll4_cfg_tbl[3]},
294 { 0 }
295};
296
297/* 8625 PLL4 @ 1401.6MHz with CDMA capable modem */
298static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1401[] = {
299 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
300 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
301 { 0, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
302 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
303 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
304 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
305 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
306 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
307 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
308 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
309 { 1, 1401600, ACPU_PLL_4, 6, 0, 175000, 3, 7, 200000, &pll4_cfg_tbl[3]},
310 { 0 }
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530311};
312
Trilok Soni48631722012-05-17 20:56:42 +0530313/* 8625 PLL4 @ 1152MHz with GSM capable modem */
314static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1152[] = {
315 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
316 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
317 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
318 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
319 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
320 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
321 { 0, 576000, ACPU_PLL_4, 6, 1, 72000, 3, 6, 160000 },
322 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
323 { 1, 1152000, ACPU_PLL_4, 6, 0, 144000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530324 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530325};
326
327/* 8625 PLL4 @ 1115MHz with CDMA capable modem */
328static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1152[] = {
329 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
330 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
331 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
332 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
333 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
334 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
335 { 0, 576000, ACPU_PLL_4, 6, 1, 72000, 3, 6, 160000 },
336 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
337 { 1, 1152000, ACPU_PLL_4, 6, 0, 144000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530338 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530339};
340
341
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530342/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530343static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_25a[] = {
Trilok Soni54d35c42011-07-14 17:47:50 +0530344 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
345 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
346 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
347 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530348 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530349 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530350 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530351 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
352 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530353 { 0 }
Trilok Soni54d35c42011-07-14 17:47:50 +0530354};
355
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530356/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530357static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = {
358 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
359 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
360 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
361 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530362 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530363 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
364 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
365 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530366 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530367 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530368 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530369};
370
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530371/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530372static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = {
373 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
374 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
375 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
376 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
377 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
378 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
379 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
380 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530381 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530382 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530383 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530384};
385
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530386/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530387static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = {
388 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
389 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
390 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
391 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530392 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530393 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
394 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530395 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
396 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530397 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530398 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530399};
400
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530401/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530402static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = {
403 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
404 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
405 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
406 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530407 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530408 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
409 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530410 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
411 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530412 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530413 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530414};
415
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530416/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530417static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_25a[] = {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530418 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
419 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
420 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
421 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530422 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530423 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530424 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530425 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
426 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530427 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530428};
429
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700430#define PLL_CONFIG(m0, m1, m2, m4) { \
Pankaj Kumar3912c982011-12-07 16:59:03 +0530431 m0, m1, m2, m4, \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700432 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
433}
434
435struct pll_freq_tbl_map {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530436 unsigned int pll0_rate;
437 unsigned int pll1_rate;
438 unsigned int pll2_rate;
439 unsigned int pll4_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700440 struct clkctl_acpu_speed *tbl;
441};
442
443static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700444 PLL_CONFIG(960, 196, 1200, 0),
445 PLL_CONFIG(960, 245, 1200, 0),
446 PLL_CONFIG(960, 196, 800, 0),
447 PLL_CONFIG(960, 245, 800, 0),
448 PLL_CONFIG(960, 245, 1200, 800),
449 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530450 PLL_CONFIG(960, 245, 1200, 1008),
Trilok Sonid7b05e52011-08-17 18:09:08 +0530451 PLL_CONFIG(960, 196, 1200, 1008),
Trilok Soni9bb022c2011-10-31 18:25:19 +0530452 PLL_CONFIG(960, 737, 1200, 800),
453 PLL_CONFIG(960, 589, 1200, 800),
454 PLL_CONFIG(960, 737, 1200, 1008),
455 PLL_CONFIG(960, 589, 1200, 1008),
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530456 PLL_CONFIG(960, 245, 1200, 1209),
457 PLL_CONFIG(960, 196, 1200, 1209),
Trilok Soni48631722012-05-17 20:56:42 +0530458 PLL_CONFIG(960, 245, 1200, 1152),
459 PLL_CONFIG(960, 196, 1200, 1152),
Kaushal Kumar86473f02012-06-28 19:35:58 +0530460 PLL_CONFIG(960, 245, 1200, 1401),
461 PLL_CONFIG(960, 196, 1200, 1401),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700462 { 0, 0, 0, 0, 0 }
463};
464
465#ifdef CONFIG_CPU_FREQ_MSM
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530466static struct cpufreq_frequency_table freq_table[NR_CPUS][20];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700467
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700468static void __devinit cpufreq_table_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700469{
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530470 int cpu;
471 for_each_possible_cpu(cpu) {
472 unsigned int i, freq_cnt = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530474 /* Construct the freq_table table from acpu_freq_tbl since
475 * the freq_table values need to match frequencies specified
476 * in acpu_freq_tbl and acpu_freq_tbl needs to be fixed up
477 * during init.
478 */
479 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
480 && freq_cnt < ARRAY_SIZE(*freq_table)-1; i++) {
481 if (acpu_freq_tbl[i].use_for_scaling) {
482 freq_table[cpu][freq_cnt].index = freq_cnt;
483 freq_table[cpu][freq_cnt].frequency
484 = acpu_freq_tbl[i].a11clk_khz;
485 freq_cnt++;
486 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487 }
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530488
489 /* freq_table not big enough to store all usable freqs. */
490 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
491
492 freq_table[cpu][freq_cnt].index = freq_cnt;
493 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
494 /* Register table with CPUFreq. */
495 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
496 pr_info("CPU%d: %d scaling frequencies supported.\n",
497 cpu, freq_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700498 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700499}
500#endif
501
Kaushal Kumar86473f02012-06-28 19:35:58 +0530502static void update_jiffies(int cpu, unsigned long loops)
503{
504#ifdef CONFIG_SMP
505 for_each_possible_cpu(cpu) {
506 per_cpu(cpu_data, cpu).loops_per_jiffy =
507 loops;
508 }
509#endif
510 /* Adjust the global one */
511 loops_per_jiffy = loops;
512}
513
514/* Assumes PLL4 is off and the acpuclock isn't sourced from PLL4 */
515static void acpuclk_config_pll4(struct pll_config *pll)
516{
517 /* Make sure write to disable PLL_4 has completed
518 * before reconfiguring that PLL. */
519 mb();
520 writel_relaxed(pll->l, PLL4_L_VAL_ADDR);
521 writel_relaxed(pll->m, PLL4_M_VAL_ADDR);
522 writel_relaxed(pll->n, PLL4_N_VAL_ADDR);
523 /* Make sure PLL is programmed before returning. */
524 mb();
525}
526
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700527static int acpuclk_set_vdd_level(int vdd)
528{
529 uint32_t current_vdd;
530
Pankaj Kumar9406a3b2011-12-23 18:07:15 +0530531 /*
532 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
533 * VDD switching support.
534 */
535 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
536 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
537 return 0;
538
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700539 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
540
541 pr_debug("Switching VDD from %u mV -> %d mV\n",
542 current_vdd, vdd);
543
544 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
545 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700546 udelay(62);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700547 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
548 pr_err("VDD set failed\n");
549 return -EIO;
550 }
551
552 pr_debug("VDD switched\n");
553
554 return 0;
555}
556
557/* Set proper dividers for the given clock speed. */
558static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
559{
560 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
561
562 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
563
564 /* AHB_CLK_DIV */
565 clk_div = (reg_clksel >> 1) & 0x03;
566 /* CLK_SEL_SRC1NO */
567 src_sel = reg_clksel & 1;
568
569 /*
570 * If the new clock divider is higher than the previous, then
571 * program the divider before switching the clock
572 */
573 if (hunt_s->ahbclk_div > clk_div) {
574 reg_clksel &= ~(0x3 << 1);
575 reg_clksel |= (hunt_s->ahbclk_div << 1);
576 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
577 }
578
579 /* Program clock source and divider */
580 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
581 reg_clkctl &= ~(0xFF << (8 * src_sel));
582 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
583 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
584 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
585
586 /* Program clock source selection */
587 reg_clksel ^= 1;
588 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
589
Pankaj Kumard66a9192012-04-11 19:35:38 +0530590 /* Wait for the clock switch to complete */
591 mb();
592 udelay(50);
593
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594 /*
595 * If the new clock divider is lower than the previous, then
596 * program the divider after switching the clock
597 */
598 if (hunt_s->ahbclk_div < clk_div) {
599 reg_clksel &= ~(0x3 << 1);
600 reg_clksel |= (hunt_s->ahbclk_div << 1);
601 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
602 }
603}
604
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530605static int acpuclk_7627_set_rate(int cpu, unsigned long rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700606 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700607{
608 uint32_t reg_clkctl;
609 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
610 int res, rc = 0;
611 unsigned int plls_enabled = 0, pll;
Kaushal Kumar86473f02012-06-28 19:35:58 +0530612 int delta;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700613
614 if (reason == SETRATE_CPUFREQ)
615 mutex_lock(&drv_state.lock);
616
617 strt_s = cur_s = drv_state.current_speed;
618
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700619 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700620 if (cur_s == NULL) {
621 rc = -ENOENT;
622 goto out;
623 }
624
625 if (rate == cur_s->a11clk_khz)
626 goto out;
627
628 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
629 if (tgt_s->a11clk_khz == rate)
630 break;
631 }
632
633 if (tgt_s->a11clk_khz == 0) {
634 rc = -EINVAL;
635 goto out;
636 }
637
638 /* Choose the highest speed at or below 'rate' with same PLL. */
639 if (reason != SETRATE_CPUFREQ
640 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
641 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
642 tgt_s--;
643 }
644
645 if (strt_s->pll != ACPU_PLL_TCXO)
646 plls_enabled |= 1 << strt_s->pll;
647
648 if (reason == SETRATE_CPUFREQ) {
649 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530650 rc = clk_enable(pll_clk[tgt_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700651 if (rc < 0) {
652 pr_err("PLL%d enable failed (%d)\n",
653 tgt_s->pll, rc);
654 goto out;
655 }
656 plls_enabled |= 1 << tgt_s->pll;
657 }
658 }
659 /* Need to do this when coming out of power collapse since some modem
660 * firmwares reset the VDD when the application processor enters power
661 * collapse. */
662 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
663 /* Increase VDD if needed. */
664 if (tgt_s->vdd > cur_s->vdd) {
665 rc = acpuclk_set_vdd_level(tgt_s->vdd);
666 if (rc < 0) {
667 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
668 goto out;
669 }
670 }
671 }
672
673 /* Set wait states for CPU inbetween frequency changes */
674 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
675 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
676 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
677
678 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
679 strt_s->a11clk_khz, tgt_s->a11clk_khz);
680
Kaushal Kumar86473f02012-06-28 19:35:58 +0530681 delta = abs((int)(strt_s->a11clk_khz - tgt_s->a11clk_khz));
682
683 if (dynamic_reprogram) {
684 if (tgt_s->pll == ACPU_PLL_4) {
685 if (strt_s->pll == ACPU_PLL_4 ||
686 delta > drv_state.max_speed_delta_khz) {
687 /*
688 * Enable the backup PLL if required
689 * and switch to it.
690 */
691 clk_enable(pll_clk[backup_s->pll].clk);
692 acpuclk_set_div(backup_s);
693 }
694 /* Make sure PLL4 is off before reprogramming */
695 if ((plls_enabled & (1 << tgt_s->pll))) {
696 clk_disable(pll_clk[tgt_s->pll].clk);
697 plls_enabled &= (0 << tgt_s->pll);
698 }
699 acpuclk_config_pll4(tgt_s->pll_rate);
700 pll_clk[tgt_s->pll].clk->rate = tgt_s->a11clk_khz*1000;
701
702 } else if (strt_s->pll == ACPU_PLL_4) {
703 if (delta > drv_state.max_speed_delta_khz) {
704 /*
705 * Enable the bcackup PLL if required
706 * and switch to it.
707 */
708 clk_enable(pll_clk[backup_s->pll].clk);
709 acpuclk_set_div(backup_s);
710 }
711 }
712
713 if (!(plls_enabled & (1 << tgt_s->pll))) {
714 rc = clk_enable(pll_clk[tgt_s->pll].clk);
715 if (rc < 0) {
716 pr_err("PLL%d enable failed (%d)\n",
717 tgt_s->pll, rc);
718 goto out;
719 }
720 plls_enabled |= 1 << tgt_s->pll;
721 }
722 acpuclk_set_div(tgt_s);
723 drv_state.current_speed = tgt_s;
724 /* Re-adjust lpj for the new clock speed. */
725 update_jiffies(cpu, cur_s->lpj);
726
727 /* Disable the backup PLL */
728 if ((delta > drv_state.max_speed_delta_khz)
729 || (strt_s->pll == ACPU_PLL_4 &&
730 tgt_s->pll == ACPU_PLL_4))
731 clk_disable_unprepare(pll_clk[backup_s->pll].clk);
732
733 goto done;
734 }
735
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700736 while (cur_s != tgt_s) {
737 /*
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530738 * Always jump to target freq if within max_speed_delta_khz,
739 * regardless of PLL. If differnece is greater, use the
740 * predefined steppings in the table.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700741 */
742 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
743 if (d > drv_state.max_speed_delta_khz) {
744
745 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
746 /* Step up: jump to target PLL as early as
747 * possible so indexing using TCXO (up[-1])
748 * never occurs. */
749 if (likely(cur_s->up[tgt_s->pll]))
750 cur_s = cur_s->up[tgt_s->pll];
751 else
752 cur_s = cur_s->up[cur_s->pll];
753 } else {
754 /* Step down: stay on current PLL as long as
755 * possible so indexing using TCXO (down[-1])
756 * never occurs. */
757 if (likely(cur_s->down[cur_s->pll]))
758 cur_s = cur_s->down[cur_s->pll];
759 else
760 cur_s = cur_s->down[tgt_s->pll];
761 }
762
763 if (cur_s == NULL) { /* This should not happen. */
764 pr_err("No stepping frequencies found. "
765 "strt_s:%u tgt_s:%u\n",
766 strt_s->a11clk_khz, tgt_s->a11clk_khz);
767 rc = -EINVAL;
768 goto out;
769 }
770
771 } else {
772 cur_s = tgt_s;
773 }
774
775 pr_debug("STEP khz = %u, pll = %d\n",
776 cur_s->a11clk_khz, cur_s->pll);
777
778 if (cur_s->pll != ACPU_PLL_TCXO
779 && !(plls_enabled & (1 << cur_s->pll))) {
Trilok Soni57c07782012-05-07 16:52:16 +0530780 rc = clk_enable(pll_clk[cur_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700781 if (rc < 0) {
782 pr_err("PLL%d enable failed (%d)\n",
783 cur_s->pll, rc);
784 goto out;
785 }
786 plls_enabled |= 1 << cur_s->pll;
787 }
788
789 acpuclk_set_div(cur_s);
790 drv_state.current_speed = cur_s;
Taniya Dasc43e6872012-03-21 16:41:14 +0530791 /* Re-adjust lpj for the new clock speed. */
Kaushal Kumar86473f02012-06-28 19:35:58 +0530792 update_jiffies(cpu, cur_s->lpj);
Taniya Dasc43e6872012-03-21 16:41:14 +0530793
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700794 }
Kaushal Kumar86473f02012-06-28 19:35:58 +0530795done:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700796 /* Nothing else to do for SWFI. */
797 if (reason == SETRATE_SWFI)
798 goto out;
799
800 /* Change the AXI bus frequency if we can. */
801 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
802 res = clk_set_rate(drv_state.ebi1_clk,
803 tgt_s->axiclk_khz * 1000);
804 if (res < 0)
805 pr_warning("Setting AXI min rate failed (%d)\n", res);
806 }
807
808 /* Disable PLLs we are not using anymore. */
809 if (tgt_s->pll != ACPU_PLL_TCXO)
810 plls_enabled &= ~(1 << tgt_s->pll);
811 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
Pankaj Kumar3912c982011-12-07 16:59:03 +0530812 if (plls_enabled & (1 << pll))
Trilok Soni57c07782012-05-07 16:52:16 +0530813 clk_disable(pll_clk[pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700814
815 /* Nothing else to do for power collapse. */
816 if (reason == SETRATE_PC)
817 goto out;
818
819 /* Drop VDD level if we can. */
820 if (tgt_s->vdd < strt_s->vdd) {
821 res = acpuclk_set_vdd_level(tgt_s->vdd);
822 if (res < 0)
823 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
824 }
825
826 pr_debug("ACPU speed change complete\n");
827out:
828 if (reason == SETRATE_CPUFREQ)
829 mutex_unlock(&drv_state.lock);
830 return rc;
831}
832
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700833static void __devinit acpuclk_hw_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700834{
835 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530836 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700837 int res;
838
839 /*
Trilok Soni57c07782012-05-07 16:52:16 +0530840 * Prepare all the PLLs because we enable/disable them
841 * from atomic context and can't always ensure they're
842 * all prepared in non-atomic context. Same goes for
843 * ebi1_acpu_clk.
844 */
845 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_0].clk));
846 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_1].clk));
847 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_2].clk));
848 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_4].clk));
849 BUG_ON(clk_prepare(drv_state.ebi1_clk));
850
851 /*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700852 * Determine the rate of ACPU clock
853 */
854
855 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
856 /* CLK_SRC0_SEL */
857 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
858 /* CLK_SRC0_DIV */
859 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
860 } else {
861 /* CLK_SRC1_SEL */
862 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
863 /* CLK_SRC1_DIV */
864 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
865 }
866
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700867 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
868 if (speed->a11clk_src_sel == sel
869 && (speed->a11clk_src_div == div))
870 break;
871 }
872 if (speed->a11clk_khz == 0) {
873 pr_err("Error - ACPU clock reports invalid speed\n");
874 return;
875 }
876
877 drv_state.current_speed = speed;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530878 if (speed->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530879 if (clk_enable(pll_clk[speed->pll].clk))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700880 pr_warning("Failed to vote for boot PLL\n");
Pankaj Kumar3912c982011-12-07 16:59:03 +0530881 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700882
Trilok Soni7d6c8652011-07-14 15:35:07 +0530883 /* Fix div2 to 2 for 7x27/5a(aa) targets */
884 if (!cpu_is_msm7x27()) {
885 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
886 reg_clksel &= ~(0x3 << 14);
887 reg_clksel |= (0x1 << 14);
888 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
889 }
890
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700891 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
892 if (res < 0)
893 pr_warning("Setting AXI min rate failed (%d)\n", res);
Trilok Soni57c07782012-05-07 16:52:16 +0530894 res = clk_enable(drv_state.ebi1_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700895 if (res < 0)
896 pr_warning("Enabling AXI clock failed (%d)\n", res);
897
898 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
899}
900
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530901static unsigned long acpuclk_7627_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902{
903 WARN_ONCE(drv_state.current_speed == NULL,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700904 "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700905 if (drv_state.current_speed)
906 return drv_state.current_speed->a11clk_khz;
907 else
908 return 0;
909}
910
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911/*----------------------------------------------------------------------------
912 * Clock driver initialization
913 *---------------------------------------------------------------------------*/
Pankaj Kumar3912c982011-12-07 16:59:03 +0530914#define MHZ 1000000
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700915static void __devinit select_freq_plan(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700916{
Pankaj Kumar3912c982011-12-07 16:59:03 +0530917 unsigned long pll_mhz[ACPU_PLL_END];
Kaushal Kumar86473f02012-06-28 19:35:58 +0530918 struct pll_freq_tbl_map *t = acpu_freq_tbl_list;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530919 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700920
Pankaj Kumar3912c982011-12-07 16:59:03 +0530921 /* Get PLL clocks */
922 for (i = 0; i < ACPU_PLL_END; i++) {
923 if (pll_clk[i].name) {
924 pll_clk[i].clk = clk_get_sys("acpu", pll_clk[i].name);
925 if (IS_ERR(pll_clk[i].clk)) {
926 pll_mhz[i] = 0;
927 continue;
928 }
929 /* Get PLL's Rate */
930 pll_mhz[i] = clk_get_rate(pll_clk[i].clk)/MHZ;
931 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932 }
933
Pankaj Kumar3912c982011-12-07 16:59:03 +0530934 /*
935 * For the pll configuration used in acpuclock table e.g.
936 * pll0_960_pll1_245_pll2_1200" is same for 7627 and
937 * 7625a (as pll0,pll1,pll2) having same rates, but frequency
938 * table is different for both targets.
939 *
940 * Hence below for loop will not be able to select correct
941 * table based on PLL rates as rates are same. Hence we need
942 * to add this cpu check for selecting the correct acpuclock table.
943 */
Trilok Soni54d35c42011-07-14 17:47:50 +0530944 if (cpu_is_msm7x25a()) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530945 if (pll_mhz[ACPU_PLL_1] == 245) {
Trilok Soni54d35c42011-07-14 17:47:50 +0530946 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530947 pll0_960_pll1_245_pll2_1200_25a;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530948 } else if (pll_mhz[ACPU_PLL_1] == 737) {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530949 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530950 pll0_960_pll1_737_pll2_1200_25a;
Trilok Soni54d35c42011-07-14 17:47:50 +0530951 }
952 } else {
953 /* Select the right table to use. */
Kaushal Kumar86473f02012-06-28 19:35:58 +0530954 for (; t->tbl != 0; t++) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530955 if (t->pll0_rate == pll_mhz[ACPU_PLL_0]
956 && t->pll1_rate == pll_mhz[ACPU_PLL_1]
957 && t->pll2_rate == pll_mhz[ACPU_PLL_2]
958 && t->pll4_rate == pll_mhz[ACPU_PLL_4]) {
959 acpu_freq_tbl = t->tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +0530960 break;
961 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700962 }
963 }
964
Trilok Soni3f33ffc2012-08-03 20:14:04 +0530965 if (acpu_freq_tbl == NULL) {
966 pr_crit("Unknown PLL configuration!\n");
967 BUG();
968 }
969
Kaushal Kumar86473f02012-06-28 19:35:58 +0530970 /*
Trilok Soni3f33ffc2012-08-03 20:14:04 +0530971 * Turn ON the dynamic reprogramming method
972 * if one of the table entry has pll_rate defined.
973 */
974 for ( ; t->tbl->a11clk_khz; t->tbl++) {
975 if (t->tbl->pll_rate) {
976 if (!dynamic_reprogram) {
977 dynamic_reprogram = 1;
978 pr_info("Dynamic reprogramming is ON\n");
979 }
980 }
981 }
982
983 /*
Kaushal Kumar86473f02012-06-28 19:35:58 +0530984 * Also find the backup pll used during PLL4 reprogramming.
985 * We are using PLL2@600MHz as backup PLL, since 800MHz jump
986 * is fine.
987 */
Trilok Soni3f33ffc2012-08-03 20:14:04 +0530988 if (dynamic_reprogram) {
989 for (t->tbl = acpu_freq_tbl; t->tbl->a11clk_khz; t->tbl++) {
Kaushal Kumar86473f02012-06-28 19:35:58 +0530990 if (t->tbl->pll == ACPU_PLL_2 &&
991 t->tbl->a11clk_src_div == 1) {
992 backup_s = t->tbl;
993 break;
994 }
995 }
996 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700997}
998
999/*
1000 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
1001 * before entering a wait for irq low-power mode. Find a suitable rate.
1002 */
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001003static unsigned long __devinit find_wait_for_irq_khz(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001004{
1005 unsigned long found_khz = 0;
1006 int i;
1007
1008 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
1009 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
1010 found_khz = acpu_freq_tbl[i].a11clk_khz;
1011
1012 return found_khz;
1013}
1014
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001015static void __devinit lpj_init(void)
Taniya Dasc43e6872012-03-21 16:41:14 +05301016{
1017 int i = 0, cpu;
1018 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
1019 unsigned long loops;
1020
1021 for_each_possible_cpu(cpu) {
1022#ifdef CONFIG_SMP
1023 loops = per_cpu(cpu_data, cpu).loops_per_jiffy;
1024#else
1025 loops = loops_per_jiffy;
1026#endif
1027 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1028 acpu_freq_tbl[i].lpj = cpufreq_scale(
1029 loops,
1030 base_clk->a11clk_khz,
1031 acpu_freq_tbl[i].a11clk_khz);
1032 }
1033 }
1034}
1035
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001036static void __devinit precompute_stepping(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001037{
1038 int i, step_idx;
1039
1040#define cur_freq acpu_freq_tbl[i].a11clk_khz
1041#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
1042#define cur_pll acpu_freq_tbl[i].pll
1043#define step_pll acpu_freq_tbl[step_idx].pll
1044
1045 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1046
1047 /* Calculate max "up" step for each destination PLL */
1048 step_idx = i + 1;
1049 while (step_freq && (step_freq - cur_freq)
1050 <= drv_state.max_speed_delta_khz) {
1051 acpu_freq_tbl[i].up[step_pll] =
1052 &acpu_freq_tbl[step_idx];
1053 step_idx++;
1054 }
1055 if (step_idx == (i + 1) && step_freq) {
1056 pr_crit("Delta between freqs %u KHz and %u KHz is"
1057 " too high!\n", cur_freq, step_freq);
1058 BUG();
1059 }
1060
1061 /* Calculate max "down" step for each destination PLL */
1062 step_idx = i - 1;
1063 while (step_idx >= 0 && (cur_freq - step_freq)
1064 <= drv_state.max_speed_delta_khz) {
1065 acpu_freq_tbl[i].down[step_pll] =
1066 &acpu_freq_tbl[step_idx];
1067 step_idx--;
1068 }
1069 if (step_idx == (i - 1) && i > 0) {
1070 pr_crit("Delta between freqs %u KHz and %u KHz is"
1071 " too high!\n", cur_freq, step_freq);
1072 BUG();
1073 }
1074 }
1075}
1076
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001077static void __devinit print_acpu_freq_tbl(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001078{
1079 struct clkctl_acpu_speed *t;
1080 short down_idx[ACPU_PLL_END];
1081 short up_idx[ACPU_PLL_END];
1082 int i, j;
1083
1084#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
1085 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
1086 "D0 D1 D2 D4 U0 U1 U2 U4\n");
1087
1088 t = &acpu_freq_tbl[0];
1089 for (i = 0; t->a11clk_khz != 0; i++) {
1090
1091 for (j = 0; j < ACPU_PLL_END; j++) {
1092 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
1093 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
1094 }
1095
1096 pr_info("%2d %7d %3d %3d %7d %4d %7d "
1097 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
1098 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
1099 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
1100 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
1101 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
1102
1103 t++;
1104 }
1105}
1106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001107
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301108static struct acpuclk_data acpuclk_7627_data = {
1109 .set_rate = acpuclk_7627_set_rate,
1110 .get_rate = acpuclk_7627_get_rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001111 .power_collapse_khz = POWER_COLLAPSE_KHZ,
Matt Wagantallec57f062011-08-16 23:54:46 -07001112 .switch_time_us = 50,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001113};
1114
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001115static int __devinit acpuclk_7627_probe(struct platform_device *pdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001116{
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001117 const struct acpuclk_pdata *pdata = pdev->dev.platform_data;
1118
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001119 pr_info("%s()\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001120
1121 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
1122 BUG_ON(IS_ERR(drv_state.ebi1_clk));
1123
1124 mutex_init(&drv_state.lock);
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001125 drv_state.max_speed_delta_khz = pdata->max_speed_delta_khz;
Pankaj Kumar3912c982011-12-07 16:59:03 +05301126 select_freq_plan();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301127 acpuclk_7627_data.wait_for_irq_khz = find_wait_for_irq_khz();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001128 precompute_stepping();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001129 acpuclk_hw_init();
Taniya Dasc43e6872012-03-21 16:41:14 +05301130 lpj_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001131 print_acpu_freq_tbl();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301132 acpuclk_register(&acpuclk_7627_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001133
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001134#ifdef CONFIG_CPU_FREQ_MSM
1135 cpufreq_table_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001136#endif
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001137 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001138}
Matt Wagantallec57f062011-08-16 23:54:46 -07001139
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001140static struct platform_driver acpuclk_7627_driver = {
1141 .probe = acpuclk_7627_probe,
1142 .driver = {
1143 .name = "acpuclk-7627",
1144 .owner = THIS_MODULE,
1145 },
Matt Wagantallec57f062011-08-16 23:54:46 -07001146};
1147
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001148static int __init acpuclk_7627_init(void)
1149{
1150 return platform_driver_register(&acpuclk_7627_driver);
1151}
1152postcore_initcall(acpuclk_7627_init);
Kaushal Kumar86473f02012-06-28 19:35:58 +05301153