blob: 140bb024c1453bfb802b498794b02a6c1c17d2f8 [file] [log] [blame]
Matt Wagantalld1af38e2011-08-06 01:38:02 -07001/*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 * MSM architecture clock driver
3 *
4 * Copyright (C) 2007 Google, Inc.
Pankaj Kumarc9136b32012-01-02 18:46:13 +05305 * Copyright (c) 2007-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006 * Author: San Mehat <san@android.com>
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/version.h>
20#include <linux/kernel.h>
Matt Wagantallbf430eb2012-03-22 11:45:49 -070021#include <linux/module.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#include <linux/init.h>
23#include <linux/errno.h>
24#include <linux/string.h>
25#include <linux/delay.h>
26#include <linux/clk.h>
27#include <linux/cpufreq.h>
28#include <linux/mutex.h>
29#include <linux/io.h>
30#include <linux/sort.h>
Matt Wagantallbf430eb2012-03-22 11:45:49 -070031#include <linux/platform_device.h>
32
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033#include <mach/board.h>
34#include <mach/msm_iomap.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035#include <mach/socinfo.h>
Taniya Dasc43e6872012-03-21 16:41:14 +053036#include <asm/mach-types.h>
37#include <asm/cpu.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039#include "smd_private.h"
40#include "acpuclock.h"
Kaushal Kumar86473f02012-06-28 19:35:58 +053041#include "clock.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
44#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
45#define A11S_VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046
Kaushal Kumar86473f02012-06-28 19:35:58 +053047#define PLL4_L_VAL_ADDR (MSM_CLK_CTL_BASE + 0x378)
48#define PLL4_M_VAL_ADDR (MSM_CLK_CTL_BASE + 0x37C)
49#define PLL4_N_VAL_ADDR (MSM_CLK_CTL_BASE + 0x380)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050
Matt Wagantall6d9ebee2011-08-26 12:15:24 -070051#define POWER_COLLAPSE_KHZ 19200
52
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053/* Max CPU frequency allowed by hardware while in standby waiting for an irq. */
54#define MAX_WAIT_FOR_IRQ_KHZ 128000
55
Pankaj Kumar3912c982011-12-07 16:59:03 +053056/**
57 * enum - For acpuclock PLL IDs
58 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059enum {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060 ACPU_PLL_0 = 0,
61 ACPU_PLL_1,
62 ACPU_PLL_2,
63 ACPU_PLL_3,
64 ACPU_PLL_4,
Pankaj Kumar0249bed2012-03-08 15:20:54 +053065 ACPU_PLL_TCXO,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 ACPU_PLL_END,
67};
68
Pankaj Kumar3912c982011-12-07 16:59:03 +053069struct acpu_clk_src {
70 struct clk *clk;
71 const char *name;
72};
73
Kaushal Kumar86473f02012-06-28 19:35:58 +053074struct pll_config {
75 unsigned int l;
76 unsigned int m;
77 unsigned int n;
78};
79
Pankaj Kumar3912c982011-12-07 16:59:03 +053080static struct acpu_clk_src pll_clk[ACPU_PLL_END] = {
81 [ACPU_PLL_0] = { .name = "pll0_clk" },
82 [ACPU_PLL_1] = { .name = "pll1_clk" },
83 [ACPU_PLL_2] = { .name = "pll2_clk" },
84 [ACPU_PLL_4] = { .name = "pll4_clk" },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085};
86
Kaushal Kumar86473f02012-06-28 19:35:58 +053087static struct pll_config pll4_cfg_tbl[] = {
88 { 36, 1, 2 }, /* 700.8 MHz */
89 { 52, 1, 2 }, /* 1008 MHz */
90 { 63, 0, 1 }, /* 1209.6 MHz */
91 { 73, 0, 1 }, /* 1401.6 MHz */
92};
93
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094struct clock_state {
95 struct clkctl_acpu_speed *current_speed;
96 struct mutex lock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097 uint32_t max_speed_delta_khz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098 struct clk *ebi1_clk;
99};
100
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700101struct clkctl_acpu_speed {
102 unsigned int use_for_scaling;
103 unsigned int a11clk_khz;
104 int pll;
105 unsigned int a11clk_src_sel;
106 unsigned int a11clk_src_div;
107 unsigned int ahbclk_khz;
108 unsigned int ahbclk_div;
109 int vdd;
110 unsigned int axiclk_khz;
Kaushal Kumar86473f02012-06-28 19:35:58 +0530111 struct pll_config *pll_rate;
Taniya Dasc43e6872012-03-21 16:41:14 +0530112 unsigned long lpj; /* loops_per_jiffy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700113 /* Pointers in acpu_freq_tbl[] for max up/down steppings. */
114 struct clkctl_acpu_speed *down[ACPU_PLL_END];
115 struct clkctl_acpu_speed *up[ACPU_PLL_END];
116};
117
Kaushal Kumar86473f02012-06-28 19:35:58 +0530118static bool dynamic_reprogram;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700119static struct clock_state drv_state = { 0 };
120static struct clkctl_acpu_speed *acpu_freq_tbl;
121
Kaushal Kumar86473f02012-06-28 19:35:58 +0530122/* Switch to this when reprogramming PLL4 */
123static struct clkctl_acpu_speed *backup_s;
124
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125/*
126 * ACPU freq tables used for different PLLs frequency combinations. The
127 * correct table is selected during init.
128 *
129 * Table stepping up/down entries are calculated during boot to choose the
130 * largest frequency jump that's less than max_speed_delta_khz on each PLL.
131 */
132
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530133/* 7627 with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700134static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = {
135 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
136 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
137 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
138 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 },
139 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530140 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
141 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
142 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
143 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530144 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700145};
146
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530147/* 7627 with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = {
149 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
150 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
151 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
152 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
153 { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530154 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
155 { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 160000 },
156 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
157 { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530158 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159};
160
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530161/* 7627 with GSM capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = {
163 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 },
164 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 },
165 { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 },
166 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 },
167 { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530168 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
169 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
170 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
171 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530172 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700173};
174
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530175/* 7627 with CDMA capable modem - PLL2 @ 800 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = {
177 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 },
178 { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 },
179 { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 },
180 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 },
181 { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 },
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530182 { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 160000 },
183 { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 160000 },
184 { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 160000 },
185 { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530186 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187};
188
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530189/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530191 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
192 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
193 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
194 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530195 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530196 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
197 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
198 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530199 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530200 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530201 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202};
203
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530204/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = {
Trilok Soni7d6c8652011-07-14 15:35:07 +0530206 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
207 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
208 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
209 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Trilok Soniabb750b2011-07-13 16:47:18 +0530210 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
211 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
212 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
213 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530214 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni7d6c8652011-07-14 15:35:07 +0530215 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530216 { 0 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217};
218
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530219/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Sonif597e242011-06-06 12:37:16 +0530220static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = {
221 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
222 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
223 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
224 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530225 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonif597e242011-06-06 12:37:16 +0530226 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
227 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530228 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
229 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Sonif597e242011-06-06 12:37:16 +0530230 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530231 { 0 }
Trilok Sonif597e242011-06-06 12:37:16 +0530232};
233
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530234/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Sonid7b05e52011-08-17 18:09:08 +0530235static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008[] = {
236 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
237 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
238 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
239 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530240 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530241 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
242 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530243 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
244 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Sonid7b05e52011-08-17 18:09:08 +0530245 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530246 { 0 }
Trilok Sonid7b05e52011-08-17 18:09:08 +0530247};
248
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530249/* 8625 PLL4 @ 1209MHz with GSM capable modem */
250static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1209[] = {
251 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
252 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
253 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
254 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
255 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
256 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530257 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
258 { 0, 604800, ACPU_PLL_4, 6, 1, 75600, 3, 6, 160000 },
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530259 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530260 { 0 }
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530261};
262
263/* 8625 PLL4 @ 1209MHz with CDMA capable modem */
264static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1209[] = {
265 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
266 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
267 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
268 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
269 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
270 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530271 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
272 { 0, 604800, ACPU_PLL_4, 6, 1, 75600, 3, 6, 160000 },
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530273 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530274 { 0 }
275};
276
277/* 8625 PLL4 @ 1401.6MHz with GSM capable modem */
278static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1401[] = {
279 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
280 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 0, 61440 },
281 { 0, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 1, 61440 },
282 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 1, 61440 },
283 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 2, 122880 },
284 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
285 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
286 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
287 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
288 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
289 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
290 { 1, 1401600, ACPU_PLL_4, 6, 0, 175000, 3, 7, 200000, &pll4_cfg_tbl[3]},
291 { 0 }
292};
293
294/* 8625 PLL4 @ 1401.6MHz with CDMA capable modem */
295static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1401[] = {
296 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
297 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
298 { 0, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
299 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
300 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 2, 122880 },
301 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 3, 122880 },
302 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 4, 160000 },
303 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, 4, 160000, &pll4_cfg_tbl[0]},
304 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 5, 200000, &pll4_cfg_tbl[1]},
305 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, 6, 200000, &pll4_cfg_tbl[2]},
306 { 1, 1401600, ACPU_PLL_4, 6, 0, 175000, 3, 7, 200000, &pll4_cfg_tbl[3]},
307 { 0 }
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530308};
309
Trilok Soni48631722012-05-17 20:56:42 +0530310/* 8625 PLL4 @ 1152MHz with GSM capable modem */
311static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1152[] = {
312 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
313 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
314 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
315 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
316 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
317 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
318 { 0, 576000, ACPU_PLL_4, 6, 1, 72000, 3, 6, 160000 },
319 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
320 { 1, 1152000, ACPU_PLL_4, 6, 0, 144000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530321 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530322};
323
324/* 8625 PLL4 @ 1115MHz with CDMA capable modem */
325static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1152[] = {
326 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
327 { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 },
328 { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 },
329 { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 },
330 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
331 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
332 { 0, 576000, ACPU_PLL_4, 6, 1, 72000, 3, 6, 160000 },
333 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
334 { 1, 1152000, ACPU_PLL_4, 6, 0, 144000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530335 { 0 }
Trilok Soni48631722012-05-17 20:56:42 +0530336};
337
338
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530339/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530340static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_25a[] = {
Trilok Soni54d35c42011-07-14 17:47:50 +0530341 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
342 { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 },
343 { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 },
344 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530345 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530346 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530347 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni54d35c42011-07-14 17:47:50 +0530348 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
349 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530350 { 0 }
Trilok Soni54d35c42011-07-14 17:47:50 +0530351};
352
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530353/* 7627a PLL2 @ 1200MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530354static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = {
355 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
356 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
357 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
358 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530359 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530360 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
361 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 },
362 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530363 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530364 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530365 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530366};
367
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530368/* 7627a PLL2 @ 1200MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530369static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = {
370 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
371 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
372 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
373 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
374 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 },
375 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 },
376 { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 },
377 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530378 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530379 { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530380 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530381};
382
Pankaj Kumar714c5cc2012-01-05 13:14:38 +0530383/* 7627aa PLL4 @ 1008MHz with GSM capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530384static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = {
385 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
386 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
387 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
388 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530389 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530390 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
391 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530392 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
393 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530394 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530395 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530396};
397
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530398/* 7627aa PLL4 @ 1008MHz with CDMA capable modem */
Trilok Soni9bb022c2011-10-31 18:25:19 +0530399static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = {
400 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 },
401 { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 },
402 { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 },
403 { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530404 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530405 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
406 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
Pankaj Kumar501e14e2012-04-10 14:51:41 +0530407 { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 160000 },
408 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 160000 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530409 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000},
Kaushal Kumar86473f02012-06-28 19:35:58 +0530410 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530411};
412
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530413/* 7625a PLL2 @ 1200MHz with GSM capable modem */
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530414static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_25a[] = {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530415 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
416 { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 },
417 { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 },
418 { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 },
Pankaj Kumar2764fe72012-02-23 00:53:28 +0530419 { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530420 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 },
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530421 { 0, 400000, ACPU_PLL_2, 2, 2, 50000, 3, 4, 122880 },
Trilok Soni9bb022c2011-10-31 18:25:19 +0530422 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 },
423 { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 },
Kaushal Kumar86473f02012-06-28 19:35:58 +0530424 { 0 }
Trilok Soni9bb022c2011-10-31 18:25:19 +0530425};
426
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700427#define PLL_CONFIG(m0, m1, m2, m4) { \
Pankaj Kumar3912c982011-12-07 16:59:03 +0530428 m0, m1, m2, m4, \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700429 pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \
430}
431
432struct pll_freq_tbl_map {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530433 unsigned int pll0_rate;
434 unsigned int pll1_rate;
435 unsigned int pll2_rate;
436 unsigned int pll4_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700437 struct clkctl_acpu_speed *tbl;
438};
439
440static struct pll_freq_tbl_map acpu_freq_tbl_list[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700441 PLL_CONFIG(960, 196, 1200, 0),
442 PLL_CONFIG(960, 245, 1200, 0),
443 PLL_CONFIG(960, 196, 800, 0),
444 PLL_CONFIG(960, 245, 800, 0),
445 PLL_CONFIG(960, 245, 1200, 800),
446 PLL_CONFIG(960, 196, 1200, 800),
Trilok Sonif597e242011-06-06 12:37:16 +0530447 PLL_CONFIG(960, 245, 1200, 1008),
Trilok Sonid7b05e52011-08-17 18:09:08 +0530448 PLL_CONFIG(960, 196, 1200, 1008),
Trilok Soni9bb022c2011-10-31 18:25:19 +0530449 PLL_CONFIG(960, 737, 1200, 800),
450 PLL_CONFIG(960, 589, 1200, 800),
451 PLL_CONFIG(960, 737, 1200, 1008),
452 PLL_CONFIG(960, 589, 1200, 1008),
Pankaj Kumar50c705c2012-01-10 12:02:07 +0530453 PLL_CONFIG(960, 245, 1200, 1209),
454 PLL_CONFIG(960, 196, 1200, 1209),
Trilok Soni48631722012-05-17 20:56:42 +0530455 PLL_CONFIG(960, 245, 1200, 1152),
456 PLL_CONFIG(960, 196, 1200, 1152),
Kaushal Kumar86473f02012-06-28 19:35:58 +0530457 PLL_CONFIG(960, 245, 1200, 1401),
458 PLL_CONFIG(960, 196, 1200, 1401),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700459 { 0, 0, 0, 0, 0 }
460};
461
462#ifdef CONFIG_CPU_FREQ_MSM
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530463static struct cpufreq_frequency_table freq_table[NR_CPUS][20];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700464
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700465static void __devinit cpufreq_table_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466{
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530467 int cpu;
468 for_each_possible_cpu(cpu) {
469 unsigned int i, freq_cnt = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700470
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530471 /* Construct the freq_table table from acpu_freq_tbl since
472 * the freq_table values need to match frequencies specified
473 * in acpu_freq_tbl and acpu_freq_tbl needs to be fixed up
474 * during init.
475 */
476 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
477 && freq_cnt < ARRAY_SIZE(*freq_table)-1; i++) {
478 if (acpu_freq_tbl[i].use_for_scaling) {
479 freq_table[cpu][freq_cnt].index = freq_cnt;
480 freq_table[cpu][freq_cnt].frequency
481 = acpu_freq_tbl[i].a11clk_khz;
482 freq_cnt++;
483 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700484 }
Pankaj Kumar873bc7a2011-12-21 17:25:44 +0530485
486 /* freq_table not big enough to store all usable freqs. */
487 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
488
489 freq_table[cpu][freq_cnt].index = freq_cnt;
490 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
491 /* Register table with CPUFreq. */
492 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
493 pr_info("CPU%d: %d scaling frequencies supported.\n",
494 cpu, freq_cnt);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700495 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700496}
497#endif
498
Kaushal Kumar86473f02012-06-28 19:35:58 +0530499static void update_jiffies(int cpu, unsigned long loops)
500{
501#ifdef CONFIG_SMP
502 for_each_possible_cpu(cpu) {
503 per_cpu(cpu_data, cpu).loops_per_jiffy =
504 loops;
505 }
506#endif
507 /* Adjust the global one */
508 loops_per_jiffy = loops;
509}
510
511/* Assumes PLL4 is off and the acpuclock isn't sourced from PLL4 */
512static void acpuclk_config_pll4(struct pll_config *pll)
513{
514 /* Make sure write to disable PLL_4 has completed
515 * before reconfiguring that PLL. */
516 mb();
517 writel_relaxed(pll->l, PLL4_L_VAL_ADDR);
518 writel_relaxed(pll->m, PLL4_M_VAL_ADDR);
519 writel_relaxed(pll->n, PLL4_N_VAL_ADDR);
520 /* Make sure PLL is programmed before returning. */
521 mb();
522}
523
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700524static int acpuclk_set_vdd_level(int vdd)
525{
526 uint32_t current_vdd;
527
Pankaj Kumar9406a3b2011-12-23 18:07:15 +0530528 /*
529 * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working
530 * VDD switching support.
531 */
532 if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) &&
533 (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1))
534 return 0;
535
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700536 current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
537
538 pr_debug("Switching VDD from %u mV -> %d mV\n",
539 current_vdd, vdd);
540
541 writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
542 mb();
Matt Wagantallec57f062011-08-16 23:54:46 -0700543 udelay(62);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700544 if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
545 pr_err("VDD set failed\n");
546 return -EIO;
547 }
548
549 pr_debug("VDD switched\n");
550
551 return 0;
552}
553
554/* Set proper dividers for the given clock speed. */
555static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
556{
557 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
558
559 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
560
561 /* AHB_CLK_DIV */
562 clk_div = (reg_clksel >> 1) & 0x03;
563 /* CLK_SEL_SRC1NO */
564 src_sel = reg_clksel & 1;
565
566 /*
567 * If the new clock divider is higher than the previous, then
568 * program the divider before switching the clock
569 */
570 if (hunt_s->ahbclk_div > clk_div) {
571 reg_clksel &= ~(0x3 << 1);
572 reg_clksel |= (hunt_s->ahbclk_div << 1);
573 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
574 }
575
576 /* Program clock source and divider */
577 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
578 reg_clkctl &= ~(0xFF << (8 * src_sel));
579 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
580 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
581 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
582
583 /* Program clock source selection */
584 reg_clksel ^= 1;
585 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
586
Pankaj Kumard66a9192012-04-11 19:35:38 +0530587 /* Wait for the clock switch to complete */
588 mb();
589 udelay(50);
590
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700591 /*
592 * If the new clock divider is lower than the previous, then
593 * program the divider after switching the clock
594 */
595 if (hunt_s->ahbclk_div < clk_div) {
596 reg_clksel &= ~(0x3 << 1);
597 reg_clksel |= (hunt_s->ahbclk_div << 1);
598 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
599 }
600}
601
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530602static int acpuclk_7627_set_rate(int cpu, unsigned long rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700603 enum setrate_reason reason)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700604{
605 uint32_t reg_clkctl;
606 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
607 int res, rc = 0;
608 unsigned int plls_enabled = 0, pll;
Kaushal Kumar86473f02012-06-28 19:35:58 +0530609 int delta;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700610
611 if (reason == SETRATE_CPUFREQ)
612 mutex_lock(&drv_state.lock);
613
614 strt_s = cur_s = drv_state.current_speed;
615
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700616 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700617 if (cur_s == NULL) {
618 rc = -ENOENT;
619 goto out;
620 }
621
622 if (rate == cur_s->a11clk_khz)
623 goto out;
624
625 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
626 if (tgt_s->a11clk_khz == rate)
627 break;
628 }
629
630 if (tgt_s->a11clk_khz == 0) {
631 rc = -EINVAL;
632 goto out;
633 }
634
635 /* Choose the highest speed at or below 'rate' with same PLL. */
636 if (reason != SETRATE_CPUFREQ
637 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
638 while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
639 tgt_s--;
640 }
641
642 if (strt_s->pll != ACPU_PLL_TCXO)
643 plls_enabled |= 1 << strt_s->pll;
644
645 if (reason == SETRATE_CPUFREQ) {
646 if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530647 rc = clk_enable(pll_clk[tgt_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700648 if (rc < 0) {
649 pr_err("PLL%d enable failed (%d)\n",
650 tgt_s->pll, rc);
651 goto out;
652 }
653 plls_enabled |= 1 << tgt_s->pll;
654 }
655 }
656 /* Need to do this when coming out of power collapse since some modem
657 * firmwares reset the VDD when the application processor enters power
658 * collapse. */
659 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
660 /* Increase VDD if needed. */
661 if (tgt_s->vdd > cur_s->vdd) {
662 rc = acpuclk_set_vdd_level(tgt_s->vdd);
663 if (rc < 0) {
664 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
665 goto out;
666 }
667 }
668 }
669
670 /* Set wait states for CPU inbetween frequency changes */
671 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
672 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
673 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
674
675 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
676 strt_s->a11clk_khz, tgt_s->a11clk_khz);
677
Kaushal Kumar86473f02012-06-28 19:35:58 +0530678 delta = abs((int)(strt_s->a11clk_khz - tgt_s->a11clk_khz));
679
680 if (dynamic_reprogram) {
681 if (tgt_s->pll == ACPU_PLL_4) {
682 if (strt_s->pll == ACPU_PLL_4 ||
683 delta > drv_state.max_speed_delta_khz) {
684 /*
685 * Enable the backup PLL if required
686 * and switch to it.
687 */
688 clk_enable(pll_clk[backup_s->pll].clk);
689 acpuclk_set_div(backup_s);
690 }
691 /* Make sure PLL4 is off before reprogramming */
692 if ((plls_enabled & (1 << tgt_s->pll))) {
693 clk_disable(pll_clk[tgt_s->pll].clk);
694 plls_enabled &= (0 << tgt_s->pll);
695 }
696 acpuclk_config_pll4(tgt_s->pll_rate);
697 pll_clk[tgt_s->pll].clk->rate = tgt_s->a11clk_khz*1000;
698
699 } else if (strt_s->pll == ACPU_PLL_4) {
700 if (delta > drv_state.max_speed_delta_khz) {
701 /*
702 * Enable the bcackup PLL if required
703 * and switch to it.
704 */
705 clk_enable(pll_clk[backup_s->pll].clk);
706 acpuclk_set_div(backup_s);
707 }
708 }
709
710 if (!(plls_enabled & (1 << tgt_s->pll))) {
711 rc = clk_enable(pll_clk[tgt_s->pll].clk);
712 if (rc < 0) {
713 pr_err("PLL%d enable failed (%d)\n",
714 tgt_s->pll, rc);
715 goto out;
716 }
717 plls_enabled |= 1 << tgt_s->pll;
718 }
719 acpuclk_set_div(tgt_s);
720 drv_state.current_speed = tgt_s;
721 /* Re-adjust lpj for the new clock speed. */
722 update_jiffies(cpu, cur_s->lpj);
723
724 /* Disable the backup PLL */
725 if ((delta > drv_state.max_speed_delta_khz)
726 || (strt_s->pll == ACPU_PLL_4 &&
727 tgt_s->pll == ACPU_PLL_4))
728 clk_disable_unprepare(pll_clk[backup_s->pll].clk);
729
730 goto done;
731 }
732
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700733 while (cur_s != tgt_s) {
734 /*
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530735 * Always jump to target freq if within max_speed_delta_khz,
736 * regardless of PLL. If differnece is greater, use the
737 * predefined steppings in the table.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700738 */
739 int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
740 if (d > drv_state.max_speed_delta_khz) {
741
742 if (tgt_s->a11clk_khz > cur_s->a11clk_khz) {
743 /* Step up: jump to target PLL as early as
744 * possible so indexing using TCXO (up[-1])
745 * never occurs. */
746 if (likely(cur_s->up[tgt_s->pll]))
747 cur_s = cur_s->up[tgt_s->pll];
748 else
749 cur_s = cur_s->up[cur_s->pll];
750 } else {
751 /* Step down: stay on current PLL as long as
752 * possible so indexing using TCXO (down[-1])
753 * never occurs. */
754 if (likely(cur_s->down[cur_s->pll]))
755 cur_s = cur_s->down[cur_s->pll];
756 else
757 cur_s = cur_s->down[tgt_s->pll];
758 }
759
760 if (cur_s == NULL) { /* This should not happen. */
761 pr_err("No stepping frequencies found. "
762 "strt_s:%u tgt_s:%u\n",
763 strt_s->a11clk_khz, tgt_s->a11clk_khz);
764 rc = -EINVAL;
765 goto out;
766 }
767
768 } else {
769 cur_s = tgt_s;
770 }
771
772 pr_debug("STEP khz = %u, pll = %d\n",
773 cur_s->a11clk_khz, cur_s->pll);
774
775 if (cur_s->pll != ACPU_PLL_TCXO
776 && !(plls_enabled & (1 << cur_s->pll))) {
Trilok Soni57c07782012-05-07 16:52:16 +0530777 rc = clk_enable(pll_clk[cur_s->pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700778 if (rc < 0) {
779 pr_err("PLL%d enable failed (%d)\n",
780 cur_s->pll, rc);
781 goto out;
782 }
783 plls_enabled |= 1 << cur_s->pll;
784 }
785
786 acpuclk_set_div(cur_s);
787 drv_state.current_speed = cur_s;
Taniya Dasc43e6872012-03-21 16:41:14 +0530788 /* Re-adjust lpj for the new clock speed. */
Kaushal Kumar86473f02012-06-28 19:35:58 +0530789 update_jiffies(cpu, cur_s->lpj);
Taniya Dasc43e6872012-03-21 16:41:14 +0530790
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700791 }
Kaushal Kumar86473f02012-06-28 19:35:58 +0530792done:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700793 /* Nothing else to do for SWFI. */
794 if (reason == SETRATE_SWFI)
795 goto out;
796
797 /* Change the AXI bus frequency if we can. */
798 if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
799 res = clk_set_rate(drv_state.ebi1_clk,
800 tgt_s->axiclk_khz * 1000);
801 if (res < 0)
802 pr_warning("Setting AXI min rate failed (%d)\n", res);
803 }
804
805 /* Disable PLLs we are not using anymore. */
806 if (tgt_s->pll != ACPU_PLL_TCXO)
807 plls_enabled &= ~(1 << tgt_s->pll);
808 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
Pankaj Kumar3912c982011-12-07 16:59:03 +0530809 if (plls_enabled & (1 << pll))
Trilok Soni57c07782012-05-07 16:52:16 +0530810 clk_disable(pll_clk[pll].clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811
812 /* Nothing else to do for power collapse. */
813 if (reason == SETRATE_PC)
814 goto out;
815
816 /* Drop VDD level if we can. */
817 if (tgt_s->vdd < strt_s->vdd) {
818 res = acpuclk_set_vdd_level(tgt_s->vdd);
819 if (res < 0)
820 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
821 }
822
823 pr_debug("ACPU speed change complete\n");
824out:
825 if (reason == SETRATE_CPUFREQ)
826 mutex_unlock(&drv_state.lock);
827 return rc;
828}
829
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700830static void __devinit acpuclk_hw_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700831{
832 struct clkctl_acpu_speed *speed;
Trilok Soni7d6c8652011-07-14 15:35:07 +0530833 uint32_t div, sel, reg_clksel;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700834 int res;
835
836 /*
Trilok Soni57c07782012-05-07 16:52:16 +0530837 * Prepare all the PLLs because we enable/disable them
838 * from atomic context and can't always ensure they're
839 * all prepared in non-atomic context. Same goes for
840 * ebi1_acpu_clk.
841 */
842 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_0].clk));
843 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_1].clk));
844 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_2].clk));
845 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_4].clk));
846 BUG_ON(clk_prepare(drv_state.ebi1_clk));
847
848 /*
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700849 * Determine the rate of ACPU clock
850 */
851
852 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
853 /* CLK_SRC0_SEL */
854 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
855 /* CLK_SRC0_DIV */
856 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
857 } else {
858 /* CLK_SRC1_SEL */
859 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
860 /* CLK_SRC1_DIV */
861 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
862 }
863
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700864 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
865 if (speed->a11clk_src_sel == sel
866 && (speed->a11clk_src_div == div))
867 break;
868 }
869 if (speed->a11clk_khz == 0) {
870 pr_err("Error - ACPU clock reports invalid speed\n");
871 return;
872 }
873
874 drv_state.current_speed = speed;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530875 if (speed->pll != ACPU_PLL_TCXO) {
Trilok Soni57c07782012-05-07 16:52:16 +0530876 if (clk_enable(pll_clk[speed->pll].clk))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700877 pr_warning("Failed to vote for boot PLL\n");
Pankaj Kumar3912c982011-12-07 16:59:03 +0530878 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700879
Trilok Soni7d6c8652011-07-14 15:35:07 +0530880 /* Fix div2 to 2 for 7x27/5a(aa) targets */
881 if (!cpu_is_msm7x27()) {
882 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
883 reg_clksel &= ~(0x3 << 14);
884 reg_clksel |= (0x1 << 14);
885 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
886 }
887
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700888 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
889 if (res < 0)
890 pr_warning("Setting AXI min rate failed (%d)\n", res);
Trilok Soni57c07782012-05-07 16:52:16 +0530891 res = clk_enable(drv_state.ebi1_clk);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700892 if (res < 0)
893 pr_warning("Enabling AXI clock failed (%d)\n", res);
894
895 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
896}
897
Pankaj Kumar6e66f372011-12-05 14:41:58 +0530898static unsigned long acpuclk_7627_get_rate(int cpu)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700899{
900 WARN_ONCE(drv_state.current_speed == NULL,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -0700901 "%s: not initialized\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 if (drv_state.current_speed)
903 return drv_state.current_speed->a11clk_khz;
904 else
905 return 0;
906}
907
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700908/*----------------------------------------------------------------------------
909 * Clock driver initialization
910 *---------------------------------------------------------------------------*/
Pankaj Kumar3912c982011-12-07 16:59:03 +0530911#define MHZ 1000000
Matt Wagantallbf430eb2012-03-22 11:45:49 -0700912static void __devinit select_freq_plan(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913{
Pankaj Kumar3912c982011-12-07 16:59:03 +0530914 unsigned long pll_mhz[ACPU_PLL_END];
Kaushal Kumar86473f02012-06-28 19:35:58 +0530915 struct pll_freq_tbl_map *t = acpu_freq_tbl_list;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530916 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700917
Pankaj Kumar3912c982011-12-07 16:59:03 +0530918 /* Get PLL clocks */
919 for (i = 0; i < ACPU_PLL_END; i++) {
920 if (pll_clk[i].name) {
921 pll_clk[i].clk = clk_get_sys("acpu", pll_clk[i].name);
922 if (IS_ERR(pll_clk[i].clk)) {
923 pll_mhz[i] = 0;
924 continue;
925 }
926 /* Get PLL's Rate */
927 pll_mhz[i] = clk_get_rate(pll_clk[i].clk)/MHZ;
928 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700929 }
930
Pankaj Kumar3912c982011-12-07 16:59:03 +0530931 /*
932 * For the pll configuration used in acpuclock table e.g.
933 * pll0_960_pll1_245_pll2_1200" is same for 7627 and
934 * 7625a (as pll0,pll1,pll2) having same rates, but frequency
935 * table is different for both targets.
936 *
937 * Hence below for loop will not be able to select correct
938 * table based on PLL rates as rates are same. Hence we need
939 * to add this cpu check for selecting the correct acpuclock table.
940 */
Trilok Soni54d35c42011-07-14 17:47:50 +0530941 if (cpu_is_msm7x25a()) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530942 if (pll_mhz[ACPU_PLL_1] == 245) {
Trilok Soni54d35c42011-07-14 17:47:50 +0530943 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530944 pll0_960_pll1_245_pll2_1200_25a;
Pankaj Kumar3912c982011-12-07 16:59:03 +0530945 } else if (pll_mhz[ACPU_PLL_1] == 737) {
Trilok Soni9bb022c2011-10-31 18:25:19 +0530946 acpu_freq_tbl =
Pankaj Kumarc9136b32012-01-02 18:46:13 +0530947 pll0_960_pll1_737_pll2_1200_25a;
Trilok Soni54d35c42011-07-14 17:47:50 +0530948 }
949 } else {
950 /* Select the right table to use. */
Kaushal Kumar86473f02012-06-28 19:35:58 +0530951 for (; t->tbl != 0; t++) {
Pankaj Kumar3912c982011-12-07 16:59:03 +0530952 if (t->pll0_rate == pll_mhz[ACPU_PLL_0]
953 && t->pll1_rate == pll_mhz[ACPU_PLL_1]
954 && t->pll2_rate == pll_mhz[ACPU_PLL_2]
955 && t->pll4_rate == pll_mhz[ACPU_PLL_4]) {
956 acpu_freq_tbl = t->tbl;
Trilok Soni54d35c42011-07-14 17:47:50 +0530957 break;
958 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700959 }
960 }
961
Trilok Soni3f33ffc2012-08-03 20:14:04 +0530962 if (acpu_freq_tbl == NULL) {
963 pr_crit("Unknown PLL configuration!\n");
964 BUG();
965 }
966
Kaushal Kumar86473f02012-06-28 19:35:58 +0530967 /*
Trilok Soni3f33ffc2012-08-03 20:14:04 +0530968 * Turn ON the dynamic reprogramming method
969 * if one of the table entry has pll_rate defined.
970 */
971 for ( ; t->tbl->a11clk_khz; t->tbl++) {
972 if (t->tbl->pll_rate) {
973 if (!dynamic_reprogram) {
974 dynamic_reprogram = 1;
975 pr_info("Dynamic reprogramming is ON\n");
976 }
977 }
978 }
979
980 /*
Kaushal Kumar86473f02012-06-28 19:35:58 +0530981 * Also find the backup pll used during PLL4 reprogramming.
982 * We are using PLL2@600MHz as backup PLL, since 800MHz jump
983 * is fine.
984 */
Trilok Soni3f33ffc2012-08-03 20:14:04 +0530985 if (dynamic_reprogram) {
986 for (t->tbl = acpu_freq_tbl; t->tbl->a11clk_khz; t->tbl++) {
Kaushal Kumar86473f02012-06-28 19:35:58 +0530987 if (t->tbl->pll == ACPU_PLL_2 &&
988 t->tbl->a11clk_src_div == 1) {
989 backup_s = t->tbl;
990 break;
991 }
992 }
993 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700994}
995
996/*
997 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
998 * before entering a wait for irq low-power mode. Find a suitable rate.
999 */
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001000static unsigned long __devinit find_wait_for_irq_khz(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001001{
1002 unsigned long found_khz = 0;
1003 int i;
1004
1005 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
1006 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
1007 found_khz = acpu_freq_tbl[i].a11clk_khz;
1008
1009 return found_khz;
1010}
1011
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001012static void __devinit lpj_init(void)
Taniya Dasc43e6872012-03-21 16:41:14 +05301013{
1014 int i = 0, cpu;
1015 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
1016 unsigned long loops;
1017
1018 for_each_possible_cpu(cpu) {
1019#ifdef CONFIG_SMP
1020 loops = per_cpu(cpu_data, cpu).loops_per_jiffy;
1021#else
1022 loops = loops_per_jiffy;
1023#endif
1024 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1025 acpu_freq_tbl[i].lpj = cpufreq_scale(
1026 loops,
1027 base_clk->a11clk_khz,
1028 acpu_freq_tbl[i].a11clk_khz);
1029 }
1030 }
1031}
1032
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001033static void __devinit precompute_stepping(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001034{
1035 int i, step_idx;
1036
1037#define cur_freq acpu_freq_tbl[i].a11clk_khz
1038#define step_freq acpu_freq_tbl[step_idx].a11clk_khz
1039#define cur_pll acpu_freq_tbl[i].pll
1040#define step_pll acpu_freq_tbl[step_idx].pll
1041
1042 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
1043
1044 /* Calculate max "up" step for each destination PLL */
1045 step_idx = i + 1;
1046 while (step_freq && (step_freq - cur_freq)
1047 <= drv_state.max_speed_delta_khz) {
1048 acpu_freq_tbl[i].up[step_pll] =
1049 &acpu_freq_tbl[step_idx];
1050 step_idx++;
1051 }
1052 if (step_idx == (i + 1) && step_freq) {
1053 pr_crit("Delta between freqs %u KHz and %u KHz is"
1054 " too high!\n", cur_freq, step_freq);
1055 BUG();
1056 }
1057
1058 /* Calculate max "down" step for each destination PLL */
1059 step_idx = i - 1;
1060 while (step_idx >= 0 && (cur_freq - step_freq)
1061 <= drv_state.max_speed_delta_khz) {
1062 acpu_freq_tbl[i].down[step_pll] =
1063 &acpu_freq_tbl[step_idx];
1064 step_idx--;
1065 }
1066 if (step_idx == (i - 1) && i > 0) {
1067 pr_crit("Delta between freqs %u KHz and %u KHz is"
1068 " too high!\n", cur_freq, step_freq);
1069 BUG();
1070 }
1071 }
1072}
1073
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001074static void __devinit print_acpu_freq_tbl(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001075{
1076 struct clkctl_acpu_speed *t;
1077 short down_idx[ACPU_PLL_END];
1078 short up_idx[ACPU_PLL_END];
1079 int i, j;
1080
1081#define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl)
1082 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz "
1083 "D0 D1 D2 D4 U0 U1 U2 U4\n");
1084
1085 t = &acpu_freq_tbl[0];
1086 for (i = 0; t->a11clk_khz != 0; i++) {
1087
1088 for (j = 0; j < ACPU_PLL_END; j++) {
1089 down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1;
1090 up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1;
1091 }
1092
1093 pr_info("%2d %7d %3d %3d %7d %4d %7d "
1094 "%2d %2d %2d %2d %2d %2d %2d %2d\n",
1095 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
1096 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
1097 down_idx[0], down_idx[1], down_idx[2], down_idx[4],
1098 up_idx[0], up_idx[1], up_idx[2], up_idx[4]);
1099
1100 t++;
1101 }
1102}
1103
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001104
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301105static struct acpuclk_data acpuclk_7627_data = {
1106 .set_rate = acpuclk_7627_set_rate,
1107 .get_rate = acpuclk_7627_get_rate,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001108 .power_collapse_khz = POWER_COLLAPSE_KHZ,
Matt Wagantallec57f062011-08-16 23:54:46 -07001109 .switch_time_us = 50,
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001110};
1111
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001112static int __devinit acpuclk_7627_probe(struct platform_device *pdev)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001113{
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001114 const struct acpuclk_pdata *pdata = pdev->dev.platform_data;
1115
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001116 pr_info("%s()\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001117
1118 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
1119 BUG_ON(IS_ERR(drv_state.ebi1_clk));
1120
1121 mutex_init(&drv_state.lock);
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001122 drv_state.max_speed_delta_khz = pdata->max_speed_delta_khz;
Pankaj Kumar3912c982011-12-07 16:59:03 +05301123 select_freq_plan();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301124 acpuclk_7627_data.wait_for_irq_khz = find_wait_for_irq_khz();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001125 precompute_stepping();
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001126 acpuclk_hw_init();
Taniya Dasc43e6872012-03-21 16:41:14 +05301127 lpj_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001128 print_acpu_freq_tbl();
Pankaj Kumar6e66f372011-12-05 14:41:58 +05301129 acpuclk_register(&acpuclk_7627_data);
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001131#ifdef CONFIG_CPU_FREQ_MSM
1132 cpufreq_table_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001133#endif
Matt Wagantall6d9ebee2011-08-26 12:15:24 -07001134 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001135}
Matt Wagantallec57f062011-08-16 23:54:46 -07001136
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001137static struct platform_driver acpuclk_7627_driver = {
1138 .probe = acpuclk_7627_probe,
1139 .driver = {
1140 .name = "acpuclk-7627",
1141 .owner = THIS_MODULE,
1142 },
Matt Wagantallec57f062011-08-16 23:54:46 -07001143};
1144
Matt Wagantallbf430eb2012-03-22 11:45:49 -07001145static int __init acpuclk_7627_init(void)
1146{
1147 return platform_driver_register(&acpuclk_7627_driver);
1148}
1149postcore_initcall(acpuclk_7627_init);
Kaushal Kumar86473f02012-06-28 19:35:58 +05301150