Advertisement
Guest User

Untitled

a guest
Apr 7th, 2010
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.89 KB | None | 0 0
  1. /* arch/arm/mach-msm/acpuclock.c
  2. *
  3. * MSM architecture clock driver
  4. *
  5. * Copyright (C) 2007 Google, Inc.
  6. * Copyright (c) 2007 QUALCOMM Incorporated
  7. * Author: San Mehat <san@android.com>
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19.  
  20. #include <linux/version.h>
  21. #include <linux/kernel.h>
  22. #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/sort.h>
  29. #include <linux/mutex.h>
  30. #include <linux/io.h>
  31. #include <mach/board.h>
  32. #include <mach/msm_iomap.h>
  33.  
  34. #include <mach/proc_comm.h>
  35. #include "acpuclock.h"
  36.  
  37. enum {
  38. PERF_SWITCH_DEBUG = 1U << 0,
  39. PERF_SWITCH_STEP_DEBUG = 1U << 1,
  40. PERF_SWITCH_PLL_DEBUG = 1U << 2,
  41. PERF_SWITCH_VDD_DEBUG = 1U << 3,
  42. };
  43.  
  44. struct clock_state
  45. {
  46. struct clkctl_acpu_speed *current_speed;
  47. struct mutex lock;
  48. uint32_t acpu_switch_time_us;
  49. uint32_t max_speed_delta_khz;
  50. uint32_t vdd_switch_time_us;
  51. unsigned long power_collapse_khz;
  52. unsigned long wait_for_irq_khz;
  53. };
  54.  
  55. static struct clk *ebi1_clk;
  56. static struct clock_state drv_state = { 0 };
  57.  
  58. static void __init acpuclk_init(void);
  59.  
  60. /* MSM7201A Levels 3-6 all correspond to 1.2V, level 7 corresponds to 1.325V. */
  61. enum {
  62. VDD_0 = 0,
  63. VDD_1 = 1,
  64. VDD_2 = 2,
  65. VDD_3 = 3,
  66. VDD_4 = 4,
  67. VDD_5 = 5,
  68. VDD_6 = 6,
  69. VDD_7 = 7,
  70. VDD_END
  71. };
  72.  
  73. struct clkctl_acpu_speed {
  74. unsigned int a11clk_khz;
  75. int pll;
  76. unsigned int a11clk_src_sel;
  77. unsigned int a11clk_src_div;
  78. unsigned int ahbclk_khz;
  79. unsigned int ahbclk_div;
  80. int vdd;
  81. unsigned int axiclk_khz;
  82. unsigned long lpj; /* loops_per_jiffy */
  83. /* Index in acpu_freq_tbl[] for steppings. */
  84. short down;
  85. short up;
  86. };
  87.  
  88. /*
  89. * ACPU speed table. Complete table is shown but certain speeds are commented
  90. * out to optimized speed switching. Initalize loops_per_jiffy to 0.
  91. *
  92. * Table stepping up/down is optimized for 256mhz jumps while staying on the
  93. * same PLL.
  94. */
  95. #if (0)
  96. static struct clkctl_acpu_speed acpu_freq_tbl[] = {
  97. { 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, VDD_0, 30720, 0, 0, 8 },
  98. { 61440, ACPU_PLL_0, 4, 3, 61440, 0, VDD_0, 30720, 0, 0, 8 },
  99. { 81920, ACPU_PLL_0, 4, 2, 40960, 1, VDD_0, 61440, 0, 0, 8 },
  100. { 96000, ACPU_PLL_1, 1, 7, 48000, 1, VDD_0, 61440, 0, 0, 9 },
  101. { 122880, ACPU_PLL_0, 4, 1, 61440, 1, VDD_3, 61440, 0, 0, 8 },
  102. { 128000, ACPU_PLL_1, 1, 5, 64000, 1, VDD_3, 61440, 0, 0, 12 },
  103. { 176000, ACPU_PLL_2, 2, 5, 88000, 1, VDD_3, 61440, 0, 0, 11 },
  104. { 192000, ACPU_PLL_1, 1, 3, 64000, 2, VDD_3, 61440, 0, 0, 12 },
  105. { 245760, ACPU_PLL_0, 4, 0, 81920, 2, VDD_4, 61440, 0, 0, 12 },
  106. { 256000, ACPU_PLL_1, 1, 2, 128000, 2, VDD_5, 128000, 0, 0, 12 },
  107. { 264000, ACPU_PLL_2, 2, 3, 88000, 2, VDD_5, 128000, 0, 6, 13 },
  108. { 352000, ACPU_PLL_2, 2, 2, 88000, 3, VDD_5, 128000, 0, 6, 13 },
  109. { 384000, ACPU_PLL_1, 1, 1, 128000, 2, VDD_6, 128000, 0, 5, -1 },
  110. { 528000, ACPU_PLL_2, 2, 1, 132000, 3, VDD_7, 128000, 0, 11, -1 },
  111. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  112. };
  113. #else /* Table of freq we currently use. */
  114. #if defined(CONFIG_TURBO_MODE)
  115. /* 7200a turbo mode, PLL0(mpll):245.76, PLL1(gpll):960, PLL2(bpll0):1056 */
  116. static struct clkctl_acpu_speed acpu_freq_tbl[] = {
  117. { 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, VDD_0, 30720, 0, 0, 4 },
  118. { 122880, ACPU_PLL_0, 4, 1, 61440, 1, VDD_3, 61440, 0, 0, 4 },
  119. #if 1 /* QCT fixup */
  120. { 160000, ACPU_PLL_1, 1, 5, 53333, 2, VDD_3, 61440, 0, 0, 6 },
  121. #else /* Google */
  122. { 160000, ACPU_PLL_1, 1, 5, 64000, 1, VDD_3, 61440, 0, 0, 6 },
  123. #endif
  124. { 176000, ACPU_PLL_2, 2, 5, 88000, 1, VDD_3, 61440, 0, 0, 5 },
  125. { 245760, ACPU_PLL_0, 4, 0, 81920, 2, VDD_4, 61440, 0, 0, 5 },
  126. { 352000, ACPU_PLL_2, 2, 2, 88000, 3, VDD_5, 128000, 0, 3, 7 },
  127. #if 1 /* QCT fixup */
  128. { 480000, ACPU_PLL_1, 1, 1, 120000, 3, VDD_6, 120000, 0, 2, -1 },
  129. #else /* Google */
  130. { 480000, ACPU_PLL_1, 1, 1, 128000, 2, VDD_6, 160000, 0, 2, -1 },
  131. #endif
  132. { 528000, ACPU_PLL_2, 2, 1, 132000, 3, VDD_7, 160000, 0, 5, -1 },
  133. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  134. };
  135. #else
  136. static struct clkctl_acpu_speed acpu_freq_tbl[] = {
  137. { 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, VDD_0, 30720, 0, 0, 4 },
  138. { 122880, ACPU_PLL_0, 4, 1, 61440, 1, VDD_3, 61440, 0, 0, 4 },
  139. { 128000, ACPU_PLL_1, 1, 5, 64000, 1, VDD_3, 61440, 0, 0, 6 },
  140. { 176000, ACPU_PLL_2, 2, 5, 88000, 1, VDD_3, 61440, 0, 0, 5 },
  141. { 245760, ACPU_PLL_0, 4, 0, 81920, 2, VDD_4, 61440, 0, 0, 5 },
  142. { 352000, ACPU_PLL_2, 2, 2, 88000, 3, VDD_5, 128000, 0, 3, 7 },
  143. { 384000, ACPU_PLL_1, 1, 1, 128000, 2, VDD_6, 128000, 0, 2, -1 },
  144. { 528000, ACPU_PLL_2, 2, 1, 132000, 3, VDD_7, 128000, 0, 5, -1 },
  145. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  146. };
  147. #endif
  148. #endif
  149.  
  150. #if defined(CONFIG_MSM_CPU_FREQ_ONDEMAND) || \
  151. defined(CONFIG_MSM_CPU_FREQ_USERSPACE) || \
  152. defined(CONFIG_MSM_CPU_FREQ_MSM7K)
  153. #if defined(CONFIG_TURBO_MODE)
  154. static struct cpufreq_frequency_table freq_table[] = {
  155. { 0, 19200 },
  156. { 1, 122880 },
  157. { 2, 160000 },
  158. { 3, 245760 },
  159. { 4, 480000 },
  160. { 5, 528000 },
  161. { 6, CPUFREQ_TABLE_END },
  162. };
  163. #else
  164. static struct cpufreq_frequency_table freq_table[] = {
  165. { 0, 19200 },
  166. { 1, 122880 },
  167. { 2, 128000 },
  168. { 3, 245760 },
  169. { 4, 384000 },
  170. { 5, 528000 },
  171. { 6, CPUFREQ_TABLE_END },
  172. };
  173. #endif
  174. #endif
  175.  
  176. static int acpu_debug_mask;
  177. module_param_call(debug_mask, param_set_int, param_get_int,
  178. &acpu_debug_mask, S_IWUSR | S_IRUGO);
  179.  
  180. static int pc_pll_request(unsigned id, unsigned on)
  181. {
  182. int res;
  183. on = !!on;
  184.  
  185. if (acpu_debug_mask & PERF_SWITCH_PLL_DEBUG) {
  186. if (on)
  187. printk(KERN_DEBUG "Enabling PLL %d\n", id);
  188. else
  189. printk(KERN_DEBUG "Disabling PLL %d\n", id);
  190. }
  191.  
  192. res = msm_proc_comm(PCOM_CLKCTL_RPC_PLL_REQUEST, &id, &on);
  193. if (res < 0)
  194. return res;
  195.  
  196. if (acpu_debug_mask & PERF_SWITCH_PLL_DEBUG) {
  197. if (on)
  198. printk(KERN_DEBUG "PLL %d enabled\n", id);
  199. else
  200. printk(KERN_DEBUG "PLL %d disabled\n", id);
  201. }
  202. return res;
  203. }
  204.  
  205.  
  206. /*----------------------------------------------------------------------------
  207. * ARM11 'owned' clock control
  208. *---------------------------------------------------------------------------*/
  209. module_param_call(pwrc_khz, param_set_int, param_get_int,
  210. &drv_state.power_collapse_khz, S_IWUSR | S_IRUGO);
  211. module_param_call(wfi_khz, param_set_int, param_get_int,
  212. &drv_state.wait_for_irq_khz, S_IWUSR | S_IRUGO);
  213.  
  214. unsigned long acpuclk_power_collapse(void) {
  215. int ret = acpuclk_get_rate();
  216. acpuclk_set_rate(drv_state.power_collapse_khz, 1);
  217. return ret * 1000;
  218. }
  219.  
  220. unsigned long acpuclk_wait_for_irq(void) {
  221. int ret = acpuclk_get_rate();
  222. acpuclk_set_rate(drv_state.wait_for_irq_khz, 1);
  223. return ret * 1000;
  224. }
  225.  
  226. static int acpuclk_set_vdd_level(int vdd)
  227. {
  228. uint32_t current_vdd;
  229.  
  230. current_vdd = readl(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
  231.  
  232. if (acpu_debug_mask & PERF_SWITCH_VDD_DEBUG)
  233. printk(KERN_DEBUG "acpuclock: Switching VDD from %u -> %d\n",
  234. current_vdd, vdd);
  235.  
  236. writel((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
  237. udelay(drv_state.vdd_switch_time_us);
  238. if ((readl(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
  239. if (acpu_debug_mask & PERF_SWITCH_VDD_DEBUG)
  240. printk(KERN_ERR "acpuclock: VDD set failed\n");
  241. return -EIO;
  242. }
  243.  
  244. if (acpu_debug_mask & PERF_SWITCH_VDD_DEBUG)
  245. printk(KERN_DEBUG "acpuclock: VDD switched\n");
  246. return 0;
  247. }
  248.  
  249. /* Set proper dividers for the given clock speed. */
  250. static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s) {
  251. uint32_t reg_clkctl, reg_clksel, clk_div;
  252.  
  253. /* AHB_CLK_DIV */
  254. clk_div = (readl(A11S_CLK_SEL_ADDR) >> 1) & 0x03;
  255. /*
  256. * If the new clock divider is higher than the previous, then
  257. * program the divider before switching the clock
  258. */
  259. if (hunt_s->ahbclk_div > clk_div) {
  260. reg_clksel = readl(A11S_CLK_SEL_ADDR);
  261. reg_clksel &= ~(0x3 << 1);
  262. reg_clksel |= (hunt_s->ahbclk_div << 1);
  263. writel(reg_clksel, A11S_CLK_SEL_ADDR);
  264. }
  265. if ((readl(A11S_CLK_SEL_ADDR) & 0x01) == 0) {
  266. /* SRC0 */
  267.  
  268. /* Program clock source */
  269. reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
  270. reg_clkctl &= ~(0x07 << 4);
  271. reg_clkctl |= (hunt_s->a11clk_src_sel << 4);
  272. writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
  273.  
  274. /* Program clock divider */
  275. reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
  276. reg_clkctl &= ~0xf;
  277. reg_clkctl |= hunt_s->a11clk_src_div;
  278. writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
  279.  
  280. /* Program clock source selection */
  281. reg_clksel = readl(A11S_CLK_SEL_ADDR);
  282. reg_clksel |= 1; /* CLK_SEL_SRC1NO == SRC1 */
  283. writel(reg_clksel, A11S_CLK_SEL_ADDR);
  284. } else {
  285. /* SRC1 */
  286.  
  287. /* Program clock source */
  288. reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
  289. reg_clkctl &= ~(0x07 << 12);
  290. reg_clkctl |= (hunt_s->a11clk_src_sel << 12);
  291. writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
  292.  
  293. /* Program clock divider */
  294. reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
  295. reg_clkctl &= ~(0xf << 8);
  296. reg_clkctl |= (hunt_s->a11clk_src_div << 8);
  297. writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
  298.  
  299. /* Program clock source selection */
  300. reg_clksel = readl(A11S_CLK_SEL_ADDR);
  301. reg_clksel &= ~1; /* CLK_SEL_SRC1NO == SRC0 */
  302. writel(reg_clksel, A11S_CLK_SEL_ADDR);
  303. }
  304.  
  305. /*
  306. * If the new clock divider is lower than the previous, then
  307. * program the divider after switching the clock
  308. */
  309. if (hunt_s->ahbclk_div < clk_div) {
  310. reg_clksel = readl(A11S_CLK_SEL_ADDR);
  311. reg_clksel &= ~(0x3 << 1);
  312. reg_clksel |= (hunt_s->ahbclk_div << 1);
  313. writel(reg_clksel, A11S_CLK_SEL_ADDR);
  314. }
  315. }
  316.  
  317. int acpuclk_set_rate(unsigned long rate, int for_power_collapse)
  318. {
  319. uint32_t reg_clkctl;
  320. struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
  321. int rc = 0;
  322. unsigned int plls_enabled = 0, pll;
  323.  
  324. strt_s = cur_s = drv_state.current_speed;
  325.  
  326. WARN_ONCE(cur_s == NULL, "acpuclk_set_rate: not initialized\n");
  327. if (cur_s == NULL)
  328. return -ENOENT;
  329.  
  330. if (rate == (cur_s->a11clk_khz * 1000))
  331. return 0;
  332.  
  333. for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
  334. if (tgt_s->a11clk_khz == (rate / 1000))
  335. break;
  336. }
  337.  
  338. if (tgt_s->a11clk_khz == 0)
  339. return -EINVAL;
  340.  
  341. /* Choose the highest speed speed at or below 'rate' with same PLL. */
  342. if (for_power_collapse && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
  343. while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
  344. tgt_s--;
  345. }
  346.  
  347. if (strt_s->pll != ACPU_PLL_TCXO)
  348. plls_enabled |= 1 << strt_s->pll;
  349.  
  350. if (!for_power_collapse) {
  351. mutex_lock(&drv_state.lock);
  352. if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
  353. rc = pc_pll_request(tgt_s->pll, 1);
  354. if (rc < 0) {
  355. pr_err("PLL%d enable failed (%d)\n", tgt_s->pll, rc);
  356. goto out;
  357. }
  358. plls_enabled |= 1 << tgt_s->pll;
  359. }
  360. /* Increase VDD if needed. */
  361. if (tgt_s->vdd > cur_s->vdd) {
  362. if ((rc = acpuclk_set_vdd_level(tgt_s->vdd)) < 0) {
  363. printk(KERN_ERR "Unable to switch ACPU vdd\n");
  364. goto out;
  365. }
  366. }
  367. } else {
  368. /* Power collapse should also increase VDD. */
  369. if (tgt_s->vdd > cur_s->vdd) {
  370. if ((rc = acpuclk_set_vdd_level(tgt_s->vdd)) < 0) {
  371. printk(KERN_ERR "Unable to switch ACPU vdd\n");
  372. goto out;
  373. }
  374. }
  375. }
  376.  
  377. /* Set wait states for CPU inbetween frequency changes */
  378. reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
  379. reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
  380. writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
  381.  
  382. if (acpu_debug_mask & PERF_SWITCH_DEBUG)
  383. printk(KERN_INFO "%s: Switching from ACPU rate %u -> %u\n",
  384. __func__, strt_s->a11clk_khz * 1000,
  385. tgt_s->a11clk_khz * 1000);
  386.  
  387. while (cur_s != tgt_s) {
  388. /*
  389. * Always jump to target freq if within 256mhz, regulardless of
  390. * PLL. If differnece is greater, use the predefinied
  391. * steppings in the table.
  392. */
  393. int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
  394. if (d > drv_state.max_speed_delta_khz) {
  395. /* Step up or down depending on target vs current. */
  396. int clk_index = tgt_s->a11clk_khz > cur_s->a11clk_khz ?
  397. cur_s->up : cur_s->down;
  398. if (clk_index < 0) { /* This should not happen. */
  399. printk(KERN_ERR "cur:%u target: %u\n",
  400. cur_s->a11clk_khz, tgt_s->a11clk_khz);
  401. rc = -EINVAL;
  402. goto out;
  403. }
  404. cur_s = &acpu_freq_tbl[clk_index];
  405. } else {
  406. cur_s = tgt_s;
  407. }
  408. if (acpu_debug_mask & PERF_SWITCH_STEP_DEBUG)
  409. printk(KERN_DEBUG "%s: STEP khz = %u, pll = %d\n",
  410. __func__, cur_s->a11clk_khz, cur_s->pll);
  411.  
  412. /* Power collapse should also request pll.(19.2->528) */
  413. if (cur_s->pll != ACPU_PLL_TCXO
  414. && !(plls_enabled & (1 << cur_s->pll))) {
  415. rc = pc_pll_request(cur_s->pll, 1);
  416. if (rc < 0) {
  417. pr_err("PLL%d enable failed (%d)\n",
  418. cur_s->pll, rc);
  419. goto out;
  420. }
  421. plls_enabled |= 1 << cur_s->pll;
  422. }
  423.  
  424. acpuclk_set_div(cur_s);
  425. drv_state.current_speed = cur_s;
  426. /* Re-adjust lpj for the new clock speed. */
  427. loops_per_jiffy = cur_s->lpj;
  428. udelay(drv_state.acpu_switch_time_us);
  429. }
  430.  
  431. /* Nothing else to do for power collapse. */
  432. if (for_power_collapse)
  433. return 0;
  434.  
  435. /* Disable PLLs we are not using anymore. */
  436. plls_enabled &= ~(1 << tgt_s->pll);
  437. for (pll = ACPU_PLL_0; pll <= ACPU_PLL_2; pll++)
  438. if (plls_enabled & (1 << pll)) {
  439. rc = pc_pll_request(pll, 0);
  440. if (rc < 0) {
  441. pr_err("PLL%d disable failed (%d)\n", pll, rc);
  442. goto out;
  443. }
  444. }
  445.  
  446. /* Change the AXI bus frequency if we can. */
  447. /* Don't change it at power collapse, it will cause stability issue. */
  448. if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
  449. rc = clk_set_rate(ebi1_clk, tgt_s->axiclk_khz * 1000);
  450. if (rc < 0)
  451. pr_err("Setting AXI min rate failed!\n");
  452. }
  453.  
  454. /* Drop VDD level if we can. */
  455. if (tgt_s->vdd < strt_s->vdd) {
  456. if (acpuclk_set_vdd_level(tgt_s->vdd) < 0)
  457. printk(KERN_ERR "acpuclock: Unable to drop ACPU vdd\n");
  458. }
  459.  
  460. if (acpu_debug_mask & PERF_SWITCH_DEBUG)
  461. printk(KERN_DEBUG "%s: ACPU speed change complete\n",
  462. __func__);
  463. out:
  464. if (!for_power_collapse)
  465. mutex_unlock(&drv_state.lock);
  466. return rc;
  467. }
  468.  
  469. static void __init acpuclk_init(void)
  470. {
  471. struct clkctl_acpu_speed *speed;
  472. uint32_t div, sel;
  473. int rc;
  474.  
  475. /*
  476. * Determine the rate of ACPU clock
  477. */
  478. if (!(readl(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
  479. /* CLK_SRC0_SEL */
  480. sel = (readl(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
  481. /* CLK_SRC0_DIV */
  482. div = (readl(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
  483. } else {
  484. /* CLK_SRC1_SEL */
  485. sel = (readl(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
  486. /* CLK_SRC1_DIV */
  487. div = readl(A11S_CLK_CNTL_ADDR) & 0x0f;
  488. }
  489.  
  490. for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
  491. if (speed->a11clk_src_sel == sel
  492. && (speed->a11clk_src_div == div))
  493. break;
  494. }
  495. if (speed->a11clk_khz == 0) {
  496. printk(KERN_WARNING "Warning - ACPU clock reports invalid speed\n");
  497. return;
  498. }
  499.  
  500. drv_state.current_speed = speed;
  501.  
  502. rc = clk_set_rate(ebi1_clk, speed->axiclk_khz * 1000);
  503. if (rc < 0)
  504. pr_err("Setting AXI min rate failed!\n");
  505.  
  506. printk(KERN_INFO "ACPU running at %d KHz\n", speed->a11clk_khz);
  507. }
  508.  
  509. unsigned long acpuclk_get_rate(void)
  510. {
  511. WARN_ONCE(drv_state.current_speed == NULL,
  512. "acpuclk_get_rate: not initialized\n");
  513. if (drv_state.current_speed)
  514. return drv_state.current_speed->a11clk_khz;
  515. else
  516. return 0;
  517. }
  518.  
  519. uint32_t acpuclk_get_switch_time(void)
  520. {
  521. return drv_state.acpu_switch_time_us;
  522. }
  523.  
  524. unsigned long acpuclk_get_ebi1(unsigned long acpu_rate)
  525. {
  526. int i;
  527.  
  528. for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
  529. if (acpu_freq_tbl[i].a11clk_khz == (acpu_rate / 1000))
  530. break;
  531. }
  532. return acpu_freq_tbl[i].axiclk_khz * 1000;
  533. }
  534.  
  535. /*----------------------------------------------------------------------------
  536. * Clock driver initialization
  537. *---------------------------------------------------------------------------*/
  538.  
  539. /* Initalize the lpj field in the acpu_freq_tbl. */
  540. static void __init lpj_init(void)
  541. {
  542. int i;
  543. const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
  544. for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
  545. acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy,
  546. base_clk->a11clk_khz,
  547. acpu_freq_tbl[i].a11clk_khz);
  548. }
  549. }
  550.  
  551. void __init msm_acpu_clock_init(struct msm_acpu_clock_platform_data *clkdata)
  552. {
  553. pr_info("acpu_clock_init()\n");
  554.  
  555. ebi1_clk = clk_get(NULL, "ebi1_clk");
  556. writel(0x3e, MSM_CLK_CTL_BASE+0x33c);
  557. udelay(100);
  558. mutex_init(&drv_state.lock);
  559. drv_state.acpu_switch_time_us = clkdata->acpu_switch_time_us;
  560. drv_state.max_speed_delta_khz = clkdata->max_speed_delta_khz;
  561. drv_state.vdd_switch_time_us = clkdata->vdd_switch_time_us;
  562. drv_state.power_collapse_khz = clkdata->power_collapse_khz;
  563. drv_state.wait_for_irq_khz = clkdata->wait_for_irq_khz;
  564. acpuclk_init();
  565. lpj_init();
  566. #if defined(CONFIG_MSM_CPU_FREQ_ONDEMAND) || \
  567. defined(CONFIG_MSM_CPU_FREQ_USERSPACE) || \
  568. defined(CONFIG_MSM_CPU_FREQ_MSM7K)
  569. cpufreq_frequency_table_get_attr(freq_table, smp_processor_id());
  570. #endif
  571. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement