blob: d0b81b0b9ced6211ef2fadbe90b299587e6a8e2e [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 Truong790f06d2013-02-13 16:38:12 -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 Wagantall33d01f52012-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[] = {
Trilok Soni2c2ec162012-10-15 17:54:23 +053088 [0] = { 36, 1, 2 }, /* 700.8 MHz */
89 [1] = { 52, 1, 2 }, /* 1008 MHz */
90 [2] = { 63, 0, 1 }, /* 1209.6 MHz */
91 [3] = { 73, 0, 1 }, /* 1401.6 MHz */
92 [4] = { 60, 0, 1 }, /* 1152 MHz */
Trilok Soni4a0be012012-10-16 16:26:24 +053093 [5] = { 57, 1, 2 }, /* 1104 MHz */
Kaushal Kumar86473f02012-06-28 19:35:58 +053094};
95
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070096struct clock_state {
97 struct clkctl_acpu_speed *current_speed;
98 struct mutex lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099 uint32_t max_speed_delta_khz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700100 struct clk *ebi1_clk;
101};
102
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103struct clkctl_acpu_speed {
104 unsigned int use_for_scaling;
105 unsigned int a11clk_khz;
106 int pll;
107 unsigned int a11clk_src_sel;
108 unsigned int a11clk_src_div;
109 unsigned int ahbclk_khz;
110 unsigned int ahbclk_div;
111 int vdd;
112 unsigned int axiclk_khz;
Kaushal Kumar86473f02012-06-28 19:35:58 +0530113 struct pll_config *pll_rate;
Taniya Dasc43e6872012-03-21 16:41:14 +0530114 unsigned long lpj; /* loops_per_jiffy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700115 /* Pointers in acpu_freq_tbl[] for max up/down steppings. */
116 struct clkctl_acpu_speed *down[ACPU_PLL_END];
117 struct clkctl_acpu_speed *up[ACPU_PLL_END];
118};
119
Kaushal Kumar86473f02012-06-28 19:35:58 +0530120static bool dynamic_reprogram;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121static struct clock_state drv_state = { 0 };
122static struct clkctl_acpu_speed *acpu_freq_tbl;
123
Kaushal Kumar86473f02012-06-28 19:35:58 +0530124/* Switch to this when reprogramming PLL4 */
125static struct clkctl_acpu_speed *backup_s;
126
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127/*
128 * ACPU freq tables used for different PLLs frequency combinations. The
129 * correct table is selected during init.
130 *
131 * Table stepping up/down entries are calculated during boot to choose the
132 * largest frequency jump that's less than max_speed_delta_khz on each PLL.
133 */
134
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530135/* 7627 with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700136static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = {
137 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
138 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
139 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
140 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
141 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530142 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
143 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
144 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
145 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530146 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147};
148
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530149/* 7627 with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = {
151 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
152 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
153 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
154 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
155 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530156 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
157 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
158 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
159 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530160 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700161};
162
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530163/* 7627 with GSM capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = {
165 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
166 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
167 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
168 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 },
169 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530170 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
171 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
172 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
173 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530174 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175};
176
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530177/* 7627 with CDMA capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = {
179 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
180 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
181 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
182 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
183 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530184 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
185 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
186 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
187 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530188 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189};
190
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530191/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530193 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
194 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
195 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
196 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530197 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530198 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
199 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
200 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530201 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530202 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530203 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204};
205
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530206/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700207static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530208 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
209 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
210 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
211 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Trilok Soniabb750b2011-07-13 16:47:18 +0530212 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
213 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
214 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
215 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530216 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530217 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530218 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219};
220
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530221/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Sonif597e242011-06-06 12:37:16 +0530222static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = {
223 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
224 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
225 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
226 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530227 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonif597e242011-06-06 12:37:16 +0530228 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
229 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530230 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
231 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Sonif597e242011-06-06 12:37:16 +0530232 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530233 { 0 }
Trilok Sonif597e242011-06-06 12:37:16 +0530234};
235
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530236/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Sonid7b05e52011-08-17 18:09:08 +0530237static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008[] = {
238 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
239 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
240 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
241 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530242 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530243 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
244 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530245 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
246 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530247 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530248 { 0 }
Trilok Sonid7b05e52011-08-17 18:09:08 +0530249};
250
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530251/* 8625 PLL4 @ 1209MHz with GSM capable modem */
252static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1209[] = {
253 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
Trilok Soni266a1502012-08-03 20:25:48 +0530254 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 0, 61440 },
255 { 0, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 1, 61440 },
256 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
257 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 2, 122880 },
258 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
259 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
260 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
261 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
262 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
263 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530264 { 0 }
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530265};
266
267/* 8625 PLL4 @ 1209MHz with CDMA capable modem */
268static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1209[] = {
269 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
270 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
Trilok Soni55b7af92012-10-15 18:21:51 +0530271 { 0, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 1, 49152 },
272 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 1, 98304 },
Trilok Soni266a1502012-08-03 20:25:48 +0530273 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
274 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
275 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
276 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
277 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
278 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530279 { 0 }
280};
281
282/* 8625 PLL4 @ 1401.6MHz with GSM capable modem */
283static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1401[] = {
284 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
285 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 0, 61440 },
286 { 0, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 1, 61440 },
287 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
288 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 2, 122880 },
289 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
290 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
291 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
292 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
293 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
294 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
295 { 1, 1401600, ACPU_PLL_4, 6, 0, 175000, 3, 7, 200000, &pll4_cfg_tbl[3]},
296 { 0 }
297};
298
299/* 8625 PLL4 @ 1401.6MHz with CDMA capable modem */
300static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1401[] = {
301 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
302 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
Trilok Soni55b7af92012-10-15 18:21:51 +0530303 { 0, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 1, 49152 },
304 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 1, 98304 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530305 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
306 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
307 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
308 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
309 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
310 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
311 { 1, 1401600, ACPU_PLL_4, 6, 0, 175000, 3, 7, 200000, &pll4_cfg_tbl[3]},
312 { 0 }
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530313};
314
Trilok Soni72cacdb2012-10-15 17:58:57 +0530315/* 8625 PLL4 @ 1008MHz with GSM capable modem */
Trilok Sonia5639902012-08-05 16:49:07 +0530316static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008_2p0[] = {
317 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
318 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 0, 61440 },
319 { 0, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 1, 61440 },
320 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
321 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 2, 122880 },
322 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
323 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
324 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
325 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
326 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
327 { 0 }
328};
329
Trilok Soni72cacdb2012-10-15 17:58:57 +0530330/* 8625 PLL4 @ 1008MHz with CDMA capable modem */
Trilok Sonia5639902012-08-05 16:49:07 +0530331static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008_2p0[] = {
332 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
333 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
Trilok Soni55b7af92012-10-15 18:21:51 +0530334 { 0, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 1, 49152 },
335 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 1, 98304 },
Trilok Sonia5639902012-08-05 16:49:07 +0530336 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
337 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
338 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
339 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
340 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
341 { 0 }
342};
343
Trilok Soni4a0be012012-10-16 16:26:24 +0530344/* 8625 PLL4 @ 1104MHz with GSM capable modem with v2.0 plan */
345static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1104[] = {
346 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
347 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
348 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
349 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
350 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
351 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
352 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
353 { 1, 1104000, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[5]},
354 { 0 }
355};
356
357/* 8625 PLL4 @ 1104MHz with CDMA capable modem with v2.0 plan */
358static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1104[] = {
359 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
360 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 1, 98304 },
361 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
362 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
363 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
364 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
365 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
366 { 1, 1104000, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[5]},
367 { 0 }
368};
369
Trilok Soni2c2ec162012-10-15 17:54:23 +0530370/* 8625 PLL4 @ 1152MHz with GSM capable modem with v2.0 plan */
Trilok Soni48631722012-05-17 20:56:42 +0530371static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1152[] = {
372 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
Trilok Soni2c2ec162012-10-15 17:54:23 +0530373 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
374 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
375 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
376 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
377 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
378 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
379 { 1, 1152000, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[4]},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530380 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530381};
382
Trilok Soni2c2ec162012-10-15 17:54:23 +0530383/* 8625 PLL4 @ 1115MHz with CDMA capable modem with v2.0 plan */
Trilok Soni48631722012-05-17 20:56:42 +0530384static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1152[] = {
385 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
Trilok Soni2c2ec162012-10-15 17:54:23 +0530386 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 1, 98304 },
387 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
388 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
389 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
390 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
391 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
392 { 1, 1152000, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[4]},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530393 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530394};
395
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530396/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530397static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_25a[] = {
Trilok Soni54d35c42011-07-14 17:47:50 +0530398 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
399 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
400 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
401 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530402 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530403 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530404 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530405 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
406 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530407 { 0 }
Trilok Soni54d35c42011-07-14 17:47:50 +0530408};
409
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530410/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530411static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = {
412 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
413 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
414 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
415 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530416 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530417 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
418 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
419 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530420 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530421 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530422 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530423};
424
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530425/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530426static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = {
427 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
428 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
429 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
430 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
431 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
432 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
433 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
434 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530435 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530436 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530437 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530438};
439
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530440/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530441static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = {
442 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
443 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
444 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
445 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530446 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530447 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
448 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530449 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
450 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530451 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530452 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530453};
454
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530455/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530456static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = {
457 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
458 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
459 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
460 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530461 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530462 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
463 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530464 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
465 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530466 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530467 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530468};
469
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530470/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530471static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_25a[] = {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530472 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
473 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
474 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
475 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530476 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530477 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530478 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530479 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
480 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530481 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530482};
483
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700484#define PLL_CONFIG(m0, m1, m2, m4) { \
Pankaj Kumar3912c982011-12-07 16:59:03 +0530485 m0, m1, m2, m4, \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700486 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
487}
488
489struct pll_freq_tbl_map {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530490 unsigned int pll0_rate;
491 unsigned int pll1_rate;
492 unsigned int pll2_rate;
493 unsigned int pll4_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700494 struct clkctl_acpu_speed *tbl;
495};
496
497static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700498 PLL_CONFIG(960, 196, 1200, 0),
499 PLL_CONFIG(960, 245, 1200, 0),
500 PLL_CONFIG(960, 196, 800, 0),
501 PLL_CONFIG(960, 245, 800, 0),
502 PLL_CONFIG(960, 245, 1200, 800),
503 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530504 PLL_CONFIG(960, 245, 1200, 1008),
Trilok Sonid7b05e52011-08-17 18:09:08 +0530505 PLL_CONFIG(960, 196, 1200, 1008),
Trilok Soni9bb022c2011-10-31 18:25:19 +0530506 PLL_CONFIG(960, 737, 1200, 800),
507 PLL_CONFIG(960, 589, 1200, 800),
508 PLL_CONFIG(960, 737, 1200, 1008),
509 PLL_CONFIG(960, 589, 1200, 1008),
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530510 PLL_CONFIG(960, 245, 1200, 1209),
511 PLL_CONFIG(960, 196, 1200, 1209),
Trilok Soni48631722012-05-17 20:56:42 +0530512 PLL_CONFIG(960, 245, 1200, 1152),
513 PLL_CONFIG(960, 196, 1200, 1152),
Trilok Soni4a0be012012-10-16 16:26:24 +0530514 PLL_CONFIG(960, 245, 1200, 1104),
515 PLL_CONFIG(960, 196, 1200, 1104),
Kaushal Kumar86473f02012-06-28 19:35:58 +0530516 PLL_CONFIG(960, 245, 1200, 1401),
517 PLL_CONFIG(960, 196, 1200, 1401),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700518 { 0, 0, 0, 0, 0 }
519};
520
521#ifdef CONFIG_CPU_FREQ_MSM
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530522static struct cpufreq_frequency_table freq_table[NR_CPUS][20];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700523
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700524static void __devinit cpufreq_table_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525{
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530526 int cpu;
527 for_each_possible_cpu(cpu) {
528 unsigned int i, freq_cnt = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700529
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530530 /* Construct the freq_table table from acpu_freq_tbl since
531 * the freq_table values need to match frequencies specified
532 * in acpu_freq_tbl and acpu_freq_tbl needs to be fixed up
533 * during init.
534 */
535 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
536 && freq_cnt < ARRAY_SIZE(*freq_table)-1; i++) {
537 if (acpu_freq_tbl[i].use_for_scaling) {
538 freq_table[cpu][freq_cnt].index = freq_cnt;
539 freq_table[cpu][freq_cnt].frequency
540 = acpu_freq_tbl[i].a11clk_khz;
541 freq_cnt++;
542 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700543 }
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530544
545 /* freq_table not big enough to store all usable freqs. */
546 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
547
548 freq_table[cpu][freq_cnt].index = freq_cnt;
549 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
550 /* Register table with CPUFreq. */
551 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
552 pr_info("CPU%d: %d scaling frequencies supported.\n",
553 cpu, freq_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700554 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700555}
556#endif
557
Kaushal Kumar86473f02012-06-28 19:35:58 +0530558static void update_jiffies(int cpu, unsigned long loops)
559{
560#ifdef CONFIG_SMP
561 for_each_possible_cpu(cpu) {
562 per_cpu(cpu_data, cpu).loops_per_jiffy =
563 loops;
564 }
565#endif
566 /* Adjust the global one */
567 loops_per_jiffy = loops;
568}
569
570/* Assumes PLL4 is off and the acpuclock isn't sourced from PLL4 */
571static void acpuclk_config_pll4(struct pll_config *pll)
572{
573 /* Make sure write to disable PLL_4 has completed
574 * before reconfiguring that PLL. */
575 mb();
576 writel_relaxed(pll->l, PLL4_L_VAL_ADDR);
577 writel_relaxed(pll->m, PLL4_M_VAL_ADDR);
578 writel_relaxed(pll->n, PLL4_N_VAL_ADDR);
579 /* Make sure PLL is programmed before returning. */
580 mb();
581}
582
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583static int acpuclk_set_vdd_level(int vdd)
584{
585 uint32_t current_vdd;
586
Pankaj Kumar9406a3b2011-12-23 18:07:15 +0530587 /*
588 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
589 * VDD switching support.
590 */
591 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
592 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
593 return 0;
594
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700595 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
596
597 pr_debug("Switching VDD from %u mV -> %d mV\n",
598 current_vdd, vdd);
599
600 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
601 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700602 udelay(62);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700603 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
604 pr_err("VDD set failed\n");
605 return -EIO;
606 }
607
608 pr_debug("VDD switched\n");
609
610 return 0;
611}
612
613/* Set proper dividers for the given clock speed. */
614static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
615{
616 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
617
618 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
619
620 /* AHB_CLK_DIV */
621 clk_div = (reg_clksel >> 1) & 0x03;
622 /* CLK_SEL_SRC1NO */
623 src_sel = reg_clksel & 1;
624
625 /*
626 * If the new clock divider is higher than the previous, then
627 * program the divider before switching the clock
628 */
629 if (hunt_s->ahbclk_div > clk_div) {
630 reg_clksel &= ~(0x3 << 1);
631 reg_clksel |= (hunt_s->ahbclk_div << 1);
632 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
633 }
634
635 /* Program clock source and divider */
636 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
637 reg_clkctl &= ~(0xFF << (8 * src_sel));
638 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
639 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
640 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
641
642 /* Program clock source selection */
643 reg_clksel ^= 1;
644 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
645
Pankaj Kumard66a919a2012-04-11 19:35:38 +0530646 /* Wait for the clock switch to complete */
647 mb();
648 udelay(50);
649
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700650 /*
651 * If the new clock divider is lower than the previous, then
652 * program the divider after switching the clock
653 */
654 if (hunt_s->ahbclk_div < clk_div) {
655 reg_clksel &= ~(0x3 << 1);
656 reg_clksel |= (hunt_s->ahbclk_div << 1);
657 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
658 }
659}
660
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530661static int acpuclk_7627_set_rate(int cpu, unsigned long rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700662 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700663{
664 uint32_t reg_clkctl;
665 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
666 int res, rc = 0;
667 unsigned int plls_enabled = 0, pll;
Kaushal Kumar86473f02012-06-28 19:35:58 +0530668 int delta;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700669
670 if (reason == SETRATE_CPUFREQ)
671 mutex_lock(&drv_state.lock);
672
673 strt_s = cur_s = drv_state.current_speed;
674
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700675 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676 if (cur_s == NULL) {
677 rc = -ENOENT;
678 goto out;
679 }
680
681 if (rate == cur_s->a11clk_khz)
682 goto out;
683
684 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
685 if (tgt_s->a11clk_khz == rate)
686 break;
687 }
688
689 if (tgt_s->a11clk_khz == 0) {
690 rc = -EINVAL;
691 goto out;
692 }
693
694 /* Choose the highest speed at or below 'rate' with same PLL. */
695 if (reason != SETRATE_CPUFREQ
696 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
697 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
698 tgt_s--;
699 }
700
701 if (strt_s->pll != ACPU_PLL_TCXO)
702 plls_enabled |= 1 << strt_s->pll;
703
704 if (reason == SETRATE_CPUFREQ) {
705 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530706 rc = clk_enable(pll_clk[tgt_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700707 if (rc < 0) {
708 pr_err("PLL%d enable failed (%d)\n",
709 tgt_s->pll, rc);
710 goto out;
711 }
712 plls_enabled |= 1 << tgt_s->pll;
713 }
714 }
715 /* Need to do this when coming out of power collapse since some modem
716 * firmwares reset the VDD when the application processor enters power
717 * collapse. */
718 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
719 /* Increase VDD if needed. */
720 if (tgt_s->vdd > cur_s->vdd) {
721 rc = acpuclk_set_vdd_level(tgt_s->vdd);
722 if (rc < 0) {
723 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
724 goto out;
725 }
726 }
727 }
728
729 /* Set wait states for CPU inbetween frequency changes */
730 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
731 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
732 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
733
734 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
735 strt_s->a11clk_khz, tgt_s->a11clk_khz);
736
Kaushal Kumar86473f02012-06-28 19:35:58 +0530737 delta = abs((int)(strt_s->a11clk_khz - tgt_s->a11clk_khz));
738
739 if (dynamic_reprogram) {
740 if (tgt_s->pll == ACPU_PLL_4) {
741 if (strt_s->pll == ACPU_PLL_4 ||
742 delta > drv_state.max_speed_delta_khz) {
743 /*
744 * Enable the backup PLL if required
745 * and switch to it.
746 */
747 clk_enable(pll_clk[backup_s->pll].clk);
748 acpuclk_set_div(backup_s);
Trilok Soni613d2d82012-09-25 01:58:20 +0530749 update_jiffies(cpu, backup_s->lpj);
Kaushal Kumar86473f02012-06-28 19:35:58 +0530750 }
751 /* Make sure PLL4 is off before reprogramming */
752 if ((plls_enabled & (1 << tgt_s->pll))) {
753 clk_disable(pll_clk[tgt_s->pll].clk);
Trilok Soni8c239d72012-09-14 13:42:37 +0530754 plls_enabled &= ~(1 << tgt_s->pll);
Kaushal Kumar86473f02012-06-28 19:35:58 +0530755 }
756 acpuclk_config_pll4(tgt_s->pll_rate);
757 pll_clk[tgt_s->pll].clk->rate = tgt_s->a11clk_khz*1000;
758
759 } else if (strt_s->pll == ACPU_PLL_4) {
760 if (delta > drv_state.max_speed_delta_khz) {
761 /*
762 * Enable the bcackup PLL if required
763 * and switch to it.
764 */
765 clk_enable(pll_clk[backup_s->pll].clk);
766 acpuclk_set_div(backup_s);
Trilok Soni613d2d82012-09-25 01:58:20 +0530767 update_jiffies(cpu, backup_s->lpj);
Kaushal Kumar86473f02012-06-28 19:35:58 +0530768 }
769 }
770
Trilok Soni1163e8c2012-09-17 14:31:04 +0530771 if ((tgt_s->pll != ACPU_PLL_TCXO) &&
772 !(plls_enabled & (1 << tgt_s->pll))) {
Kaushal Kumar86473f02012-06-28 19:35:58 +0530773 rc = clk_enable(pll_clk[tgt_s->pll].clk);
774 if (rc < 0) {
775 pr_err("PLL%d enable failed (%d)\n",
776 tgt_s->pll, rc);
777 goto out;
778 }
779 plls_enabled |= 1 << tgt_s->pll;
780 }
781 acpuclk_set_div(tgt_s);
782 drv_state.current_speed = tgt_s;
783 /* Re-adjust lpj for the new clock speed. */
Trilok Sonif113db42012-10-17 22:20:23 +0530784 update_jiffies(cpu, tgt_s->lpj);
Kaushal Kumar86473f02012-06-28 19:35:58 +0530785
786 /* Disable the backup PLL */
787 if ((delta > drv_state.max_speed_delta_khz)
788 || (strt_s->pll == ACPU_PLL_4 &&
789 tgt_s->pll == ACPU_PLL_4))
Trilok Sonieec9dd52012-08-04 14:51:28 +0530790 clk_disable(pll_clk[backup_s->pll].clk);
Kaushal Kumar86473f02012-06-28 19:35:58 +0530791
792 goto done;
793 }
794
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700795 while (cur_s != tgt_s) {
796 /*
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530797 * Always jump to target freq if within max_speed_delta_khz,
798 * regardless of PLL. If differnece is greater, use the
799 * predefined steppings in the table.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800 */
801 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
802 if (d > drv_state.max_speed_delta_khz) {
803
804 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
805 /* Step up: jump to target PLL as early as
806 * possible so indexing using TCXO (up[-1])
807 * never occurs. */
808 if (likely(cur_s->up[tgt_s->pll]))
809 cur_s = cur_s->up[tgt_s->pll];
810 else
811 cur_s = cur_s->up[cur_s->pll];
812 } else {
813 /* Step down: stay on current PLL as long as
814 * possible so indexing using TCXO (down[-1])
815 * never occurs. */
816 if (likely(cur_s->down[cur_s->pll]))
817 cur_s = cur_s->down[cur_s->pll];
818 else
819 cur_s = cur_s->down[tgt_s->pll];
820 }
821
822 if (cur_s == NULL) { /* This should not happen. */
823 pr_err("No stepping frequencies found. "
824 "strt_s:%u tgt_s:%u\n",
825 strt_s->a11clk_khz, tgt_s->a11clk_khz);
826 rc = -EINVAL;
827 goto out;
828 }
829
830 } else {
831 cur_s = tgt_s;
832 }
833
834 pr_debug("STEP khz = %u, pll = %d\n",
835 cur_s->a11clk_khz, cur_s->pll);
836
837 if (cur_s->pll != ACPU_PLL_TCXO
838 && !(plls_enabled & (1 << cur_s->pll))) {
Trilok Soni57c07782012-05-07 16:52:16 +0530839 rc = clk_enable(pll_clk[cur_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700840 if (rc < 0) {
841 pr_err("PLL%d enable failed (%d)\n",
842 cur_s->pll, rc);
843 goto out;
844 }
845 plls_enabled |= 1 << cur_s->pll;
846 }
847
848 acpuclk_set_div(cur_s);
849 drv_state.current_speed = cur_s;
Taniya Dasc43e6872012-03-21 16:41:14 +0530850 /* Re-adjust lpj for the new clock speed. */
Kaushal Kumar86473f02012-06-28 19:35:58 +0530851 update_jiffies(cpu, cur_s->lpj);
Taniya Dasc43e6872012-03-21 16:41:14 +0530852
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700853 }
Kaushal Kumar86473f02012-06-28 19:35:58 +0530854done:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855 /* Nothing else to do for SWFI. */
856 if (reason == SETRATE_SWFI)
857 goto out;
858
859 /* Change the AXI bus frequency if we can. */
Trilok Soni89ddd222012-10-11 15:06:57 +0530860 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700861 res = clk_set_rate(drv_state.ebi1_clk,
862 tgt_s->axiclk_khz * 1000);
863 if (res < 0)
864 pr_warning("Setting AXI min rate failed (%d)\n", res);
865 }
866
867 /* Disable PLLs we are not using anymore. */
868 if (tgt_s->pll != ACPU_PLL_TCXO)
869 plls_enabled &= ~(1 << tgt_s->pll);
870 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
Pankaj Kumar3912c982011-12-07 16:59:03 +0530871 if (plls_enabled & (1 << pll))
Trilok Soni57c07782012-05-07 16:52:16 +0530872 clk_disable(pll_clk[pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700873
874 /* Nothing else to do for power collapse. */
875 if (reason == SETRATE_PC)
876 goto out;
877
878 /* Drop VDD level if we can. */
879 if (tgt_s->vdd < strt_s->vdd) {
880 res = acpuclk_set_vdd_level(tgt_s->vdd);
881 if (res < 0)
882 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
883 }
884
885 pr_debug("ACPU speed change complete\n");
886out:
887 if (reason == SETRATE_CPUFREQ)
888 mutex_unlock(&drv_state.lock);
889 return rc;
890}
891
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700892static void __devinit acpuclk_hw_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700893{
894 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530895 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700896 int res;
897
898 /*
Trilok Soni57c07782012-05-07 16:52:16 +0530899 * Prepare all the PLLs because we enable/disable them
900 * from atomic context and can't always ensure they're
901 * all prepared in non-atomic context. Same goes for
902 * ebi1_acpu_clk.
903 */
904 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_0].clk));
905 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_1].clk));
906 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_2].clk));
907 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_4].clk));
908 BUG_ON(clk_prepare(drv_state.ebi1_clk));
909
910 /*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700911 * Determine the rate of ACPU clock
912 */
913
914 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
915 /* CLK_SRC0_SEL */
916 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
917 /* CLK_SRC0_DIV */
918 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
919 } else {
920 /* CLK_SRC1_SEL */
921 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
922 /* CLK_SRC1_DIV */
923 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
924 }
925
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700926 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
927 if (speed->a11clk_src_sel == sel
928 && (speed->a11clk_src_div == div))
929 break;
930 }
931 if (speed->a11clk_khz == 0) {
932 pr_err("Error - ACPU clock reports invalid speed\n");
933 return;
934 }
935
936 drv_state.current_speed = speed;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530937 if (speed->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530938 if (clk_enable(pll_clk[speed->pll].clk))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700939 pr_warning("Failed to vote for boot PLL\n");
Pankaj Kumar3912c982011-12-07 16:59:03 +0530940 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700941
Trilok Soni7d6c8652011-07-14 15:35:07 +0530942 /* Fix div2 to 2 for 7x27/5a(aa) targets */
943 if (!cpu_is_msm7x27()) {
944 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
945 reg_clksel &= ~(0x3 << 14);
946 reg_clksel |= (0x1 << 14);
947 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
948 }
949
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700950 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
951 if (res < 0)
952 pr_warning("Setting AXI min rate failed (%d)\n", res);
Trilok Soni57c07782012-05-07 16:52:16 +0530953 res = clk_enable(drv_state.ebi1_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700954 if (res < 0)
955 pr_warning("Enabling AXI clock failed (%d)\n", res);
956
957 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
958}
959
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530960static unsigned long acpuclk_7627_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700961{
962 WARN_ONCE(drv_state.current_speed == NULL,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700963 "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700964 if (drv_state.current_speed)
965 return drv_state.current_speed->a11clk_khz;
966 else
967 return 0;
968}
969
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700970/*----------------------------------------------------------------------------
971 * Clock driver initialization
972 *---------------------------------------------------------------------------*/
Pankaj Kumar3912c982011-12-07 16:59:03 +0530973#define MHZ 1000000
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700974static void __devinit select_freq_plan(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700975{
Pankaj Kumar3912c982011-12-07 16:59:03 +0530976 unsigned long pll_mhz[ACPU_PLL_END];
Kaushal Kumar86473f02012-06-28 19:35:58 +0530977 struct pll_freq_tbl_map *t = acpu_freq_tbl_list;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530978 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700979
Pankaj Kumar3912c982011-12-07 16:59:03 +0530980 /* Get PLL clocks */
981 for (i = 0; i < ACPU_PLL_END; i++) {
982 if (pll_clk[i].name) {
983 pll_clk[i].clk = clk_get_sys("acpu", pll_clk[i].name);
984 if (IS_ERR(pll_clk[i].clk)) {
985 pll_mhz[i] = 0;
986 continue;
987 }
988 /* Get PLL's Rate */
989 pll_mhz[i] = clk_get_rate(pll_clk[i].clk)/MHZ;
990 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700991 }
992
Pankaj Kumar3912c982011-12-07 16:59:03 +0530993 /*
994 * For the pll configuration used in acpuclock table e.g.
995 * pll0_960_pll1_245_pll2_1200" is same for 7627 and
996 * 7625a (as pll0,pll1,pll2) having same rates, but frequency
997 * table is different for both targets.
998 *
999 * Hence below for loop will not be able to select correct
1000 * table based on PLL rates as rates are same. Hence we need
1001 * to add this cpu check for selecting the correct acpuclock table.
1002 */
Trilok Soni54d35c42011-07-14 17:47:50 +05301003 if (cpu_is_msm7x25a()) {
Pankaj Kumar3912c982011-12-07 16:59:03 +05301004 if (pll_mhz[ACPU_PLL_1] == 245) {
Trilok Soni54d35c42011-07-14 17:47:50 +05301005 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +05301006 pll0_960_pll1_245_pll2_1200_25a;
Pankaj Kumar3912c982011-12-07 16:59:03 +05301007 } else if (pll_mhz[ACPU_PLL_1] == 737) {
Trilok Soni9bb022c2011-10-31 18:25:19 +05301008 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +05301009 pll0_960_pll1_737_pll2_1200_25a;
Trilok Soni54d35c42011-07-14 17:47:50 +05301010 }
Trilok Sonia5639902012-08-05 16:49:07 +05301011 t->tbl = acpu_freq_tbl;
1012 }
1013
1014 /*
1015 * 1008Mhz table selection based on the Lvalue of the PLL
Trilok Soni72cacdb2012-10-15 17:58:57 +05301016 * is conflicting with the 7627AA 1GHz parts since 8625 chips
1017 * are using different clock plan based reprogramming method.
Trilok Sonia5639902012-08-05 16:49:07 +05301018 */
Trilok Soni72cacdb2012-10-15 17:58:57 +05301019 if (cpu_is_msm8625() && pll_mhz[ACPU_PLL_4] == 1008) {
Trilok Sonia5639902012-08-05 16:49:07 +05301020 if (pll_mhz[ACPU_PLL_2] == 245)
1021 acpu_freq_tbl =
1022 pll0_960_pll1_245_pll2_1200_pll4_1008_2p0;
1023 else
1024 acpu_freq_tbl =
1025 pll0_960_pll1_196_pll2_1200_pll4_1008_2p0;
1026 t->tbl = acpu_freq_tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +05301027 } else {
1028 /* Select the right table to use. */
Kaushal Kumar86473f02012-06-28 19:35:58 +05301029 for (; t->tbl != 0; t++) {
Pankaj Kumar3912c982011-12-07 16:59:03 +05301030 if (t->pll0_rate == pll_mhz[ACPU_PLL_0]
1031 && t->pll1_rate == pll_mhz[ACPU_PLL_1]
1032 && t->pll2_rate == pll_mhz[ACPU_PLL_2]
1033 && t->pll4_rate == pll_mhz[ACPU_PLL_4]) {
1034 acpu_freq_tbl = t->tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +05301035 break;
1036 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001037 }
1038 }
1039
Trilok Soni3f33ffc2012-08-03 20:14:04 +05301040 if (acpu_freq_tbl == NULL) {
1041 pr_crit("Unknown PLL configuration!\n");
1042 BUG();
1043 }
1044
Kaushal Kumar86473f02012-06-28 19:35:58 +05301045 /*
Trilok Soni3f33ffc2012-08-03 20:14:04 +05301046 * Turn ON the dynamic reprogramming method
1047 * if one of the table entry has pll_rate defined.
1048 */
1049 for ( ; t->tbl->a11clk_khz; t->tbl++) {
1050 if (t->tbl->pll_rate) {
1051 if (!dynamic_reprogram) {
1052 dynamic_reprogram = 1;
1053 pr_info("Dynamic reprogramming is ON\n");
1054 }
1055 }
1056 }
1057
1058 /*
Kaushal Kumar86473f02012-06-28 19:35:58 +05301059 * Also find the backup pll used during PLL4 reprogramming.
1060 * We are using PLL2@600MHz as backup PLL, since 800MHz jump
1061 * is fine.
1062 */
Trilok Soni3f33ffc2012-08-03 20:14:04 +05301063 if (dynamic_reprogram) {
1064 for (t->tbl = acpu_freq_tbl; t->tbl->a11clk_khz; t->tbl++) {
Kaushal Kumar86473f02012-06-28 19:35:58 +05301065 if (t->tbl->pll == ACPU_PLL_2 &&
1066 t->tbl->a11clk_src_div == 1) {
1067 backup_s = t->tbl;
1068 break;
1069 }
1070 }
1071 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001072}
1073
1074/*
1075 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
1076 * before entering a wait for irq low-power mode. Find a suitable rate.
1077 */
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001078static unsigned long __devinit find_wait_for_irq_khz(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001079{
1080 unsigned long found_khz = 0;
1081 int i;
1082
1083 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
1084 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
1085 found_khz = acpu_freq_tbl[i].a11clk_khz;
1086
1087 return found_khz;
1088}
1089
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001090static void __devinit lpj_init(void)
Taniya Dasc43e6872012-03-21 16:41:14 +05301091{
1092 int i = 0, cpu;
1093 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
1094 unsigned long loops;
1095
1096 for_each_possible_cpu(cpu) {
1097#ifdef CONFIG_SMP
1098 loops = per_cpu(cpu_data, cpu).loops_per_jiffy;
1099#else
1100 loops = loops_per_jiffy;
1101#endif
1102 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1103 acpu_freq_tbl[i].lpj = cpufreq_scale(
1104 loops,
1105 base_clk->a11clk_khz,
1106 acpu_freq_tbl[i].a11clk_khz);
1107 }
1108 }
1109}
1110
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001111static void __devinit precompute_stepping(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001112{
1113 int i, step_idx;
1114
1115#define cur_freq acpu_freq_tbl[i].a11clk_khz
1116#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
1117#define cur_pll acpu_freq_tbl[i].pll
1118#define step_pll acpu_freq_tbl[step_idx].pll
1119
1120 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1121
1122 /* Calculate max "up" step for each destination PLL */
1123 step_idx = i + 1;
1124 while (step_freq && (step_freq - cur_freq)
1125 <= drv_state.max_speed_delta_khz) {
1126 acpu_freq_tbl[i].up[step_pll] =
1127 &acpu_freq_tbl[step_idx];
1128 step_idx++;
1129 }
1130 if (step_idx == (i + 1) && step_freq) {
1131 pr_crit("Delta between freqs %u KHz and %u KHz is"
1132 " too high!\n", cur_freq, step_freq);
1133 BUG();
1134 }
1135
1136 /* Calculate max "down" step for each destination PLL */
1137 step_idx = i - 1;
1138 while (step_idx >= 0 && (cur_freq - step_freq)
1139 <= drv_state.max_speed_delta_khz) {
1140 acpu_freq_tbl[i].down[step_pll] =
1141 &acpu_freq_tbl[step_idx];
1142 step_idx--;
1143 }
1144 if (step_idx == (i - 1) && i > 0) {
1145 pr_crit("Delta between freqs %u KHz and %u KHz is"
1146 " too high!\n", cur_freq, step_freq);
1147 BUG();
1148 }
1149 }
1150}
1151
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001152static void __devinit print_acpu_freq_tbl(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001153{
1154 struct clkctl_acpu_speed *t;
1155 short down_idx[ACPU_PLL_END];
1156 short up_idx[ACPU_PLL_END];
1157 int i, j;
1158
1159#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
1160 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
1161 "D0 D1 D2 D4 U0 U1 U2 U4\n");
1162
1163 t = &acpu_freq_tbl[0];
1164 for (i = 0; t->a11clk_khz != 0; i++) {
1165
1166 for (j = 0; j < ACPU_PLL_END; j++) {
1167 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
1168 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
1169 }
1170
1171 pr_info("%2d %7d %3d %3d %7d %4d %7d "
1172 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
1173 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
1174 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
1175 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
1176 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
1177
1178 t++;
1179 }
1180}
1181
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001182
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301183static struct acpuclk_data acpuclk_7627_data = {
1184 .set_rate = acpuclk_7627_set_rate,
1185 .get_rate = acpuclk_7627_get_rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001186 .power_collapse_khz = POWER_COLLAPSE_KHZ,
Matt Wagantallec57f062011-08-16 23:54:46 -07001187 .switch_time_us = 50,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001188};
1189
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001190static int __devinit acpuclk_7627_probe(struct platform_device *pdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001191{
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001192 const struct acpuclk_pdata *pdata = pdev->dev.platform_data;
1193
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001194 pr_info("%s()\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195
1196 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
1197 BUG_ON(IS_ERR(drv_state.ebi1_clk));
1198
1199 mutex_init(&drv_state.lock);
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001200 drv_state.max_speed_delta_khz = pdata->max_speed_delta_khz;
Pankaj Kumar3912c982011-12-07 16:59:03 +05301201 select_freq_plan();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301202 acpuclk_7627_data.wait_for_irq_khz = find_wait_for_irq_khz();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001203 precompute_stepping();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001204 acpuclk_hw_init();
Taniya Dasc43e6872012-03-21 16:41:14 +05301205 lpj_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206 print_acpu_freq_tbl();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301207 acpuclk_register(&acpuclk_7627_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001208
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001209#ifdef CONFIG_CPU_FREQ_MSM
1210 cpufreq_table_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001211#endif
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001212 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001213}
Matt Wagantallec57f062011-08-16 23:54:46 -07001214
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001215static struct platform_driver acpuclk_7627_driver = {
1216 .probe = acpuclk_7627_probe,
1217 .driver = {
1218 .name = "acpuclk-7627",
1219 .owner = THIS_MODULE,
1220 },
Matt Wagantallec57f062011-08-16 23:54:46 -07001221};
1222
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001223static int __init acpuclk_7627_init(void)
1224{
1225 return platform_driver_register(&acpuclk_7627_driver);
1226}
1227postcore_initcall(acpuclk_7627_init);
Kaushal Kumar86473f02012-06-28 19:35:58 +05301228