blob: 0a6dfbe29dd1b5ba43710adef3c4036fb2ec3928 [file] [log] [blame]
Trilok Sonid1fe37f2012-11-08 15:00:36 +05301/*
2 * Copyright (C) 2007 Google, Inc.
3 * Copyright (c) 2007-2012, Linux Foundation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/delay.h>
21#include <linux/clk.h>
22#include <linux/cpufreq.h>
23#include <linux/mutex.h>
24#include <linux/io.h>
25#include <linux/sort.h>
26#include <linux/regulator/consumer.h>
27#include <linux/smp.h>
28
29#include <mach/board.h>
30#include <mach/msm_iomap.h>
31#include <mach/clk-provider.h>
32
33#include <asm/cpu.h>
34
35#include "acpuclock.h"
36#include "acpuclock-8625q.h"
37
38#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
39#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
40
41#define PLL4_L_VAL_ADDR (MSM_CLK_CTL_BASE + 0x378)
42#define PLL4_M_VAL_ADDR (MSM_CLK_CTL_BASE + 0x37C)
43#define PLL4_N_VAL_ADDR (MSM_CLK_CTL_BASE + 0x380)
44
45#define POWER_COLLAPSE_KHZ 19200
46
47/* Max CPU frequency allowed by hardware while in standby waiting for an irq. */
48#define MAX_WAIT_FOR_IRQ_KHZ 128000
49
50/**
51 * enum - For acpuclock PLL IDs
52 */
53enum {
54 ACPU_PLL_0 = 0,
55 ACPU_PLL_1,
56 ACPU_PLL_2,
57 ACPU_PLL_3,
58 ACPU_PLL_4,
59 ACPU_PLL_TCXO,
60 ACPU_PLL_END,
61};
62
63struct acpu_clk_src {
64 struct clk *clk;
65 const char *name;
66};
67
68struct pll_config {
69 unsigned int l;
70 unsigned int m;
71 unsigned int n;
72};
73
74static struct acpu_clk_src pll_clk[ACPU_PLL_END] = {
75 [ACPU_PLL_0] = { .name = "pll0_clk" },
76 [ACPU_PLL_1] = { .name = "pll1_clk" },
77 [ACPU_PLL_2] = { .name = "pll2_clk" },
78 [ACPU_PLL_4] = { .name = "pll4_clk" },
79};
80
81static struct pll_config pll4_cfg_tbl[] = {
82 [0] = { 36, 1, 2 }, /* 700.8 MHz */
83 [1] = { 52, 1, 2 }, /* 1008 MHz */
84 [2] = { 63, 0, 1 }, /* 1209.6 MHz */
85 [3] = { 73, 0, 1 }, /* 1401.6 MHz */
86};
87
88struct clock_state {
89 struct clkctl_acpu_speed *current_speed;
90 struct mutex lock;
91 uint32_t max_speed_delta_khz;
92 struct clk *ebi1_clk;
93 struct regulator *vreg_cpu;
94};
95
96struct clkctl_acpu_speed {
97 unsigned int use_for_scaling;
98 unsigned int a11clk_khz;
99 int pll;
100 unsigned int a11clk_src_sel;
101 unsigned int a11clk_src_div;
102 unsigned int ahbclk_khz;
103 unsigned int ahbclk_div;
104 int vdd;
105 unsigned int axiclk_khz;
106 struct pll_config *pll_rate;
107 unsigned long lpj;
108};
109
110static struct clock_state drv_state = { 0 };
111
112/* PVS MAX Voltage in uV as per frequencies*/
113
114# define MAX_14GHZ_VOLTAGE 1350000
115# define MAX_12GHZ_VOLTAGE 1275000
116# define MAX_1GHZ_VOLTAGE 1175000
117# define MAX_NOMINAL_VOLTAGE 1150000
118
119/* PVS deltas as per formula*/
120# define DELTA_LEVEL_1_UV 0
121# define DELTA_LEVEL_2_UV 75000
122# define DELTA_LEVEL_3_UV 150000
123
124
125static struct clkctl_acpu_speed acpu_freq_tbl_cmn[] = {
126 { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 },
127 { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, MAX_NOMINAL_VOLTAGE, 61440 },
128 { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, MAX_NOMINAL_VOLTAGE, 122880 },
129 { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, MAX_NOMINAL_VOLTAGE, 122880 },
130 { 0, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 0, 160000 },
131 { 1, 700800, ACPU_PLL_4, 6, 0, 87500, 3, MAX_NOMINAL_VOLTAGE, 160000,
132 &pll4_cfg_tbl[0]},
133 { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, MAX_1GHZ_VOLTAGE, 200000,
134 &pll4_cfg_tbl[1]},
135};
136
137static struct clkctl_acpu_speed acpu_freq_tbl_1209[] = {
138 { 1, 1209600, ACPU_PLL_4, 6, 0, 151200, 3, MAX_12GHZ_VOLTAGE, 200000,
139 &pll4_cfg_tbl[2]},
140};
141
142static struct clkctl_acpu_speed acpu_freq_tbl_1401[] = {
143 { 1, 1401600, ACPU_PLL_4, 6, 0, 175000, 3, MAX_14GHZ_VOLTAGE, 200000,
144 &pll4_cfg_tbl[3]},
145};
146
147/* Entry corresponding to CDMA build*/
148static struct clkctl_acpu_speed acpu_freq_tbl_196608[] = {
149 { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, MAX_NOMINAL_VOLTAGE, 98304 },
150};
151
152static struct clkctl_acpu_speed acpu_freq_tbl_null[] = {
153 { 0 },
154};
155
156static struct clkctl_acpu_speed acpu_freq_tbl[ARRAY_SIZE(acpu_freq_tbl_cmn)
157 + ARRAY_SIZE(acpu_freq_tbl_1209)
158 + ARRAY_SIZE(acpu_freq_tbl_1401)
159 + ARRAY_SIZE(acpu_freq_tbl_null)];
160
161/* Switch to this when reprogramming PLL4 */
162static struct clkctl_acpu_speed *backup_s;
163
164#ifdef CONFIG_CPU_FREQ_MSM
165static struct cpufreq_frequency_table freq_table[NR_CPUS][20];
166
167static void __devinit cpufreq_table_init(void)
168{
169 int cpu;
170 for_each_possible_cpu(cpu) {
171 unsigned int i, freq_cnt = 0;
172
173 /* Construct the freq_table table from acpu_freq_tbl since
174 * the freq_table values need to match frequencies specified
175 * in acpu_freq_tbl and acpu_freq_tbl needs to be fixed up
176 * during init.
177 */
178 for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0
179 && freq_cnt < ARRAY_SIZE(*freq_table)-1; i++) {
180 if (acpu_freq_tbl[i].use_for_scaling) {
181 freq_table[cpu][freq_cnt].index = freq_cnt;
182 freq_table[cpu][freq_cnt].frequency
183 = acpu_freq_tbl[i].a11clk_khz;
184 freq_cnt++;
185 }
186 }
187
188 /* freq_table not big enough to store all usable freqs. */
189 BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0);
190
191 freq_table[cpu][freq_cnt].index = freq_cnt;
192 freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END;
193 /* Register table with CPUFreq. */
194 cpufreq_frequency_table_get_attr(freq_table[cpu], cpu);
195 pr_info("CPU%d: %d scaling frequencies supported.\n",
196 cpu, freq_cnt);
197 }
198}
199#else
200static void __devinit cpufreq_table_init(void) { }
201#endif
202
203static void update_jiffies(int cpu, unsigned long loops)
204{
205#ifdef CONFIG_SMP
206 for_each_possible_cpu(cpu) {
207 per_cpu(cpu_data, cpu).loops_per_jiffy =
208 loops;
209 }
210#endif
211 /* Adjust the global one */
212 loops_per_jiffy = loops;
213}
214
215/* Assumes PLL4 is off and the acpuclock isn't sourced from PLL4 */
216static void acpuclk_config_pll4(struct pll_config *pll)
217{
218 /*
219 * Make sure write to disable PLL_4 has completed
220 * before reconfiguring that PLL.
221 */
222 mb();
223 writel_relaxed(pll->l, PLL4_L_VAL_ADDR);
224 writel_relaxed(pll->m, PLL4_M_VAL_ADDR);
225 writel_relaxed(pll->n, PLL4_N_VAL_ADDR);
226 /* Make sure PLL is programmed before returning. */
227 mb();
228}
229
230/* Set proper dividers for the given clock speed. */
231static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s)
232{
233 uint32_t reg_clkctl, reg_clksel, clk_div, src_sel;
234
235 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
236
237 /* AHB_CLK_DIV */
238 clk_div = (reg_clksel >> 1) & 0x03;
239 /* CLK_SEL_SRC1NO */
240 src_sel = reg_clksel & 1;
241
242 /*
243 * If the new clock divider is higher than the previous, then
244 * program the divider before switching the clock
245 */
246 if (hunt_s->ahbclk_div > clk_div) {
247 reg_clksel &= ~(0x3 << 1);
248 reg_clksel |= (hunt_s->ahbclk_div << 1);
249 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
250 }
251
252 /* Program clock source and divider */
253 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
254 reg_clkctl &= ~(0xFF << (8 * src_sel));
255 reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel);
256 reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel);
257 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
258
259 /* Program clock source selection */
260 reg_clksel ^= 1;
261 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
262
263 /* Wait for the clock switch to complete */
264 mb();
265 udelay(50);
266
267 /*
268 * If the new clock divider is lower than the previous, then
269 * program the divider after switching the clock
270 */
271 if (hunt_s->ahbclk_div < clk_div) {
272 reg_clksel &= ~(0x3 << 1);
273 reg_clksel |= (hunt_s->ahbclk_div << 1);
274 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
275 }
276}
277
278static int acpuclk_set_vdd_level(int vdd)
279{
280 int rc;
281
282 rc = regulator_set_voltage(drv_state.vreg_cpu, vdd, vdd);
283 if (rc) {
284 pr_err("failed to set vdd=%d uV\n", vdd);
285 return rc;
286 }
287
288 return 0;
289}
290
291static int acpuclk_8625q_set_rate(int cpu, unsigned long rate,
292 enum setrate_reason reason)
293{
294 uint32_t reg_clkctl;
295 struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
296 int res, rc = 0;
297 unsigned int plls_enabled = 0, pll;
298 int delta;
299
300
301 if (reason == SETRATE_CPUFREQ)
302 mutex_lock(&drv_state.lock);
303
304 strt_s = cur_s = drv_state.current_speed;
305
306 WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__);
307 if (cur_s == NULL) {
308 rc = -ENOENT;
309 goto out;
310 }
311
312 cur_s->vdd = regulator_get_voltage(drv_state.vreg_cpu);
313 if (cur_s->vdd <= 0)
314 goto out;
315
316 pr_debug("current freq=%dKhz vdd=%duV\n",
317 cur_s->a11clk_khz, cur_s->vdd);
318
319 if (rate == cur_s->a11clk_khz)
320 goto out;
321
322 for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
323 if (tgt_s->a11clk_khz == rate)
324 break;
325 }
326
327 if (tgt_s->a11clk_khz == 0) {
328 rc = -EINVAL;
329 goto out;
330 }
331
332 /* Choose the highest speed at or below 'rate' with same PLL. */
333 if (reason != SETRATE_CPUFREQ
334 && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
335 while (tgt_s->pll != ACPU_PLL_TCXO &&
336 tgt_s->pll != cur_s->pll) {
337 pr_debug("Intermediate frequency changes: %u\n",
338 tgt_s->a11clk_khz);
339 tgt_s--;
340 }
341 }
342
343 if (strt_s->pll != ACPU_PLL_TCXO)
344 plls_enabled |= 1 << strt_s->pll;
345
346 /* Need to do this when coming out of power collapse since some modem
347 * firmwares reset the VDD when the application processor enters power
348 * collapse.
349 */
350 if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) {
351 /* Increase VDD if needed. */
352 if (tgt_s->vdd > cur_s->vdd) {
353 rc = acpuclk_set_vdd_level(tgt_s->vdd);
354 if (rc < 0) {
355 pr_err("Unable to switch ACPU vdd (%d)\n", rc);
356 goto out;
357 }
358 pr_debug("Increased Vdd to %duV\n", tgt_s->vdd);
359 }
360 }
361
362 /* Set wait states for CPU inbetween frequency changes */
363 reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR);
364 reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
365 writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR);
366
367 pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
368 strt_s->a11clk_khz, tgt_s->a11clk_khz);
369
370 delta = abs((int)(strt_s->a11clk_khz - tgt_s->a11clk_khz));
371
372 if (tgt_s->pll == ACPU_PLL_4) {
373 if (strt_s->pll == ACPU_PLL_4 ||
374 delta > drv_state.max_speed_delta_khz) {
375 /*
376 * Enable the backup PLL if required
377 * and switch to it.
378 */
379 clk_enable(pll_clk[backup_s->pll].clk);
380 acpuclk_set_div(backup_s);
381 update_jiffies(cpu, backup_s->lpj);
382 }
383 /* Make sure PLL4 is off before reprogramming */
384 if ((plls_enabled & (1 << tgt_s->pll))) {
385 clk_disable(pll_clk[tgt_s->pll].clk);
386 plls_enabled &= ~(1 << tgt_s->pll);
387 }
388 acpuclk_config_pll4(tgt_s->pll_rate);
389 pll_clk[tgt_s->pll].clk->rate = tgt_s->a11clk_khz*1000;
390
391 } else if (strt_s->pll == ACPU_PLL_4) {
392 if (delta > drv_state.max_speed_delta_khz) {
393 /*
394 * Enable the bcackup PLL if required
395 * and switch to it.
396 */
397 clk_enable(pll_clk[backup_s->pll].clk);
398 acpuclk_set_div(backup_s);
399 update_jiffies(cpu, backup_s->lpj);
400 }
401 }
402
403 if ((tgt_s->pll != ACPU_PLL_TCXO) &&
404 !(plls_enabled & (1 << tgt_s->pll))) {
405 rc = clk_enable(pll_clk[tgt_s->pll].clk);
406 if (rc < 0) {
407 pr_err("PLL%d enable failed (%d)\n",
408 tgt_s->pll, rc);
409 goto out;
410 }
411 plls_enabled |= 1 << tgt_s->pll;
412 }
413 acpuclk_set_div(tgt_s);
414 drv_state.current_speed = tgt_s;
415 pr_debug("The new clock speed is %u\n", tgt_s->a11clk_khz);
416 /* Re-adjust lpj for the new clock speed. */
417 update_jiffies(cpu, tgt_s->lpj);
418
419 /* Disable the backup PLL */
420 if ((delta > drv_state.max_speed_delta_khz)
421 || (strt_s->pll == ACPU_PLL_4 &&
422 tgt_s->pll == ACPU_PLL_4))
423 clk_disable(pll_clk[backup_s->pll].clk);
424
425 /* Nothing else to do for SWFI. */
426 if (reason == SETRATE_SWFI)
427 goto out;
428
429 /* Change the AXI bus frequency if we can. */
430 if (reason != SETRATE_PC &&
431 strt_s->axiclk_khz != tgt_s->axiclk_khz) {
432 res = clk_set_rate(drv_state.ebi1_clk,
433 tgt_s->axiclk_khz * 1000);
434 pr_debug("AXI bus set freq %d\n",
435 tgt_s->axiclk_khz * 1000);
436 if (res < 0)
437 pr_warning("Setting AXI min rate failed (%d)\n", res);
438 }
439
440 /* Disable PLLs we are not using anymore. */
441 if (tgt_s->pll != ACPU_PLL_TCXO)
442 plls_enabled &= ~(1 << tgt_s->pll);
443 for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++)
444 if (plls_enabled & (1 << pll))
445 clk_disable(pll_clk[pll].clk);
446
447 /* Nothing else to do for power collapse. */
448 if (reason == SETRATE_PC)
449 goto out;
450
451 /* Drop VDD level if we can. */
452 if (tgt_s->vdd < strt_s->vdd) {
453 res = acpuclk_set_vdd_level(tgt_s->vdd);
454 if (res < 0)
455 pr_warning("Unable to drop ACPU vdd (%d)\n", res);
456 pr_debug("Decreased Vdd to %duV\n", tgt_s->vdd);
457 }
458
459 pr_debug("ACPU speed change complete\n");
460out:
461 if (reason == SETRATE_CPUFREQ)
462 mutex_unlock(&drv_state.lock);
463
464 return rc;
465}
466
467static int __devinit acpuclk_hw_init(void)
468{
469 struct clkctl_acpu_speed *speed;
470 uint32_t div, sel, reg_clksel;
471 int res;
472
473 /*
474 * Prepare all the PLLs because we enable/disable them
475 * from atomic context and can't always ensure they're
476 * all prepared in non-atomic context. Same goes for
477 * ebi1_acpu_clk.
478 */
479 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_0].clk));
480 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_1].clk));
481 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_2].clk));
482 BUG_ON(clk_prepare(pll_clk[ACPU_PLL_4].clk));
483 BUG_ON(clk_prepare(drv_state.ebi1_clk));
484
485 /*
486 * Determine the rate of ACPU clock
487 */
488
489 if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
490 /* CLK_SRC0_SEL */
491 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
492 /* CLK_SRC0_DIV */
493 div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
494 } else {
495 /* CLK_SRC1_SEL */
496 sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
497 /* CLK_SRC1_DIV */
498 div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f;
499 }
500
501 for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
502 if (speed->a11clk_src_sel == sel
503 && (speed->a11clk_src_div == div))
504 break;
505 }
506 if (speed->a11clk_khz == 0) {
507 pr_err("Error - ACPU clock reports invalid speed\n");
508 return -EINVAL;
509 }
510
511 drv_state.current_speed = speed;
512 if (speed->pll != ACPU_PLL_TCXO) {
513 if (clk_enable(pll_clk[speed->pll].clk)) {
514 pr_warning("Failed to vote for boot PLL\n");
515 return -ENODEV;
516 }
517 }
518
519 reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR);
520 reg_clksel &= ~(0x3 << 14);
521 reg_clksel |= (0x1 << 14);
522 writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR);
523
524 res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
525 if (res < 0) {
526 pr_warning("Setting AXI min rate failed (%d)\n", res);
527 return -ENODEV;
528 }
529 res = clk_enable(drv_state.ebi1_clk);
530 if (res < 0) {
531 pr_warning("Enabling AXI clock failed (%d)\n", res);
532 return -ENODEV;
533 }
534
535 drv_state.vreg_cpu = regulator_get(NULL, "vddx_cx");
536 if (IS_ERR(drv_state.vreg_cpu)) {
537 res = PTR_ERR(drv_state.vreg_cpu);
538 pr_err("could not get regulator: %d\n", res);
539 }
540
541 pr_info("ACPU running at %d KHz\n", speed->a11clk_khz);
542 return 0;
543}
544
545static unsigned long acpuclk_8625q_get_rate(int cpu)
546{
547 WARN_ONCE(drv_state.current_speed == NULL,
548 "%s: not initialized\n", __func__);
549 if (drv_state.current_speed)
550 return drv_state.current_speed->a11clk_khz;
551 else
552 return 0;
553}
554
555#define MHZ 1000000
556
Utsab Bose4051d252012-11-30 13:32:50 +0530557static void __devinit select_freq_plan(unsigned int pvs_voltage,
558 unsigned int nominal_vol_uv,
559 unsigned int default_vol_uv)
Trilok Sonid1fe37f2012-11-08 15:00:36 +0530560{
561 unsigned long pll_mhz[ACPU_PLL_END];
562 int i;
563 int size;
564 int delta[3] = {DELTA_LEVEL_1_UV, DELTA_LEVEL_2_UV, DELTA_LEVEL_3_UV};
565 struct clkctl_acpu_speed *tbl;
566
567 /* Get PLL clocks */
568 for (i = 0; i < ACPU_PLL_END; i++) {
569 if (pll_clk[i].name) {
570 pll_clk[i].clk = clk_get_sys("acpu", pll_clk[i].name);
571 if (IS_ERR(pll_clk[i].clk)) {
572 pll_mhz[i] = 0;
573 continue;
574 }
575 /* Get PLL's Rate */
576 pll_mhz[i] = clk_get_rate(pll_clk[i].clk)/MHZ;
577 }
578 }
579
580 memcpy(acpu_freq_tbl, acpu_freq_tbl_cmn, sizeof(acpu_freq_tbl_cmn));
581 size = ARRAY_SIZE(acpu_freq_tbl_cmn);
582
583 i = 0; /* needed if we have a 1Ghz part */
584 /* select if it is a 1.2Ghz part */
585 if (pll_mhz[ACPU_PLL_4] == 1209) {
586 memcpy(acpu_freq_tbl + size, acpu_freq_tbl_1209,
587 sizeof(acpu_freq_tbl_1209));
588 size += sizeof(acpu_freq_tbl_1209);
589 i = 1; /* set the delta index */
590 }
591 /* select if it is a 1.4Ghz part */
592 if (pll_mhz[ACPU_PLL_4] == 1401) {
593 memcpy(acpu_freq_tbl + size, acpu_freq_tbl_1209,
594 sizeof(acpu_freq_tbl_1209));
595 size += ARRAY_SIZE(acpu_freq_tbl_1209);
596 memcpy(acpu_freq_tbl + size, acpu_freq_tbl_1401,
597 sizeof(acpu_freq_tbl_1401));
598 size += ARRAY_SIZE(acpu_freq_tbl_1401);
599 i = 2; /* set the delta index */
600 }
601
602 memcpy(acpu_freq_tbl + size, acpu_freq_tbl_null,
603 sizeof(acpu_freq_tbl_null));
604 size += sizeof(acpu_freq_tbl_null);
605
606 /* Alter the freq value in freq_tbl if it is a CDMA build*/
607 if (pll_mhz[ACPU_PLL_1] == 196) {
608
609 for (tbl = acpu_freq_tbl; tbl->a11clk_khz; tbl++) {
610 if (tbl->a11clk_khz == 245760 &&
611 tbl->pll == ACPU_PLL_1) {
612 pr_debug("Upgrading pll1 freq to 196 Mhz\n");
613 memcpy(tbl, acpu_freq_tbl_196608,
614 sizeof(acpu_freq_tbl_196608));
615 break;
616 }
617 }
618 }
619
620 /*
621 *PVS Voltage calculation formula
622 *1.4 Ghz device
623 *1.4 Ghz: Max(PVS_voltage,1.35V)
624 *1.2 Ghz: Max(PVS_volatge - 75mV,1.275V)
625 *1.0 Ghz: Max(PVS_voltage - 150mV, 1.175V)
626 *1.2 Ghz device
627 *1.2 Ghz: Max(PVS_voltage,1.275V)
628 *1.0 Ghz: Max(PVS_volatge - 75mV,1.175V)
629 *Nominal Mode: 1.15V
630 */
631 for (tbl = acpu_freq_tbl; tbl->a11clk_khz; tbl++) {
632 if (tbl->a11clk_khz >= 1008000) {
Utsab Bose4051d252012-11-30 13:32:50 +0530633 if (tbl->a11clk_khz == 1209600)
634 tbl->vdd = default_vol_uv;
Trilok Sonid1fe37f2012-11-08 15:00:36 +0530635 /*
636 * Change voltage as per PVS formula,
637 * i is initialized above with 2 or 1
638 * depending upon whether it is a 1.4Ghz
639 * or 1.2Ghz, so, we get the proper value
640 * from delta[i] which is to be deducted
641 * from PVS voltage.
642 */
643
644 tbl->vdd = max((int)(pvs_voltage - delta[i]), tbl->vdd);
645 i--;
Utsab Bose4051d252012-11-30 13:32:50 +0530646 } else if (tbl->a11clk_khz != 600000
647 && tbl->a11clk_khz != 19200)
648 tbl->vdd = nominal_vol_uv;
Trilok Sonid1fe37f2012-11-08 15:00:36 +0530649 }
650
651
Utsab Bose4051d252012-11-30 13:32:50 +0530652 /* find the backup PLL entry from the table */
Trilok Sonid1fe37f2012-11-08 15:00:36 +0530653 for (tbl = acpu_freq_tbl; tbl->a11clk_khz; tbl++) {
654 if (tbl->pll == ACPU_PLL_2 &&
655 tbl->a11clk_src_div == 1) {
656 backup_s = tbl;
657 break;
658 }
659 }
660
661 BUG_ON(!backup_s);
662
663}
664
665/*
666 * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ
667 * before entering a wait for irq low-power mode. Find a suitable rate.
668 */
669static unsigned long __devinit find_wait_for_irq_khz(void)
670{
671 unsigned long found_khz = 0;
672 int i;
673
674 for (i = 0; acpu_freq_tbl[i].a11clk_khz &&
675 acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++)
676 found_khz = acpu_freq_tbl[i].a11clk_khz;
677
678 return found_khz;
679}
680
681static void __devinit lpj_init(void)
682{
683 int i = 0, cpu;
684 const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
685 unsigned long loops;
686
687 for_each_possible_cpu(cpu) {
688#ifdef CONFIG_SMP
689 loops = per_cpu(cpu_data, cpu).loops_per_jiffy;
690#else
691 loops = loops_per_jiffy;
692#endif
693 for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
694 acpu_freq_tbl[i].lpj = cpufreq_scale(
695 loops,
696 base_clk->a11clk_khz,
697 acpu_freq_tbl[i].a11clk_khz);
698 }
699
700 }
701
702}
703
704static struct acpuclk_data acpuclk_8625q_data = {
705 .set_rate = acpuclk_8625q_set_rate,
706 .get_rate = acpuclk_8625q_get_rate,
707 .power_collapse_khz = POWER_COLLAPSE_KHZ,
708 .switch_time_us = 50,
709};
710
711static void __devinit print_acpu_freq_tbl(void)
712{
713 struct clkctl_acpu_speed *t;
714 int i;
715
716 pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz Vdd\n");
717
718 t = &acpu_freq_tbl[0];
719 for (i = 0; t->a11clk_khz != 0; i++) {
720 pr_info("%2d %7d %3d %3d %7d %4d %7d %3d\n",
721 i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1,
722 t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz,
723 t->vdd);
724 t++;
725 }
726}
727
728static int __devinit acpuclk_8625q_probe(struct platform_device *pdev)
729{
730 const struct acpuclk_pdata_8625q *pdata = pdev->dev.platform_data;
731 unsigned int pvs_voltage = pdata->pvs_voltage_uv;
Utsab Bose4051d252012-11-30 13:32:50 +0530732 unsigned int nom_vol_uv = pdata->nominal_voltage;
733 unsigned int default_vol_uv = pdata->default_turbo_voltage;
Trilok Sonid1fe37f2012-11-08 15:00:36 +0530734
735 drv_state.max_speed_delta_khz = pdata->acpu_clk_data->
736 max_speed_delta_khz;
737
738 drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
739 BUG_ON(IS_ERR(drv_state.ebi1_clk));
740
741 mutex_init(&drv_state.lock);
Utsab Bose4051d252012-11-30 13:32:50 +0530742 select_freq_plan(pvs_voltage, nom_vol_uv, default_vol_uv);
Trilok Sonid1fe37f2012-11-08 15:00:36 +0530743 acpuclk_8625q_data.wait_for_irq_khz = find_wait_for_irq_khz();
744
745 if (acpuclk_hw_init() < 0)
746 pr_err("acpuclk_hw_init not successful.\n");
747
748 print_acpu_freq_tbl();
749 lpj_init();
750 acpuclk_register(&acpuclk_8625q_data);
751
752 cpufreq_table_init();
753
754 return 0;
755}
756
757static struct platform_driver acpuclk_8625q_driver = {
758 .probe = acpuclk_8625q_probe,
759 .driver = {
760 .name = "acpuclock-8625q",
761 .owner = THIS_MODULE,
762 },
763};
764
765static int __init acpuclk_8625q_init(void)
766{
767
768 return platform_driver_register(&acpuclk_8625q_driver);
769}
770postcore_initcall(acpuclk_8625q_init);