exynos4210-cpufreq.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * EXYNOS4 - CPU frequency scaling support
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/err.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/slab.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <linux/cpufreq.h>
  19. #include <linux/notifier.h>
  20. #include <linux/suspend.h>
  21. #include <mach/map.h>
  22. #include <mach/regs-clock.h>
  23. #include <mach/regs-mem.h>
  24. #include <plat/clock.h>
  25. #include <plat/pm.h>
  26. static struct clk *cpu_clk;
  27. static struct clk *moutcore;
  28. static struct clk *mout_mpll;
  29. static struct clk *mout_apll;
  30. static struct regulator *arm_regulator;
  31. static struct regulator *int_regulator;
  32. static struct cpufreq_freqs freqs;
  33. static unsigned int memtype;
  34. static unsigned int locking_frequency;
  35. static bool frequency_locked;
  36. static DEFINE_MUTEX(cpufreq_lock);
  37. enum exynos4_memory_type {
  38. DDR2 = 4,
  39. LPDDR2,
  40. DDR3,
  41. };
  42. enum cpufreq_level_index {
  43. L0, L1, L2, L3, CPUFREQ_LEVEL_END,
  44. };
  45. static struct cpufreq_frequency_table exynos4_freq_table[] = {
  46. {L0, 1000*1000},
  47. {L1, 800*1000},
  48. {L2, 400*1000},
  49. {L3, 100*1000},
  50. {0, CPUFREQ_TABLE_END},
  51. };
  52. static unsigned int clkdiv_cpu0[CPUFREQ_LEVEL_END][7] = {
  53. /*
  54. * Clock divider value for following
  55. * { DIVCORE, DIVCOREM0, DIVCOREM1, DIVPERIPH,
  56. * DIVATB, DIVPCLK_DBG, DIVAPLL }
  57. */
  58. /* ARM L0: 1000MHz */
  59. { 0, 3, 7, 3, 3, 0, 1 },
  60. /* ARM L1: 800MHz */
  61. { 0, 3, 7, 3, 3, 0, 1 },
  62. /* ARM L2: 400MHz */
  63. { 0, 1, 3, 1, 3, 0, 1 },
  64. /* ARM L3: 100MHz */
  65. { 0, 0, 1, 0, 3, 1, 1 },
  66. };
  67. static unsigned int clkdiv_cpu1[CPUFREQ_LEVEL_END][2] = {
  68. /*
  69. * Clock divider value for following
  70. * { DIVCOPY, DIVHPM }
  71. */
  72. /* ARM L0: 1000MHz */
  73. { 3, 0 },
  74. /* ARM L1: 800MHz */
  75. { 3, 0 },
  76. /* ARM L2: 400MHz */
  77. { 3, 0 },
  78. /* ARM L3: 100MHz */
  79. { 3, 0 },
  80. };
  81. static unsigned int clkdiv_dmc0[CPUFREQ_LEVEL_END][8] = {
  82. /*
  83. * Clock divider value for following
  84. * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD
  85. * DIVDMCP, DIVCOPY2, DIVCORE_TIMERS }
  86. */
  87. /* DMC L0: 400MHz */
  88. { 3, 1, 1, 1, 1, 1, 3, 1 },
  89. /* DMC L1: 400MHz */
  90. { 3, 1, 1, 1, 1, 1, 3, 1 },
  91. /* DMC L2: 266.7MHz */
  92. { 7, 1, 1, 2, 1, 1, 3, 1 },
  93. /* DMC L3: 200MHz */
  94. { 7, 1, 1, 3, 1, 1, 3, 1 },
  95. };
  96. static unsigned int clkdiv_top[CPUFREQ_LEVEL_END][5] = {
  97. /*
  98. * Clock divider value for following
  99. * { DIVACLK200, DIVACLK100, DIVACLK160, DIVACLK133, DIVONENAND }
  100. */
  101. /* ACLK200 L0: 200MHz */
  102. { 3, 7, 4, 5, 1 },
  103. /* ACLK200 L1: 200MHz */
  104. { 3, 7, 4, 5, 1 },
  105. /* ACLK200 L2: 160MHz */
  106. { 4, 7, 5, 7, 1 },
  107. /* ACLK200 L3: 133.3MHz */
  108. { 5, 7, 7, 7, 1 },
  109. };
  110. static unsigned int clkdiv_lr_bus[CPUFREQ_LEVEL_END][2] = {
  111. /*
  112. * Clock divider value for following
  113. * { DIVGDL/R, DIVGPL/R }
  114. */
  115. /* ACLK_GDL/R L0: 200MHz */
  116. { 3, 1 },
  117. /* ACLK_GDL/R L1: 200MHz */
  118. { 3, 1 },
  119. /* ACLK_GDL/R L2: 160MHz */
  120. { 4, 1 },
  121. /* ACLK_GDL/R L3: 133.3MHz */
  122. { 5, 1 },
  123. };
  124. struct cpufreq_voltage_table {
  125. unsigned int index; /* any */
  126. unsigned int arm_volt; /* uV */
  127. unsigned int int_volt;
  128. };
  129. static struct cpufreq_voltage_table exynos4_volt_table[CPUFREQ_LEVEL_END] = {
  130. {
  131. .index = L0,
  132. .arm_volt = 1200000,
  133. .int_volt = 1100000,
  134. }, {
  135. .index = L1,
  136. .arm_volt = 1100000,
  137. .int_volt = 1100000,
  138. }, {
  139. .index = L2,
  140. .arm_volt = 1000000,
  141. .int_volt = 1000000,
  142. }, {
  143. .index = L3,
  144. .arm_volt = 900000,
  145. .int_volt = 1000000,
  146. },
  147. };
  148. static unsigned int exynos4_apll_pms_table[CPUFREQ_LEVEL_END] = {
  149. /* APLL FOUT L0: 1000MHz */
  150. ((250 << 16) | (6 << 8) | 1),
  151. /* APLL FOUT L1: 800MHz */
  152. ((200 << 16) | (6 << 8) | 1),
  153. /* APLL FOUT L2 : 400MHz */
  154. ((200 << 16) | (6 << 8) | 2),
  155. /* APLL FOUT L3: 100MHz */
  156. ((200 << 16) | (6 << 8) | 4),
  157. };
  158. static int exynos4_verify_speed(struct cpufreq_policy *policy)
  159. {
  160. return cpufreq_frequency_table_verify(policy, exynos4_freq_table);
  161. }
  162. static unsigned int exynos4_getspeed(unsigned int cpu)
  163. {
  164. return clk_get_rate(cpu_clk) / 1000;
  165. }
  166. static void exynos4_set_clkdiv(unsigned int div_index)
  167. {
  168. unsigned int tmp;
  169. /* Change Divider - CPU0 */
  170. tmp = __raw_readl(S5P_CLKDIV_CPU);
  171. tmp &= ~(S5P_CLKDIV_CPU0_CORE_MASK | S5P_CLKDIV_CPU0_COREM0_MASK |
  172. S5P_CLKDIV_CPU0_COREM1_MASK | S5P_CLKDIV_CPU0_PERIPH_MASK |
  173. S5P_CLKDIV_CPU0_ATB_MASK | S5P_CLKDIV_CPU0_PCLKDBG_MASK |
  174. S5P_CLKDIV_CPU0_APLL_MASK);
  175. tmp |= ((clkdiv_cpu0[div_index][0] << S5P_CLKDIV_CPU0_CORE_SHIFT) |
  176. (clkdiv_cpu0[div_index][1] << S5P_CLKDIV_CPU0_COREM0_SHIFT) |
  177. (clkdiv_cpu0[div_index][2] << S5P_CLKDIV_CPU0_COREM1_SHIFT) |
  178. (clkdiv_cpu0[div_index][3] << S5P_CLKDIV_CPU0_PERIPH_SHIFT) |
  179. (clkdiv_cpu0[div_index][4] << S5P_CLKDIV_CPU0_ATB_SHIFT) |
  180. (clkdiv_cpu0[div_index][5] << S5P_CLKDIV_CPU0_PCLKDBG_SHIFT) |
  181. (clkdiv_cpu0[div_index][6] << S5P_CLKDIV_CPU0_APLL_SHIFT));
  182. __raw_writel(tmp, S5P_CLKDIV_CPU);
  183. do {
  184. tmp = __raw_readl(S5P_CLKDIV_STATCPU);
  185. } while (tmp & 0x1111111);
  186. /* Change Divider - CPU1 */
  187. tmp = __raw_readl(S5P_CLKDIV_CPU1);
  188. tmp &= ~((0x7 << 4) | 0x7);
  189. tmp |= ((clkdiv_cpu1[div_index][0] << 4) |
  190. (clkdiv_cpu1[div_index][1] << 0));
  191. __raw_writel(tmp, S5P_CLKDIV_CPU1);
  192. do {
  193. tmp = __raw_readl(S5P_CLKDIV_STATCPU1);
  194. } while (tmp & 0x11);
  195. /* Change Divider - DMC0 */
  196. tmp = __raw_readl(S5P_CLKDIV_DMC0);
  197. tmp &= ~(S5P_CLKDIV_DMC0_ACP_MASK | S5P_CLKDIV_DMC0_ACPPCLK_MASK |
  198. S5P_CLKDIV_DMC0_DPHY_MASK | S5P_CLKDIV_DMC0_DMC_MASK |
  199. S5P_CLKDIV_DMC0_DMCD_MASK | S5P_CLKDIV_DMC0_DMCP_MASK |
  200. S5P_CLKDIV_DMC0_COPY2_MASK | S5P_CLKDIV_DMC0_CORETI_MASK);
  201. tmp |= ((clkdiv_dmc0[div_index][0] << S5P_CLKDIV_DMC0_ACP_SHIFT) |
  202. (clkdiv_dmc0[div_index][1] << S5P_CLKDIV_DMC0_ACPPCLK_SHIFT) |
  203. (clkdiv_dmc0[div_index][2] << S5P_CLKDIV_DMC0_DPHY_SHIFT) |
  204. (clkdiv_dmc0[div_index][3] << S5P_CLKDIV_DMC0_DMC_SHIFT) |
  205. (clkdiv_dmc0[div_index][4] << S5P_CLKDIV_DMC0_DMCD_SHIFT) |
  206. (clkdiv_dmc0[div_index][5] << S5P_CLKDIV_DMC0_DMCP_SHIFT) |
  207. (clkdiv_dmc0[div_index][6] << S5P_CLKDIV_DMC0_COPY2_SHIFT) |
  208. (clkdiv_dmc0[div_index][7] << S5P_CLKDIV_DMC0_CORETI_SHIFT));
  209. __raw_writel(tmp, S5P_CLKDIV_DMC0);
  210. do {
  211. tmp = __raw_readl(S5P_CLKDIV_STAT_DMC0);
  212. } while (tmp & 0x11111111);
  213. /* Change Divider - TOP */
  214. tmp = __raw_readl(S5P_CLKDIV_TOP);
  215. tmp &= ~(S5P_CLKDIV_TOP_ACLK200_MASK | S5P_CLKDIV_TOP_ACLK100_MASK |
  216. S5P_CLKDIV_TOP_ACLK160_MASK | S5P_CLKDIV_TOP_ACLK133_MASK |
  217. S5P_CLKDIV_TOP_ONENAND_MASK);
  218. tmp |= ((clkdiv_top[div_index][0] << S5P_CLKDIV_TOP_ACLK200_SHIFT) |
  219. (clkdiv_top[div_index][1] << S5P_CLKDIV_TOP_ACLK100_SHIFT) |
  220. (clkdiv_top[div_index][2] << S5P_CLKDIV_TOP_ACLK160_SHIFT) |
  221. (clkdiv_top[div_index][3] << S5P_CLKDIV_TOP_ACLK133_SHIFT) |
  222. (clkdiv_top[div_index][4] << S5P_CLKDIV_TOP_ONENAND_SHIFT));
  223. __raw_writel(tmp, S5P_CLKDIV_TOP);
  224. do {
  225. tmp = __raw_readl(S5P_CLKDIV_STAT_TOP);
  226. } while (tmp & 0x11111);
  227. /* Change Divider - LEFTBUS */
  228. tmp = __raw_readl(S5P_CLKDIV_LEFTBUS);
  229. tmp &= ~(S5P_CLKDIV_BUS_GDLR_MASK | S5P_CLKDIV_BUS_GPLR_MASK);
  230. tmp |= ((clkdiv_lr_bus[div_index][0] << S5P_CLKDIV_BUS_GDLR_SHIFT) |
  231. (clkdiv_lr_bus[div_index][1] << S5P_CLKDIV_BUS_GPLR_SHIFT));
  232. __raw_writel(tmp, S5P_CLKDIV_LEFTBUS);
  233. do {
  234. tmp = __raw_readl(S5P_CLKDIV_STAT_LEFTBUS);
  235. } while (tmp & 0x11);
  236. /* Change Divider - RIGHTBUS */
  237. tmp = __raw_readl(S5P_CLKDIV_RIGHTBUS);
  238. tmp &= ~(S5P_CLKDIV_BUS_GDLR_MASK | S5P_CLKDIV_BUS_GPLR_MASK);
  239. tmp |= ((clkdiv_lr_bus[div_index][0] << S5P_CLKDIV_BUS_GDLR_SHIFT) |
  240. (clkdiv_lr_bus[div_index][1] << S5P_CLKDIV_BUS_GPLR_SHIFT));
  241. __raw_writel(tmp, S5P_CLKDIV_RIGHTBUS);
  242. do {
  243. tmp = __raw_readl(S5P_CLKDIV_STAT_RIGHTBUS);
  244. } while (tmp & 0x11);
  245. }
  246. static void exynos4_set_apll(unsigned int index)
  247. {
  248. unsigned int tmp;
  249. /* 1. MUX_CORE_SEL = MPLL, ARMCLK uses MPLL for lock time */
  250. clk_set_parent(moutcore, mout_mpll);
  251. do {
  252. tmp = (__raw_readl(S5P_CLKMUX_STATCPU)
  253. >> S5P_CLKSRC_CPU_MUXCORE_SHIFT);
  254. tmp &= 0x7;
  255. } while (tmp != 0x2);
  256. /* 2. Set APLL Lock time */
  257. __raw_writel(S5P_APLL_LOCKTIME, S5P_APLL_LOCK);
  258. /* 3. Change PLL PMS values */
  259. tmp = __raw_readl(S5P_APLL_CON0);
  260. tmp &= ~((0x3ff << 16) | (0x3f << 8) | (0x7 << 0));
  261. tmp |= exynos4_apll_pms_table[index];
  262. __raw_writel(tmp, S5P_APLL_CON0);
  263. /* 4. wait_lock_time */
  264. do {
  265. tmp = __raw_readl(S5P_APLL_CON0);
  266. } while (!(tmp & (0x1 << S5P_APLLCON0_LOCKED_SHIFT)));
  267. /* 5. MUX_CORE_SEL = APLL */
  268. clk_set_parent(moutcore, mout_apll);
  269. do {
  270. tmp = __raw_readl(S5P_CLKMUX_STATCPU);
  271. tmp &= S5P_CLKMUX_STATCPU_MUXCORE_MASK;
  272. } while (tmp != (0x1 << S5P_CLKSRC_CPU_MUXCORE_SHIFT));
  273. }
  274. static void exynos4_set_frequency(unsigned int old_index, unsigned int new_index)
  275. {
  276. unsigned int tmp;
  277. if (old_index > new_index) {
  278. /* The frequency changing to L0 needs to change apll */
  279. if (freqs.new == exynos4_freq_table[L0].frequency) {
  280. /* 1. Change the system clock divider values */
  281. exynos4_set_clkdiv(new_index);
  282. /* 2. Change the apll m,p,s value */
  283. exynos4_set_apll(new_index);
  284. } else {
  285. /* 1. Change the system clock divider values */
  286. exynos4_set_clkdiv(new_index);
  287. /* 2. Change just s value in apll m,p,s value */
  288. tmp = __raw_readl(S5P_APLL_CON0);
  289. tmp &= ~(0x7 << 0);
  290. tmp |= (exynos4_apll_pms_table[new_index] & 0x7);
  291. __raw_writel(tmp, S5P_APLL_CON0);
  292. }
  293. }
  294. else if (old_index < new_index) {
  295. /* The frequency changing from L0 needs to change apll */
  296. if (freqs.old == exynos4_freq_table[L0].frequency) {
  297. /* 1. Change the apll m,p,s value */
  298. exynos4_set_apll(new_index);
  299. /* 2. Change the system clock divider values */
  300. exynos4_set_clkdiv(new_index);
  301. } else {
  302. /* 1. Change just s value in apll m,p,s value */
  303. tmp = __raw_readl(S5P_APLL_CON0);
  304. tmp &= ~(0x7 << 0);
  305. tmp |= (exynos4_apll_pms_table[new_index] & 0x7);
  306. __raw_writel(tmp, S5P_APLL_CON0);
  307. /* 2. Change the system clock divider values */
  308. exynos4_set_clkdiv(new_index);
  309. }
  310. }
  311. }
  312. static int exynos4_target(struct cpufreq_policy *policy,
  313. unsigned int target_freq,
  314. unsigned int relation)
  315. {
  316. unsigned int index, old_index;
  317. unsigned int arm_volt, int_volt;
  318. int err = -EINVAL;
  319. freqs.old = exynos4_getspeed(policy->cpu);
  320. mutex_lock(&cpufreq_lock);
  321. if (frequency_locked && target_freq != locking_frequency) {
  322. err = -EAGAIN;
  323. goto out;
  324. }
  325. if (cpufreq_frequency_table_target(policy, exynos4_freq_table,
  326. freqs.old, relation, &old_index))
  327. goto out;
  328. if (cpufreq_frequency_table_target(policy, exynos4_freq_table,
  329. target_freq, relation, &index))
  330. goto out;
  331. err = 0;
  332. freqs.new = exynos4_freq_table[index].frequency;
  333. freqs.cpu = policy->cpu;
  334. if (freqs.new == freqs.old)
  335. goto out;
  336. /* get the voltage value */
  337. arm_volt = exynos4_volt_table[index].arm_volt;
  338. int_volt = exynos4_volt_table[index].int_volt;
  339. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  340. /* control regulator */
  341. if (freqs.new > freqs.old) {
  342. /* Voltage up */
  343. regulator_set_voltage(arm_regulator, arm_volt, arm_volt);
  344. regulator_set_voltage(int_regulator, int_volt, int_volt);
  345. }
  346. /* Clock Configuration Procedure */
  347. exynos4_set_frequency(old_index, index);
  348. /* control regulator */
  349. if (freqs.new < freqs.old) {
  350. /* Voltage down */
  351. regulator_set_voltage(arm_regulator, arm_volt, arm_volt);
  352. regulator_set_voltage(int_regulator, int_volt, int_volt);
  353. }
  354. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  355. out:
  356. mutex_unlock(&cpufreq_lock);
  357. return err;
  358. }
  359. #ifdef CONFIG_PM
  360. /*
  361. * These suspend/resume are used as syscore_ops, it is already too
  362. * late to set regulator voltages at this stage.
  363. */
  364. static int exynos4_cpufreq_suspend(struct cpufreq_policy *policy)
  365. {
  366. return 0;
  367. }
  368. static int exynos4_cpufreq_resume(struct cpufreq_policy *policy)
  369. {
  370. return 0;
  371. }
  372. #endif
  373. /**
  374. * exynos4_cpufreq_pm_notifier - block CPUFREQ's activities in suspend-resume
  375. * context
  376. * @notifier
  377. * @pm_event
  378. * @v
  379. *
  380. * While frequency_locked == true, target() ignores every frequency but
  381. * locking_frequency. The locking_frequency value is the initial frequency,
  382. * which is set by the bootloader. In order to eliminate possible
  383. * inconsistency in clock values, we save and restore frequencies during
  384. * suspend and resume and block CPUFREQ activities. Note that the standard
  385. * suspend/resume cannot be used as they are too deep (syscore_ops) for
  386. * regulator actions.
  387. */
  388. static int exynos4_cpufreq_pm_notifier(struct notifier_block *notifier,
  389. unsigned long pm_event, void *v)
  390. {
  391. struct cpufreq_policy *policy = cpufreq_cpu_get(0); /* boot CPU */
  392. static unsigned int saved_frequency;
  393. unsigned int temp;
  394. mutex_lock(&cpufreq_lock);
  395. switch (pm_event) {
  396. case PM_SUSPEND_PREPARE:
  397. if (frequency_locked)
  398. goto out;
  399. frequency_locked = true;
  400. if (locking_frequency) {
  401. saved_frequency = exynos4_getspeed(0);
  402. mutex_unlock(&cpufreq_lock);
  403. exynos4_target(policy, locking_frequency,
  404. CPUFREQ_RELATION_H);
  405. mutex_lock(&cpufreq_lock);
  406. }
  407. break;
  408. case PM_POST_SUSPEND:
  409. if (saved_frequency) {
  410. /*
  411. * While frequency_locked, only locking_frequency
  412. * is valid for target(). In order to use
  413. * saved_frequency while keeping frequency_locked,
  414. * we temporarly overwrite locking_frequency.
  415. */
  416. temp = locking_frequency;
  417. locking_frequency = saved_frequency;
  418. mutex_unlock(&cpufreq_lock);
  419. exynos4_target(policy, locking_frequency,
  420. CPUFREQ_RELATION_H);
  421. mutex_lock(&cpufreq_lock);
  422. locking_frequency = temp;
  423. }
  424. frequency_locked = false;
  425. break;
  426. }
  427. out:
  428. mutex_unlock(&cpufreq_lock);
  429. return NOTIFY_OK;
  430. }
  431. static struct notifier_block exynos4_cpufreq_nb = {
  432. .notifier_call = exynos4_cpufreq_pm_notifier,
  433. };
  434. static int exynos4_cpufreq_cpu_init(struct cpufreq_policy *policy)
  435. {
  436. int ret;
  437. policy->cur = policy->min = policy->max = exynos4_getspeed(policy->cpu);
  438. cpufreq_frequency_table_get_attr(exynos4_freq_table, policy->cpu);
  439. /* set the transition latency value */
  440. policy->cpuinfo.transition_latency = 100000;
  441. /*
  442. * EXYNOS4 multi-core processors has 2 cores
  443. * that the frequency cannot be set independently.
  444. * Each cpu is bound to the same speed.
  445. * So the affected cpu is all of the cpus.
  446. */
  447. cpumask_setall(policy->cpus);
  448. ret = cpufreq_frequency_table_cpuinfo(policy, exynos4_freq_table);
  449. if (ret)
  450. return ret;
  451. cpufreq_frequency_table_get_attr(exynos4_freq_table, policy->cpu);
  452. return 0;
  453. }
  454. static int exynos4_cpufreq_cpu_exit(struct cpufreq_policy *policy)
  455. {
  456. cpufreq_frequency_table_put_attr(policy->cpu);
  457. return 0;
  458. }
  459. static struct freq_attr *exynos4_cpufreq_attr[] = {
  460. &cpufreq_freq_attr_scaling_available_freqs,
  461. NULL,
  462. };
  463. static struct cpufreq_driver exynos4_driver = {
  464. .flags = CPUFREQ_STICKY,
  465. .verify = exynos4_verify_speed,
  466. .target = exynos4_target,
  467. .get = exynos4_getspeed,
  468. .init = exynos4_cpufreq_cpu_init,
  469. .exit = exynos4_cpufreq_cpu_exit,
  470. .name = "exynos4_cpufreq",
  471. .attr = exynos4_cpufreq_attr,
  472. #ifdef CONFIG_PM
  473. .suspend = exynos4_cpufreq_suspend,
  474. .resume = exynos4_cpufreq_resume,
  475. #endif
  476. };
  477. static int __init exynos4_cpufreq_init(void)
  478. {
  479. cpu_clk = clk_get(NULL, "armclk");
  480. if (IS_ERR(cpu_clk))
  481. return PTR_ERR(cpu_clk);
  482. locking_frequency = exynos4_getspeed(0);
  483. moutcore = clk_get(NULL, "moutcore");
  484. if (IS_ERR(moutcore))
  485. goto out;
  486. mout_mpll = clk_get(NULL, "mout_mpll");
  487. if (IS_ERR(mout_mpll))
  488. goto out;
  489. mout_apll = clk_get(NULL, "mout_apll");
  490. if (IS_ERR(mout_apll))
  491. goto out;
  492. arm_regulator = regulator_get(NULL, "vdd_arm");
  493. if (IS_ERR(arm_regulator)) {
  494. printk(KERN_ERR "failed to get resource %s\n", "vdd_arm");
  495. goto out;
  496. }
  497. int_regulator = regulator_get(NULL, "vdd_int");
  498. if (IS_ERR(int_regulator)) {
  499. printk(KERN_ERR "failed to get resource %s\n", "vdd_int");
  500. goto out;
  501. }
  502. /*
  503. * Check DRAM type.
  504. * Because DVFS level is different according to DRAM type.
  505. */
  506. memtype = __raw_readl(S5P_VA_DMC0 + S5P_DMC0_MEMCON_OFFSET);
  507. memtype = (memtype >> S5P_DMC0_MEMTYPE_SHIFT);
  508. memtype &= S5P_DMC0_MEMTYPE_MASK;
  509. if ((memtype < DDR2) && (memtype > DDR3)) {
  510. printk(KERN_ERR "%s: wrong memtype= 0x%x\n", __func__, memtype);
  511. goto out;
  512. } else {
  513. printk(KERN_DEBUG "%s: memtype= 0x%x\n", __func__, memtype);
  514. }
  515. register_pm_notifier(&exynos4_cpufreq_nb);
  516. return cpufreq_register_driver(&exynos4_driver);
  517. out:
  518. if (!IS_ERR(cpu_clk))
  519. clk_put(cpu_clk);
  520. if (!IS_ERR(moutcore))
  521. clk_put(moutcore);
  522. if (!IS_ERR(mout_mpll))
  523. clk_put(mout_mpll);
  524. if (!IS_ERR(mout_apll))
  525. clk_put(mout_apll);
  526. if (!IS_ERR(arm_regulator))
  527. regulator_put(arm_regulator);
  528. if (!IS_ERR(int_regulator))
  529. regulator_put(int_regulator);
  530. printk(KERN_ERR "%s: failed initialization\n", __func__);
  531. return -EINVAL;
  532. }
  533. late_initcall(exynos4_cpufreq_init);