acpuclock-8x50.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /* Copyright (c) 2008-2012, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/delay.h>
  18. #include <linux/mutex.h>
  19. #include <linux/errno.h>
  20. #include <linux/cpufreq.h>
  21. #include <linux/clk.h>
  22. #include <linux/mfd/tps65023.h>
  23. #include <linux/platform_device.h>
  24. #include <mach/board.h>
  25. #include <mach/msm_iomap.h>
  26. #include "acpuclock.h"
  27. #include "avs.h"
  28. #define SHOT_SWITCH 4
  29. #define HOP_SWITCH 5
  30. #define SIMPLE_SLEW 6
  31. #define COMPLEX_SLEW 7
  32. #define SPSS_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
  33. #define SPSS_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
  34. /* Scorpion PLL registers */
  35. #define SCPLL_CTL_ADDR (MSM_SCPLL_BASE + 0x4)
  36. #define SCPLL_STATUS_ADDR (MSM_SCPLL_BASE + 0x18)
  37. #define SCPLL_FSM_CTL_EXT_ADDR (MSM_SCPLL_BASE + 0x10)
  38. #ifdef CONFIG_QSD_SVS
  39. #define TPS65023_MAX_DCDC1 1600
  40. #else
  41. #define TPS65023_MAX_DCDC1 CONFIG_QSD_PMIC_DEFAULT_DCDC1
  42. #endif
  43. enum {
  44. ACPU_PLL_TCXO = -1,
  45. ACPU_PLL_0 = 0,
  46. ACPU_PLL_1,
  47. ACPU_PLL_2,
  48. ACPU_PLL_3,
  49. ACPU_PLL_END,
  50. };
  51. struct clkctl_acpu_speed {
  52. unsigned int use_for_scaling;
  53. unsigned int acpuclk_khz;
  54. int pll;
  55. unsigned int acpuclk_src_sel;
  56. unsigned int acpuclk_src_div;
  57. unsigned int ahbclk_khz;
  58. unsigned int ahbclk_div;
  59. unsigned int axiclk_khz;
  60. unsigned int sc_core_src_sel_mask;
  61. unsigned int sc_l_value;
  62. int vdd;
  63. unsigned long lpj; /* loops_per_jiffy */
  64. };
  65. struct clkctl_acpu_speed acpu_freq_tbl_998[] = {
  66. { 0, 19200, ACPU_PLL_TCXO, 0, 0, 0, 0, 14000, 0, 0, 1000},
  67. { 0, 128000, ACPU_PLL_1, 1, 5, 0, 0, 14000, 2, 0, 1000},
  68. { 1, 245760, ACPU_PLL_0, 4, 0, 0, 0, 29000, 0, 0, 1000},
  69. /* Update AXI_S and PLL0_S macros if above row numbers change. */
  70. { 1, 384000, ACPU_PLL_3, 0, 0, 0, 0, 58000, 1, 0xA, 1000},
  71. { 0, 422400, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xB, 1000},
  72. { 0, 460800, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xC, 1000},
  73. { 0, 499200, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xD, 1050},
  74. { 0, 537600, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xE, 1050},
  75. { 1, 576000, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xF, 1050},
  76. { 0, 614400, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x10, 1075},
  77. { 0, 652800, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x11, 1100},
  78. { 0, 691200, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x12, 1125},
  79. { 0, 729600, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x13, 1150},
  80. { 1, 768000, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x14, 1150},
  81. { 0, 806400, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x15, 1175},
  82. { 0, 844800, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x16, 1225},
  83. { 0, 883200, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x17, 1250},
  84. { 0, 921600, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x18, 1300},
  85. { 0, 960000, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x19, 1300},
  86. { 1, 998400, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x1A, 1300},
  87. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  88. };
  89. struct clkctl_acpu_speed acpu_freq_tbl_768[] = {
  90. { 0, 19200, ACPU_PLL_TCXO, 0, 0, 0, 0, 14000, 0, 0, 1000},
  91. { 0, 128000, ACPU_PLL_1, 1, 5, 0, 0, 14000, 2, 0, 1000},
  92. { 1, 245760, ACPU_PLL_0, 4, 0, 0, 0, 29000, 0, 0, 1000},
  93. /* Update AXI_S and PLL0_S macros if above row numbers change. */
  94. { 1, 384000, ACPU_PLL_3, 0, 0, 0, 0, 58000, 1, 0xA, 1075},
  95. { 0, 422400, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xB, 1100},
  96. { 0, 460800, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xC, 1125},
  97. { 0, 499200, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xD, 1150},
  98. { 0, 537600, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xE, 1150},
  99. { 1, 576000, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0xF, 1150},
  100. { 0, 614400, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x10, 1175},
  101. { 0, 652800, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x11, 1200},
  102. { 0, 691200, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x12, 1225},
  103. { 0, 729600, ACPU_PLL_3, 0, 0, 0, 0, 117000, 1, 0x13, 1250},
  104. { 1, 768000, ACPU_PLL_3, 0, 0, 0, 0, 128000, 1, 0x14, 1250},
  105. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  106. };
  107. static struct clkctl_acpu_speed *acpu_freq_tbl = acpu_freq_tbl_998;
  108. #define AXI_S (&acpu_freq_tbl[1])
  109. #define PLL0_S (&acpu_freq_tbl[2])
  110. /* Use 128MHz for PC since ACPU will auto-switch to AXI (128MHz) before
  111. * coming back up. This allows detection of return-from-PC, since 128MHz
  112. * is only used for power collapse. */
  113. #define POWER_COLLAPSE_KHZ 128000
  114. /* Use 245MHz (not 128MHz) for SWFI to avoid unnecessary steps between
  115. * 128MHz<->245MHz. Jumping to high frequencies from 128MHz directly
  116. * is not allowed. */
  117. #define WAIT_FOR_IRQ_KHZ 245760
  118. #ifdef CONFIG_CPU_FREQ_MSM
  119. static struct cpufreq_frequency_table freq_table[20];
  120. static void __devinit cpufreq_table_init(void)
  121. {
  122. unsigned int i;
  123. unsigned int freq_cnt = 0;
  124. /* Construct the freq_table table from acpu_freq_tbl since the
  125. * freq_table values need to match frequencies specified in
  126. * acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init.
  127. */
  128. for (i = 0; acpu_freq_tbl[i].acpuclk_khz != 0
  129. && freq_cnt < ARRAY_SIZE(freq_table)-1; i++) {
  130. if (acpu_freq_tbl[i].use_for_scaling) {
  131. freq_table[freq_cnt].index = freq_cnt;
  132. freq_table[freq_cnt].frequency
  133. = acpu_freq_tbl[i].acpuclk_khz;
  134. freq_cnt++;
  135. }
  136. }
  137. /* freq_table not big enough to store all usable freqs. */
  138. BUG_ON(acpu_freq_tbl[i].acpuclk_khz != 0);
  139. freq_table[freq_cnt].index = freq_cnt;
  140. freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END;
  141. pr_info("%d scaling frequencies supported.\n", freq_cnt);
  142. }
  143. #endif
  144. struct clock_state {
  145. struct clkctl_acpu_speed *current_speed;
  146. struct mutex lock;
  147. struct clk *ebi1_clk;
  148. int (*acpu_set_vdd) (int mvolts);
  149. };
  150. static struct clock_state drv_state = { 0 };
  151. static void scpll_set_freq(uint32_t lval, unsigned freq_switch)
  152. {
  153. uint32_t regval;
  154. if (lval > 33)
  155. lval = 33;
  156. if (lval < 10)
  157. lval = 10;
  158. /* wait for any calibrations or frequency switches to finish */
  159. while (readl(SCPLL_STATUS_ADDR) & 0x3)
  160. ;
  161. /* write the new L val and switch mode */
  162. regval = readl(SCPLL_FSM_CTL_EXT_ADDR);
  163. regval &= ~(0x3f << 3);
  164. regval |= (lval << 3);
  165. if (freq_switch == SIMPLE_SLEW)
  166. regval |= (0x1 << 9);
  167. regval &= ~(0x3 << 0);
  168. regval |= (freq_switch << 0);
  169. writel(regval, SCPLL_FSM_CTL_EXT_ADDR);
  170. dmb();
  171. /* put in normal mode */
  172. regval = readl(SCPLL_CTL_ADDR);
  173. regval |= 0x7;
  174. writel(regval, SCPLL_CTL_ADDR);
  175. dmb();
  176. /* wait for frequency switch to finish */
  177. while (readl(SCPLL_STATUS_ADDR) & 0x1)
  178. ;
  179. /* status bit seems to clear early, using
  180. * 100us to handle the worst case. */
  181. udelay(100);
  182. }
  183. static void scpll_apps_enable(bool state)
  184. {
  185. uint32_t regval;
  186. if (state)
  187. pr_debug("Enabling PLL 3\n");
  188. else
  189. pr_debug("Disabling PLL 3\n");
  190. /* Wait for any frequency switches to finish. */
  191. while (readl(SCPLL_STATUS_ADDR) & 0x1)
  192. ;
  193. /* put the pll in standby mode */
  194. regval = readl(SCPLL_CTL_ADDR);
  195. regval &= ~(0x7);
  196. regval |= (0x2);
  197. writel(regval, SCPLL_CTL_ADDR);
  198. dmb();
  199. if (state) {
  200. /* put the pll in normal mode */
  201. regval = readl(SCPLL_CTL_ADDR);
  202. regval |= (0x7);
  203. writel(regval, SCPLL_CTL_ADDR);
  204. udelay(200);
  205. } else {
  206. /* put the pll in power down mode */
  207. regval = readl(SCPLL_CTL_ADDR);
  208. regval &= ~(0x7);
  209. writel(regval, SCPLL_CTL_ADDR);
  210. }
  211. udelay(62);
  212. if (state)
  213. pr_debug("PLL 3 Enabled\n");
  214. else
  215. pr_debug("PLL 3 Disabled\n");
  216. }
  217. static void scpll_init(void)
  218. {
  219. uint32_t regval;
  220. #define L_VAL_384MHZ 0xA
  221. #define L_VAL_768MHZ 0x14
  222. pr_debug("Initializing PLL 3\n");
  223. /* power down scpll */
  224. writel(0x0, SCPLL_CTL_ADDR);
  225. dmb();
  226. /* set bypassnl, put into standby */
  227. writel(0x00400002, SCPLL_CTL_ADDR);
  228. /* set bypassnl, reset_n, full calibration */
  229. writel(0x00600004, SCPLL_CTL_ADDR);
  230. /* Ensure register write to initiate calibration has taken
  231. effect before reading status flag */
  232. dmb();
  233. /* wait for cal_all_done */
  234. while (readl(SCPLL_STATUS_ADDR) & 0x2)
  235. ;
  236. /* Start: Set of experimentally derived steps
  237. * to work around a h/w bug. */
  238. /* Put the pll in normal mode */
  239. scpll_apps_enable(1);
  240. /* SHOT switch to 384 MHz */
  241. regval = readl(SCPLL_FSM_CTL_EXT_ADDR);
  242. regval &= ~(0x3f << 3);
  243. regval |= (L_VAL_384MHZ << 3);
  244. regval &= ~0x7;
  245. regval |= SHOT_SWITCH;
  246. writel(regval, SCPLL_FSM_CTL_EXT_ADDR);
  247. /* Trigger the freq switch by putting pll in normal mode. */
  248. regval = readl(SCPLL_CTL_ADDR);
  249. regval |= (0x7);
  250. writel(regval, SCPLL_CTL_ADDR);
  251. /* Wait for frequency switch to finish */
  252. while (readl(SCPLL_STATUS_ADDR) & 0x1)
  253. ;
  254. /* Status bit seems to clear early, using
  255. * 800 microseconds for the worst case. */
  256. udelay(800);
  257. /* HOP switch to 768 MHz. */
  258. regval = readl(SCPLL_FSM_CTL_EXT_ADDR);
  259. regval &= ~(0x3f << 3);
  260. regval |= (L_VAL_768MHZ << 3);
  261. regval &= ~0x7;
  262. regval |= HOP_SWITCH;
  263. writel(regval, SCPLL_FSM_CTL_EXT_ADDR);
  264. /* Trigger the freq switch by putting pll in normal mode. */
  265. regval = readl(SCPLL_CTL_ADDR);
  266. regval |= (0x7);
  267. writel(regval, SCPLL_CTL_ADDR);
  268. /* Wait for frequency switch to finish */
  269. while (readl(SCPLL_STATUS_ADDR) & 0x1)
  270. ;
  271. /* Status bit seems to clear early, using
  272. * 100 microseconds for the worst case. */
  273. udelay(100);
  274. /* End: Work around for h/w bug */
  275. /* Power down scpll */
  276. scpll_apps_enable(0);
  277. }
  278. static void config_pll(struct clkctl_acpu_speed *s)
  279. {
  280. uint32_t regval;
  281. if (s->pll == ACPU_PLL_3)
  282. scpll_set_freq(s->sc_l_value, HOP_SWITCH);
  283. /* Configure the PLL divider mux if we plan to use it. */
  284. else if (s->sc_core_src_sel_mask == 0) {
  285. /* get the current clock source selection */
  286. regval = readl(SPSS_CLK_SEL_ADDR) & 0x1;
  287. /* configure the other clock source, then switch to it,
  288. * using the glitch free mux */
  289. switch (regval) {
  290. case 0x0:
  291. regval = readl(SPSS_CLK_CNTL_ADDR);
  292. regval &= ~(0x7 << 4 | 0xf);
  293. regval |= (s->acpuclk_src_sel << 4);
  294. regval |= (s->acpuclk_src_div << 0);
  295. writel(regval, SPSS_CLK_CNTL_ADDR);
  296. regval = readl(SPSS_CLK_SEL_ADDR);
  297. regval |= 0x1;
  298. writel(regval, SPSS_CLK_SEL_ADDR);
  299. break;
  300. case 0x1:
  301. regval = readl(SPSS_CLK_CNTL_ADDR);
  302. regval &= ~(0x7 << 12 | 0xf << 8);
  303. regval |= (s->acpuclk_src_sel << 12);
  304. regval |= (s->acpuclk_src_div << 8);
  305. writel(regval, SPSS_CLK_CNTL_ADDR);
  306. regval = readl(SPSS_CLK_SEL_ADDR);
  307. regval &= ~0x1;
  308. writel(regval, SPSS_CLK_SEL_ADDR);
  309. break;
  310. }
  311. dmb();
  312. }
  313. regval = readl(SPSS_CLK_SEL_ADDR);
  314. regval &= ~(0x3 << 1);
  315. regval |= (s->sc_core_src_sel_mask << 1);
  316. writel(regval, SPSS_CLK_SEL_ADDR);
  317. }
  318. static int acpuclk_set_vdd_level(int vdd)
  319. {
  320. if (drv_state.acpu_set_vdd) {
  321. pr_debug("Switching VDD to %d mV\n", vdd);
  322. return drv_state.acpu_set_vdd(vdd);
  323. } else {
  324. /* Assume that the PMIC supports scaling the processor
  325. * to its maximum frequency at its default voltage.
  326. */
  327. return 0;
  328. }
  329. }
  330. static int acpuclk_8x50_set_rate(int cpu, unsigned long rate,
  331. enum setrate_reason reason)
  332. {
  333. struct clkctl_acpu_speed *tgt_s, *strt_s;
  334. int res, rc = 0;
  335. int freq_index = 0;
  336. if (reason == SETRATE_CPUFREQ)
  337. mutex_lock(&drv_state.lock);
  338. strt_s = drv_state.current_speed;
  339. if (rate == strt_s->acpuclk_khz)
  340. goto out;
  341. for (tgt_s = acpu_freq_tbl; tgt_s->acpuclk_khz != 0; tgt_s++) {
  342. if (tgt_s->acpuclk_khz == rate)
  343. break;
  344. freq_index++;
  345. }
  346. if (tgt_s->acpuclk_khz == 0) {
  347. rc = -EINVAL;
  348. goto out;
  349. }
  350. if (reason == SETRATE_CPUFREQ) {
  351. /* Increase VDD if needed. */
  352. if (tgt_s->vdd > strt_s->vdd) {
  353. rc = acpuclk_set_vdd_level(tgt_s->vdd);
  354. if (rc) {
  355. pr_err("Unable to increase ACPU vdd (%d)\n",
  356. rc);
  357. goto out;
  358. }
  359. }
  360. } else if (reason == SETRATE_PC
  361. && rate != POWER_COLLAPSE_KHZ) {
  362. /* Returning from PC. ACPU is running on AXI source.
  363. * Step up to PLL0 before ramping up higher. */
  364. config_pll(PLL0_S);
  365. }
  366. pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n",
  367. strt_s->acpuclk_khz, tgt_s->acpuclk_khz);
  368. if (strt_s->pll != ACPU_PLL_3 && tgt_s->pll != ACPU_PLL_3) {
  369. config_pll(tgt_s);
  370. } else if (strt_s->pll != ACPU_PLL_3 && tgt_s->pll == ACPU_PLL_3) {
  371. scpll_apps_enable(1);
  372. config_pll(tgt_s);
  373. } else if (strt_s->pll == ACPU_PLL_3 && tgt_s->pll != ACPU_PLL_3) {
  374. config_pll(tgt_s);
  375. scpll_apps_enable(0);
  376. } else {
  377. /* Temporarily switch to PLL0 while reconfiguring PLL3. */
  378. config_pll(PLL0_S);
  379. config_pll(tgt_s);
  380. }
  381. /* Update the driver state with the new clock freq */
  382. drv_state.current_speed = tgt_s;
  383. /* Re-adjust lpj for the new clock speed. */
  384. loops_per_jiffy = tgt_s->lpj;
  385. /* Nothing else to do for SWFI. */
  386. if (reason == SETRATE_SWFI)
  387. goto out;
  388. if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
  389. res = clk_set_rate(drv_state.ebi1_clk,
  390. tgt_s->axiclk_khz * 1000);
  391. if (res < 0)
  392. pr_warning("Setting AXI min rate failed (%d)\n", res);
  393. }
  394. /* Nothing else to do for power collapse */
  395. if (reason == SETRATE_PC)
  396. goto out;
  397. /* Drop VDD level if we can. */
  398. if (tgt_s->vdd < strt_s->vdd) {
  399. res = acpuclk_set_vdd_level(tgt_s->vdd);
  400. if (res)
  401. pr_warning("Unable to drop ACPU vdd (%d)\n", res);
  402. }
  403. pr_debug("ACPU speed change complete\n");
  404. out:
  405. if (reason == SETRATE_CPUFREQ)
  406. mutex_unlock(&drv_state.lock);
  407. return rc;
  408. }
  409. static void __devinit acpuclk_hw_init(void)
  410. {
  411. struct clkctl_acpu_speed *speed;
  412. uint32_t div, sel, regval;
  413. int res;
  414. /* Determine the source of the Scorpion clock. */
  415. regval = readl(SPSS_CLK_SEL_ADDR);
  416. switch ((regval & 0x6) >> 1) {
  417. case 0: /* raw source clock */
  418. case 3: /* low jitter PLL1 (768Mhz) */
  419. if (regval & 0x1) {
  420. sel = ((readl(SPSS_CLK_CNTL_ADDR) >> 4) & 0x7);
  421. div = ((readl(SPSS_CLK_CNTL_ADDR) >> 0) & 0xf);
  422. } else {
  423. sel = ((readl(SPSS_CLK_CNTL_ADDR) >> 12) & 0x7);
  424. div = ((readl(SPSS_CLK_CNTL_ADDR) >> 8) & 0xf);
  425. }
  426. /* Find the matching clock rate. */
  427. for (speed = acpu_freq_tbl; speed->acpuclk_khz != 0; speed++) {
  428. if (speed->acpuclk_src_sel == sel &&
  429. speed->acpuclk_src_div == div)
  430. break;
  431. }
  432. break;
  433. case 1: /* unbuffered scorpion pll (384Mhz to 998.4Mhz) */
  434. sel = ((readl(SCPLL_FSM_CTL_EXT_ADDR) >> 3) & 0x3f);
  435. /* Find the matching clock rate. */
  436. for (speed = acpu_freq_tbl; speed->acpuclk_khz != 0; speed++) {
  437. if (speed->sc_l_value == sel &&
  438. speed->sc_core_src_sel_mask == 1)
  439. break;
  440. }
  441. break;
  442. case 2: /* AXI bus clock (128Mhz) */
  443. speed = AXI_S;
  444. break;
  445. default:
  446. BUG();
  447. }
  448. /* Initialize scpll only if it wasn't already initialized by the boot
  449. * loader. If the CPU is already running on scpll, then the scpll was
  450. * initialized by the boot loader. */
  451. if (speed->pll != ACPU_PLL_3)
  452. scpll_init();
  453. if (speed->acpuclk_khz == 0) {
  454. pr_err("Error - ACPU clock reports invalid speed\n");
  455. return;
  456. }
  457. drv_state.current_speed = speed;
  458. res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000);
  459. if (res < 0)
  460. pr_warning("Setting AXI min rate failed (%d)\n", res);
  461. res = clk_enable(drv_state.ebi1_clk);
  462. if (res < 0)
  463. pr_warning("Enabling AXI clock failed (%d)\n", res);
  464. pr_info("ACPU running at %d KHz\n", speed->acpuclk_khz);
  465. }
  466. static unsigned long acpuclk_8x50_get_rate(int cpu)
  467. {
  468. return drv_state.current_speed->acpuclk_khz;
  469. }
  470. /* Spare register populated with efuse data on max ACPU freq. */
  471. #define CT_CSR_PHYS 0xA8700000
  472. #define TCSR_SPARE2_ADDR (ct_csr_base + 0x60)
  473. #define PLL0_M_VAL_ADDR (MSM_CLK_CTL_BASE + 0x308)
  474. static void __devinit acpu_freq_tbl_fixup(void)
  475. {
  476. void __iomem *ct_csr_base;
  477. uint32_t tcsr_spare2, pll0_m_val;
  478. unsigned int max_acpu_khz;
  479. unsigned int i;
  480. ct_csr_base = ioremap(CT_CSR_PHYS, PAGE_SIZE);
  481. BUG_ON(ct_csr_base == NULL);
  482. tcsr_spare2 = readl(TCSR_SPARE2_ADDR);
  483. /* Check if the register is supported and meaningful. */
  484. if ((tcsr_spare2 & 0xF000) != 0xA000) {
  485. pr_info("Efuse data on Max ACPU freq not present.\n");
  486. goto skip_efuse_fixup;
  487. }
  488. switch (tcsr_spare2 & 0xF0) {
  489. case 0x70:
  490. acpu_freq_tbl = acpu_freq_tbl_768;
  491. max_acpu_khz = 768000;
  492. break;
  493. case 0x30:
  494. case 0x00:
  495. max_acpu_khz = 998400;
  496. break;
  497. case 0x10:
  498. max_acpu_khz = 1267200;
  499. break;
  500. default:
  501. pr_warning("Invalid efuse data (%x) on Max ACPU freq!\n",
  502. tcsr_spare2);
  503. goto skip_efuse_fixup;
  504. }
  505. pr_info("Max ACPU freq from efuse data is %d KHz\n", max_acpu_khz);
  506. for (i = 0; acpu_freq_tbl[i].acpuclk_khz != 0; i++) {
  507. if (acpu_freq_tbl[i].acpuclk_khz > max_acpu_khz) {
  508. acpu_freq_tbl[i].acpuclk_khz = 0;
  509. break;
  510. }
  511. }
  512. skip_efuse_fixup:
  513. iounmap(ct_csr_base);
  514. /* pll0_m_val will be 36 when PLL0 is run at 235MHz
  515. * instead of the usual 245MHz. */
  516. pll0_m_val = readl(PLL0_M_VAL_ADDR) & 0x7FFFF;
  517. if (pll0_m_val == 36)
  518. PLL0_S->acpuclk_khz = 235930;
  519. for (i = 0; acpu_freq_tbl[i].acpuclk_khz != 0; i++) {
  520. if (acpu_freq_tbl[i].vdd > TPS65023_MAX_DCDC1) {
  521. acpu_freq_tbl[i].acpuclk_khz = 0;
  522. break;
  523. }
  524. }
  525. }
  526. /* Initalize the lpj field in the acpu_freq_tbl. */
  527. static void __devinit lpj_init(void)
  528. {
  529. int i;
  530. const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
  531. for (i = 0; acpu_freq_tbl[i].acpuclk_khz; i++) {
  532. acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy,
  533. base_clk->acpuclk_khz,
  534. acpu_freq_tbl[i].acpuclk_khz);
  535. }
  536. }
  537. static int qsd8x50_tps65023_set_dcdc1(int mVolts)
  538. {
  539. int rc = 0;
  540. #ifdef CONFIG_QSD_SVS
  541. rc = tps65023_set_dcdc1_level(mVolts);
  542. /*
  543. * By default the TPS65023 will be initialized to 1.225V.
  544. * So we can safely switch to any frequency within this
  545. * voltage even if the device is not probed/ready.
  546. */
  547. if (rc == -ENODEV && mVolts <= CONFIG_QSD_PMIC_DEFAULT_DCDC1)
  548. rc = 0;
  549. #else
  550. /*
  551. * Disallow frequencies not supported in the default PMIC
  552. * output voltage.
  553. */
  554. if (mVolts > CONFIG_QSD_PMIC_DEFAULT_DCDC1)
  555. rc = -EFAULT;
  556. #endif
  557. return rc;
  558. }
  559. static struct acpuclk_data acpuclk_8x50_data = {
  560. .set_rate = acpuclk_8x50_set_rate,
  561. .get_rate = acpuclk_8x50_get_rate,
  562. .power_collapse_khz = POWER_COLLAPSE_KHZ,
  563. .wait_for_irq_khz = WAIT_FOR_IRQ_KHZ,
  564. .switch_time_us = 20,
  565. };
  566. static int __devinit acpuclk_8x50_probe(struct platform_device *pdev)
  567. {
  568. mutex_init(&drv_state.lock);
  569. drv_state.acpu_set_vdd = qsd8x50_tps65023_set_dcdc1;
  570. drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk");
  571. BUG_ON(IS_ERR(drv_state.ebi1_clk));
  572. acpu_freq_tbl_fixup();
  573. acpuclk_hw_init();
  574. lpj_init();
  575. /* Set a lower bound for ACPU rate for boot. This limits the
  576. * maximum frequency hop caused by the first CPUFREQ switch. */
  577. if (drv_state.current_speed->acpuclk_khz < PLL0_S->acpuclk_khz)
  578. acpuclk_set_rate(0, PLL0_S->acpuclk_khz, SETRATE_CPUFREQ);
  579. acpuclk_register(&acpuclk_8x50_data);
  580. #ifdef CONFIG_CPU_FREQ_MSM
  581. cpufreq_table_init();
  582. cpufreq_frequency_table_get_attr(freq_table, smp_processor_id());
  583. #endif
  584. return 0;
  585. }
  586. static struct platform_driver acpuclk_8x50_driver = {
  587. .probe = acpuclk_8x50_probe,
  588. .driver = {
  589. .name = "acpuclk-8x50",
  590. .owner = THIS_MODULE,
  591. },
  592. };
  593. static int __init acpuclk_8x50_init(void)
  594. {
  595. return platform_driver_register(&acpuclk_8x50_driver);
  596. }
  597. postcore_initcall(acpuclk_8x50_init);