blob: 0718a0a59a3268ebf21deb048de1a5ecb61a9318 [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.
Duy Truonge833aca2013-02-12 13:35:08 -08005 * Copyright (c) 2007-2012, The Linux Foundation. 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>
Matt Wagantalld55b90f2012-02-23 23:27:44 -080035#include <mach/clk-provider.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036#include <mach/socinfo.h>
Taniya Dasc43e6872012-03-21 16:41:14 +053037#include <asm/mach-types.h>
38#include <asm/cpu.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040#include "smd_private.h"
41#include "acpuclock.h"
42
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 Sonia5639902012-08-05 16:49:07 +0530313/* 8625v2.0 PLL4 @ 1008MHz with GSM capable modem */
314static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008_2p0[] = {
315 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
316 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 0, 61440 },
317 { 0, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 1, 61440 },
318 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
319 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 2, 122880 },
320 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
321 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
322 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
323 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
324 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
325 { 0 }
326};
327
328/* 8625v2.0 PLL4 @ 1008MHz with CDMA capable modem */
329static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008_2p0[] = {
330 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
331 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
332 { 0, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
333 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
334 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
335 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
336 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
337 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
338 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
339 { 0 }
340};
341
Trilok Soni48631722012-05-17 20:56:42 +0530342/* 8625 PLL4 @ 1152MHz with GSM capable modem */
343static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1152[] = {
344 { 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 },
348 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
349 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
350 { 0, 576000, ACPU_PLL_4, 6, 1, 72000, 3, 6, 160000 },
351 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
352 { 1, 1152000, ACPU_PLL_4, 6, 0, 144000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530353 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530354};
355
356/* 8625 PLL4 @ 1115MHz with CDMA capable modem */
357static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1152[] = {
358 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
359 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
360 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
361 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
362 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
363 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
364 { 0, 576000, ACPU_PLL_4, 6, 1, 72000, 3, 6, 160000 },
365 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
366 { 1, 1152000, ACPU_PLL_4, 6, 0, 144000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530367 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530368};
369
370
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530371/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530372static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_25a[] = {
Trilok Soni54d35c42011-07-14 17:47:50 +0530373 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
374 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
375 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
376 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530377 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530378 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530379 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530380 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
381 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530382 { 0 }
Trilok Soni54d35c42011-07-14 17:47:50 +0530383};
384
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530385/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530386static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = {
387 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
388 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
389 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
390 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530391 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530392 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
393 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
394 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530395 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530396 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530397 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530398};
399
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530400/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530401static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = {
402 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
403 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
404 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
405 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
406 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
407 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
408 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
409 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530410 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530411 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530412 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530413};
414
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530415/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530416static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = {
417 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
418 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
419 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
420 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530421 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530422 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
423 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530424 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
425 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530426 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530427 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530428};
429
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530430/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530431static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = {
432 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
433 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
434 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
435 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530436 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530437 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
438 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530439 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
440 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530441 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530442 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530443};
444
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530445/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530446static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_25a[] = {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530447 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
448 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
449 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
450 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530451 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530452 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530453 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530454 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
455 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530456 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530457};
458
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700459#define PLL_CONFIG(m0, m1, m2, m4) { \
Pankaj Kumar3912c982011-12-07 16:59:03 +0530460 m0, m1, m2, m4, \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700461 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
462}
463
464struct pll_freq_tbl_map {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530465 unsigned int pll0_rate;
466 unsigned int pll1_rate;
467 unsigned int pll2_rate;
468 unsigned int pll4_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700469 struct clkctl_acpu_speed *tbl;
470};
471
472static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473 PLL_CONFIG(960, 196, 1200, 0),
474 PLL_CONFIG(960, 245, 1200, 0),
475 PLL_CONFIG(960, 196, 800, 0),
476 PLL_CONFIG(960, 245, 800, 0),
477 PLL_CONFIG(960, 245, 1200, 800),
478 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530479 PLL_CONFIG(960, 245, 1200, 1008),
Trilok Sonid7b05e52011-08-17 18:09:08 +0530480 PLL_CONFIG(960, 196, 1200, 1008),
Trilok Soni9bb022c2011-10-31 18:25:19 +0530481 PLL_CONFIG(960, 737, 1200, 800),
482 PLL_CONFIG(960, 589, 1200, 800),
483 PLL_CONFIG(960, 737, 1200, 1008),
484 PLL_CONFIG(960, 589, 1200, 1008),
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530485 PLL_CONFIG(960, 245, 1200, 1209),
486 PLL_CONFIG(960, 196, 1200, 1209),
Trilok Soni48631722012-05-17 20:56:42 +0530487 PLL_CONFIG(960, 245, 1200, 1152),
488 PLL_CONFIG(960, 196, 1200, 1152),
Kaushal Kumar86473f02012-06-28 19:35:58 +0530489 PLL_CONFIG(960, 245, 1200, 1401),
490 PLL_CONFIG(960, 196, 1200, 1401),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700491 { 0, 0, 0, 0, 0 }
492};
493
494#ifdef CONFIG_CPU_FREQ_MSM
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530495static struct cpufreq_frequency_table freq_table[NR_CPUS][20];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700496
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700497static void __devinit cpufreq_table_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700498{
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530499 int cpu;
500 for_each_possible_cpu(cpu) {
501 unsigned int i, freq_cnt = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700502
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530503 /* Construct the freq_table table from acpu_freq_tbl since
504 * the freq_table values need to match frequencies specified
505 * in acpu_freq_tbl and acpu_freq_tbl needs to be fixed up
506 * during init.
507 */
508 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
509 && freq_cnt < ARRAY_SIZE(*freq_table)-1; i++) {
510 if (acpu_freq_tbl[i].use_for_scaling) {
511 freq_table[cpu][freq_cnt].index = freq_cnt;
512 freq_table[cpu][freq_cnt].frequency
513 = acpu_freq_tbl[i].a11clk_khz;
514 freq_cnt++;
515 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700516 }
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530517
518 /* freq_table not big enough to store all usable freqs. */
519 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
520
521 freq_table[cpu][freq_cnt].index = freq_cnt;
522 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
523 /* Register table with CPUFreq. */
524 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
525 pr_info("CPU%d: %d scaling frequencies supported.\n",
526 cpu, freq_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700527 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700528}
529#endif
530
Kaushal Kumar86473f02012-06-28 19:35:58 +0530531static void update_jiffies(int cpu, unsigned long loops)
532{
533#ifdef CONFIG_SMP
534 for_each_possible_cpu(cpu) {
535 per_cpu(cpu_data, cpu).loops_per_jiffy =
536 loops;
537 }
538#endif
539 /* Adjust the global one */
540 loops_per_jiffy = loops;
541}
542
543/* Assumes PLL4 is off and the acpuclock isn't sourced from PLL4 */
544static void acpuclk_config_pll4(struct pll_config *pll)
545{
546 /* Make sure write to disable PLL_4 has completed
547 * before reconfiguring that PLL. */
548 mb();
549 writel_relaxed(pll->l, PLL4_L_VAL_ADDR);
550 writel_relaxed(pll->m, PLL4_M_VAL_ADDR);
551 writel_relaxed(pll->n, PLL4_N_VAL_ADDR);
552 /* Make sure PLL is programmed before returning. */
553 mb();
554}
555
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700556static int acpuclk_set_vdd_level(int vdd)
557{
558 uint32_t current_vdd;
559
Pankaj Kumar9406a3b2011-12-23 18:07:15 +0530560 /*
561 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
562 * VDD switching support.
563 */
564 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
565 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
566 return 0;
567
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700568 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
569
570 pr_debug("Switching VDD from %u mV -> %d mV\n",
571 current_vdd, vdd);
572
573 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
574 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700575 udelay(62);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
577 pr_err("VDD set failed\n");
578 return -EIO;
579 }
580
581 pr_debug("VDD switched\n");
582
583 return 0;
584}
585
586/* Set proper dividers for the given clock speed. */
587static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
588{
589 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
590
591 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
592
593 /* AHB_CLK_DIV */
594 clk_div = (reg_clksel >> 1) & 0x03;
595 /* CLK_SEL_SRC1NO */
596 src_sel = reg_clksel & 1;
597
598 /*
599 * If the new clock divider is higher than the previous, then
600 * program the divider before switching the clock
601 */
602 if (hunt_s->ahbclk_div > clk_div) {
603 reg_clksel &= ~(0x3 << 1);
604 reg_clksel |= (hunt_s->ahbclk_div << 1);
605 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
606 }
607
608 /* Program clock source and divider */
609 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
610 reg_clkctl &= ~(0xFF << (8 * src_sel));
611 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
612 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
613 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
614
615 /* Program clock source selection */
616 reg_clksel ^= 1;
617 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
618
Pankaj Kumard66a9192012-04-11 19:35:38 +0530619 /* Wait for the clock switch to complete */
620 mb();
621 udelay(50);
622
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700623 /*
624 * If the new clock divider is lower than the previous, then
625 * program the divider after switching the clock
626 */
627 if (hunt_s->ahbclk_div < clk_div) {
628 reg_clksel &= ~(0x3 << 1);
629 reg_clksel |= (hunt_s->ahbclk_div << 1);
630 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
631 }
632}
633
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530634static int acpuclk_7627_set_rate(int cpu, unsigned long rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700635 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700636{
637 uint32_t reg_clkctl;
638 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
639 int res, rc = 0;
640 unsigned int plls_enabled = 0, pll;
Kaushal Kumar86473f02012-06-28 19:35:58 +0530641 int delta;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700642
643 if (reason == SETRATE_CPUFREQ)
644 mutex_lock(&drv_state.lock);
645
646 strt_s = cur_s = drv_state.current_speed;
647
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700648 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649 if (cur_s == NULL) {
650 rc = -ENOENT;
651 goto out;
652 }
653
654 if (rate == cur_s->a11clk_khz)
655 goto out;
656
657 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
658 if (tgt_s->a11clk_khz == rate)
659 break;
660 }
661
662 if (tgt_s->a11clk_khz == 0) {
663 rc = -EINVAL;
664 goto out;
665 }
666
667 /* Choose the highest speed at or below 'rate' with same PLL. */
668 if (reason != SETRATE_CPUFREQ
669 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
670 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
671 tgt_s--;
672 }
673
674 if (strt_s->pll != ACPU_PLL_TCXO)
675 plls_enabled |= 1 << strt_s->pll;
676
677 if (reason == SETRATE_CPUFREQ) {
678 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530679 rc = clk_enable(pll_clk[tgt_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700680 if (rc < 0) {
681 pr_err("PLL%d enable failed (%d)\n",
682 tgt_s->pll, rc);
683 goto out;
684 }
685 plls_enabled |= 1 << tgt_s->pll;
686 }
687 }
688 /* Need to do this when coming out of power collapse since some modem
689 * firmwares reset the VDD when the application processor enters power
690 * collapse. */
691 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
692 /* Increase VDD if needed. */
693 if (tgt_s->vdd > cur_s->vdd) {
694 rc = acpuclk_set_vdd_level(tgt_s->vdd);
695 if (rc < 0) {
696 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
697 goto out;
698 }
699 }
700 }
701
702 /* Set wait states for CPU inbetween frequency changes */
703 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
704 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
705 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
706
707 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
708 strt_s->a11clk_khz, tgt_s->a11clk_khz);
709
Kaushal Kumar86473f02012-06-28 19:35:58 +0530710 delta = abs((int)(strt_s->a11clk_khz - tgt_s->a11clk_khz));
711
712 if (dynamic_reprogram) {
713 if (tgt_s->pll == ACPU_PLL_4) {
714 if (strt_s->pll == ACPU_PLL_4 ||
715 delta > drv_state.max_speed_delta_khz) {
716 /*
717 * Enable the backup PLL if required
718 * and switch to it.
719 */
720 clk_enable(pll_clk[backup_s->pll].clk);
721 acpuclk_set_div(backup_s);
722 }
723 /* Make sure PLL4 is off before reprogramming */
724 if ((plls_enabled & (1 << tgt_s->pll))) {
725 clk_disable(pll_clk[tgt_s->pll].clk);
726 plls_enabled &= (0 << tgt_s->pll);
727 }
728 acpuclk_config_pll4(tgt_s->pll_rate);
729 pll_clk[tgt_s->pll].clk->rate = tgt_s->a11clk_khz*1000;
730
731 } else if (strt_s->pll == ACPU_PLL_4) {
732 if (delta > drv_state.max_speed_delta_khz) {
733 /*
734 * Enable the bcackup PLL if required
735 * and switch to it.
736 */
737 clk_enable(pll_clk[backup_s->pll].clk);
738 acpuclk_set_div(backup_s);
739 }
740 }
741
742 if (!(plls_enabled & (1 << tgt_s->pll))) {
743 rc = clk_enable(pll_clk[tgt_s->pll].clk);
744 if (rc < 0) {
745 pr_err("PLL%d enable failed (%d)\n",
746 tgt_s->pll, rc);
747 goto out;
748 }
749 plls_enabled |= 1 << tgt_s->pll;
750 }
751 acpuclk_set_div(tgt_s);
752 drv_state.current_speed = tgt_s;
753 /* Re-adjust lpj for the new clock speed. */
754 update_jiffies(cpu, cur_s->lpj);
755
756 /* Disable the backup PLL */
757 if ((delta > drv_state.max_speed_delta_khz)
758 || (strt_s->pll == ACPU_PLL_4 &&
759 tgt_s->pll == ACPU_PLL_4))
Trilok Sonieec9dd52012-08-04 14:51:28 +0530760 clk_disable(pll_clk[backup_s->pll].clk);
Kaushal Kumar86473f02012-06-28 19:35:58 +0530761
762 goto done;
763 }
764
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700765 while (cur_s != tgt_s) {
766 /*
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530767 * Always jump to target freq if within max_speed_delta_khz,
768 * regardless of PLL. If differnece is greater, use the
769 * predefined steppings in the table.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700770 */
771 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
772 if (d > drv_state.max_speed_delta_khz) {
773
774 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
775 /* Step up: jump to target PLL as early as
776 * possible so indexing using TCXO (up[-1])
777 * never occurs. */
778 if (likely(cur_s->up[tgt_s->pll]))
779 cur_s = cur_s->up[tgt_s->pll];
780 else
781 cur_s = cur_s->up[cur_s->pll];
782 } else {
783 /* Step down: stay on current PLL as long as
784 * possible so indexing using TCXO (down[-1])
785 * never occurs. */
786 if (likely(cur_s->down[cur_s->pll]))
787 cur_s = cur_s->down[cur_s->pll];
788 else
789 cur_s = cur_s->down[tgt_s->pll];
790 }
791
792 if (cur_s == NULL) { /* This should not happen. */
793 pr_err("No stepping frequencies found. "
794 "strt_s:%u tgt_s:%u\n",
795 strt_s->a11clk_khz, tgt_s->a11clk_khz);
796 rc = -EINVAL;
797 goto out;
798 }
799
800 } else {
801 cur_s = tgt_s;
802 }
803
804 pr_debug("STEP khz = %u, pll = %d\n",
805 cur_s->a11clk_khz, cur_s->pll);
806
807 if (cur_s->pll != ACPU_PLL_TCXO
808 && !(plls_enabled & (1 << cur_s->pll))) {
Trilok Soni57c07782012-05-07 16:52:16 +0530809 rc = clk_enable(pll_clk[cur_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700810 if (rc < 0) {
811 pr_err("PLL%d enable failed (%d)\n",
812 cur_s->pll, rc);
813 goto out;
814 }
815 plls_enabled |= 1 << cur_s->pll;
816 }
817
818 acpuclk_set_div(cur_s);
819 drv_state.current_speed = cur_s;
Taniya Dasc43e6872012-03-21 16:41:14 +0530820 /* Re-adjust lpj for the new clock speed. */
Kaushal Kumar86473f02012-06-28 19:35:58 +0530821 update_jiffies(cpu, cur_s->lpj);
Taniya Dasc43e6872012-03-21 16:41:14 +0530822
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700823 }
Kaushal Kumar86473f02012-06-28 19:35:58 +0530824done:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700825 /* Nothing else to do for SWFI. */
826 if (reason == SETRATE_SWFI)
827 goto out;
828
829 /* Change the AXI bus frequency if we can. */
830 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
831 res = clk_set_rate(drv_state.ebi1_clk,
832 tgt_s->axiclk_khz * 1000);
833 if (res < 0)
834 pr_warning("Setting AXI min rate failed (%d)\n", res);
835 }
836
837 /* Disable PLLs we are not using anymore. */
838 if (tgt_s->pll != ACPU_PLL_TCXO)
839 plls_enabled &= ~(1 << tgt_s->pll);
840 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
Pankaj Kumar3912c982011-12-07 16:59:03 +0530841 if (plls_enabled & (1 << pll))
Trilok Soni57c07782012-05-07 16:52:16 +0530842 clk_disable(pll_clk[pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700843
844 /* Nothing else to do for power collapse. */
845 if (reason == SETRATE_PC)
846 goto out;
847
848 /* Drop VDD level if we can. */
849 if (tgt_s->vdd < strt_s->vdd) {
850 res = acpuclk_set_vdd_level(tgt_s->vdd);
851 if (res < 0)
852 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
853 }
854
855 pr_debug("ACPU speed change complete\n");
856out:
857 if (reason == SETRATE_CPUFREQ)
858 mutex_unlock(&drv_state.lock);
859 return rc;
860}
861
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700862static void __devinit acpuclk_hw_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700863{
864 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530865 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700866 int res;
867
868 /*
Trilok Soni57c07782012-05-07 16:52:16 +0530869 * Prepare all the PLLs because we enable/disable them
870 * from atomic context and can't always ensure they're
871 * all prepared in non-atomic context. Same goes for
872 * ebi1_acpu_clk.
873 */
874 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_0].clk));
875 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_1].clk));
876 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_2].clk));
877 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_4].clk));
878 BUG_ON(clk_prepare(drv_state.ebi1_clk));
879
880 /*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700881 * Determine the rate of ACPU clock
882 */
883
884 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
885 /* CLK_SRC0_SEL */
886 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
887 /* CLK_SRC0_DIV */
888 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
889 } else {
890 /* CLK_SRC1_SEL */
891 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
892 /* CLK_SRC1_DIV */
893 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
894 }
895
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700896 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
897 if (speed->a11clk_src_sel == sel
898 && (speed->a11clk_src_div == div))
899 break;
900 }
901 if (speed->a11clk_khz == 0) {
902 pr_err("Error - ACPU clock reports invalid speed\n");
903 return;
904 }
905
906 drv_state.current_speed = speed;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530907 if (speed->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530908 if (clk_enable(pll_clk[speed->pll].clk))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 pr_warning("Failed to vote for boot PLL\n");
Pankaj Kumar3912c982011-12-07 16:59:03 +0530910 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911
Trilok Soni7d6c8652011-07-14 15:35:07 +0530912 /* Fix div2 to 2 for 7x27/5a(aa) targets */
913 if (!cpu_is_msm7x27()) {
914 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
915 reg_clksel &= ~(0x3 << 14);
916 reg_clksel |= (0x1 << 14);
917 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
918 }
919
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700920 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
921 if (res < 0)
922 pr_warning("Setting AXI min rate failed (%d)\n", res);
Trilok Soni57c07782012-05-07 16:52:16 +0530923 res = clk_enable(drv_state.ebi1_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700924 if (res < 0)
925 pr_warning("Enabling AXI clock failed (%d)\n", res);
926
927 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
928}
929
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530930static unsigned long acpuclk_7627_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700931{
932 WARN_ONCE(drv_state.current_speed == NULL,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700933 "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700934 if (drv_state.current_speed)
935 return drv_state.current_speed->a11clk_khz;
936 else
937 return 0;
938}
939
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700940/*----------------------------------------------------------------------------
941 * Clock driver initialization
942 *---------------------------------------------------------------------------*/
Pankaj Kumar3912c982011-12-07 16:59:03 +0530943#define MHZ 1000000
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700944static void __devinit select_freq_plan(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700945{
Pankaj Kumar3912c982011-12-07 16:59:03 +0530946 unsigned long pll_mhz[ACPU_PLL_END];
Kaushal Kumar86473f02012-06-28 19:35:58 +0530947 struct pll_freq_tbl_map *t = acpu_freq_tbl_list;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530948 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949
Pankaj Kumar3912c982011-12-07 16:59:03 +0530950 /* Get PLL clocks */
951 for (i = 0; i < ACPU_PLL_END; i++) {
952 if (pll_clk[i].name) {
953 pll_clk[i].clk = clk_get_sys("acpu", pll_clk[i].name);
954 if (IS_ERR(pll_clk[i].clk)) {
955 pll_mhz[i] = 0;
956 continue;
957 }
958 /* Get PLL's Rate */
959 pll_mhz[i] = clk_get_rate(pll_clk[i].clk)/MHZ;
960 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700961 }
962
Pankaj Kumar3912c982011-12-07 16:59:03 +0530963 /*
964 * For the pll configuration used in acpuclock table e.g.
965 * pll0_960_pll1_245_pll2_1200" is same for 7627 and
966 * 7625a (as pll0,pll1,pll2) having same rates, but frequency
967 * table is different for both targets.
968 *
969 * Hence below for loop will not be able to select correct
970 * table based on PLL rates as rates are same. Hence we need
971 * to add this cpu check for selecting the correct acpuclock table.
972 */
Trilok Soni54d35c42011-07-14 17:47:50 +0530973 if (cpu_is_msm7x25a()) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530974 if (pll_mhz[ACPU_PLL_1] == 245) {
Trilok Soni54d35c42011-07-14 17:47:50 +0530975 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530976 pll0_960_pll1_245_pll2_1200_25a;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530977 } else if (pll_mhz[ACPU_PLL_1] == 737) {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530978 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530979 pll0_960_pll1_737_pll2_1200_25a;
Trilok Soni54d35c42011-07-14 17:47:50 +0530980 }
Trilok Sonia5639902012-08-05 16:49:07 +0530981 t->tbl = acpu_freq_tbl;
982 }
983
984 /*
985 * 1008Mhz table selection based on the Lvalue of the PLL
986 * is conflicting with the 7627AA and 8625 v1.0 1GHz parts
987 * since v2.0 8625 chips are using different clock plan based
988 * reprogramming method.
989 */
990 if (cpu_is_msm8625() &&
991 (SOCINFO_VERSION_MAJOR(socinfo_get_version()) >= 2) &&
992 pll_mhz[ACPU_PLL_4] == 1008) {
993
994 if (pll_mhz[ACPU_PLL_2] == 245)
995 acpu_freq_tbl =
996 pll0_960_pll1_245_pll2_1200_pll4_1008_2p0;
997 else
998 acpu_freq_tbl =
999 pll0_960_pll1_196_pll2_1200_pll4_1008_2p0;
1000 t->tbl = acpu_freq_tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +05301001 } else {
1002 /* Select the right table to use. */
Kaushal Kumar86473f02012-06-28 19:35:58 +05301003 for (; t->tbl != 0; t++) {
Pankaj Kumar3912c982011-12-07 16:59:03 +05301004 if (t->pll0_rate == pll_mhz[ACPU_PLL_0]
1005 && t->pll1_rate == pll_mhz[ACPU_PLL_1]
1006 && t->pll2_rate == pll_mhz[ACPU_PLL_2]
1007 && t->pll4_rate == pll_mhz[ACPU_PLL_4]) {
1008 acpu_freq_tbl = t->tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +05301009 break;
1010 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001011 }
1012 }
1013
Trilok Soni3f33ffc2012-08-03 20:14:04 +05301014 if (acpu_freq_tbl == NULL) {
1015 pr_crit("Unknown PLL configuration!\n");
1016 BUG();
1017 }
1018
Kaushal Kumar86473f02012-06-28 19:35:58 +05301019 /*
Trilok Soni3f33ffc2012-08-03 20:14:04 +05301020 * Turn ON the dynamic reprogramming method
1021 * if one of the table entry has pll_rate defined.
1022 */
1023 for ( ; t->tbl->a11clk_khz; t->tbl++) {
1024 if (t->tbl->pll_rate) {
1025 if (!dynamic_reprogram) {
1026 dynamic_reprogram = 1;
1027 pr_info("Dynamic reprogramming is ON\n");
1028 }
1029 }
1030 }
1031
1032 /*
Kaushal Kumar86473f02012-06-28 19:35:58 +05301033 * Also find the backup pll used during PLL4 reprogramming.
1034 * We are using PLL2@600MHz as backup PLL, since 800MHz jump
1035 * is fine.
1036 */
Trilok Soni3f33ffc2012-08-03 20:14:04 +05301037 if (dynamic_reprogram) {
1038 for (t->tbl = acpu_freq_tbl; t->tbl->a11clk_khz; t->tbl++) {
Kaushal Kumar86473f02012-06-28 19:35:58 +05301039 if (t->tbl->pll == ACPU_PLL_2 &&
1040 t->tbl->a11clk_src_div == 1) {
1041 backup_s = t->tbl;
1042 break;
1043 }
1044 }
1045 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001046}
1047
1048/*
1049 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
1050 * before entering a wait for irq low-power mode. Find a suitable rate.
1051 */
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001052static unsigned long __devinit find_wait_for_irq_khz(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001053{
1054 unsigned long found_khz = 0;
1055 int i;
1056
1057 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
1058 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
1059 found_khz = acpu_freq_tbl[i].a11clk_khz;
1060
1061 return found_khz;
1062}
1063
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001064static void __devinit lpj_init(void)
Taniya Dasc43e6872012-03-21 16:41:14 +05301065{
1066 int i = 0, cpu;
1067 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
1068 unsigned long loops;
1069
1070 for_each_possible_cpu(cpu) {
1071#ifdef CONFIG_SMP
1072 loops = per_cpu(cpu_data, cpu).loops_per_jiffy;
1073#else
1074 loops = loops_per_jiffy;
1075#endif
1076 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1077 acpu_freq_tbl[i].lpj = cpufreq_scale(
1078 loops,
1079 base_clk->a11clk_khz,
1080 acpu_freq_tbl[i].a11clk_khz);
1081 }
1082 }
1083}
1084
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001085static void __devinit precompute_stepping(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001086{
1087 int i, step_idx;
1088
1089#define cur_freq acpu_freq_tbl[i].a11clk_khz
1090#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
1091#define cur_pll acpu_freq_tbl[i].pll
1092#define step_pll acpu_freq_tbl[step_idx].pll
1093
1094 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1095
1096 /* Calculate max "up" step for each destination PLL */
1097 step_idx = i + 1;
1098 while (step_freq && (step_freq - cur_freq)
1099 <= drv_state.max_speed_delta_khz) {
1100 acpu_freq_tbl[i].up[step_pll] =
1101 &acpu_freq_tbl[step_idx];
1102 step_idx++;
1103 }
1104 if (step_idx == (i + 1) && step_freq) {
1105 pr_crit("Delta between freqs %u KHz and %u KHz is"
1106 " too high!\n", cur_freq, step_freq);
1107 BUG();
1108 }
1109
1110 /* Calculate max "down" step for each destination PLL */
1111 step_idx = i - 1;
1112 while (step_idx >= 0 && (cur_freq - step_freq)
1113 <= drv_state.max_speed_delta_khz) {
1114 acpu_freq_tbl[i].down[step_pll] =
1115 &acpu_freq_tbl[step_idx];
1116 step_idx--;
1117 }
1118 if (step_idx == (i - 1) && i > 0) {
1119 pr_crit("Delta between freqs %u KHz and %u KHz is"
1120 " too high!\n", cur_freq, step_freq);
1121 BUG();
1122 }
1123 }
1124}
1125
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001126static void __devinit print_acpu_freq_tbl(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001127{
1128 struct clkctl_acpu_speed *t;
1129 short down_idx[ACPU_PLL_END];
1130 short up_idx[ACPU_PLL_END];
1131 int i, j;
1132
1133#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
1134 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
1135 "D0 D1 D2 D4 U0 U1 U2 U4\n");
1136
1137 t = &acpu_freq_tbl[0];
1138 for (i = 0; t->a11clk_khz != 0; i++) {
1139
1140 for (j = 0; j < ACPU_PLL_END; j++) {
1141 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
1142 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
1143 }
1144
1145 pr_info("%2d %7d %3d %3d %7d %4d %7d "
1146 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
1147 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
1148 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
1149 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
1150 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
1151
1152 t++;
1153 }
1154}
1155
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001156
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301157static struct acpuclk_data acpuclk_7627_data = {
1158 .set_rate = acpuclk_7627_set_rate,
1159 .get_rate = acpuclk_7627_get_rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001160 .power_collapse_khz = POWER_COLLAPSE_KHZ,
Matt Wagantallec57f062011-08-16 23:54:46 -07001161 .switch_time_us = 50,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001162};
1163
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001164static int __devinit acpuclk_7627_probe(struct platform_device *pdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001165{
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001166 const struct acpuclk_pdata *pdata = pdev->dev.platform_data;
1167
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001168 pr_info("%s()\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001169
1170 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
1171 BUG_ON(IS_ERR(drv_state.ebi1_clk));
1172
1173 mutex_init(&drv_state.lock);
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001174 drv_state.max_speed_delta_khz = pdata->max_speed_delta_khz;
Pankaj Kumar3912c982011-12-07 16:59:03 +05301175 select_freq_plan();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301176 acpuclk_7627_data.wait_for_irq_khz = find_wait_for_irq_khz();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177 precompute_stepping();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001178 acpuclk_hw_init();
Taniya Dasc43e6872012-03-21 16:41:14 +05301179 lpj_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001180 print_acpu_freq_tbl();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301181 acpuclk_register(&acpuclk_7627_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001182
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001183#ifdef CONFIG_CPU_FREQ_MSM
1184 cpufreq_table_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001185#endif
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001186 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001187}
Matt Wagantallec57f062011-08-16 23:54:46 -07001188
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001189static struct platform_driver acpuclk_7627_driver = {
1190 .probe = acpuclk_7627_probe,
1191 .driver = {
1192 .name = "acpuclk-7627",
1193 .owner = THIS_MODULE,
1194 },
Matt Wagantallec57f062011-08-16 23:54:46 -07001195};
1196
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001197static int __init acpuclk_7627_init(void)
1198{
1199 return platform_driver_register(&acpuclk_7627_driver);
1200}
1201postcore_initcall(acpuclk_7627_init);
Kaushal Kumar86473f02012-06-28 19:35:58 +05301202