s5pv210-cpufreq.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * CPU frequency scaling for S5PC110/S5PV210
  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/init.h>
  14. #include <linux/err.h>
  15. #include <linux/clk.h>
  16. #include <linux/io.h>
  17. #include <linux/cpufreq.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/reboot.h>
  22. #include <linux/regulator/consumer.h>
  23. static void __iomem *clk_base;
  24. static void __iomem *dmc_base[2];
  25. #define S5P_CLKREG(x) (clk_base + (x))
  26. #define S5P_APLL_LOCK S5P_CLKREG(0x00)
  27. #define S5P_APLL_CON S5P_CLKREG(0x100)
  28. #define S5P_CLK_SRC0 S5P_CLKREG(0x200)
  29. #define S5P_CLK_SRC2 S5P_CLKREG(0x208)
  30. #define S5P_CLK_DIV0 S5P_CLKREG(0x300)
  31. #define S5P_CLK_DIV2 S5P_CLKREG(0x308)
  32. #define S5P_CLK_DIV6 S5P_CLKREG(0x318)
  33. #define S5P_CLKDIV_STAT0 S5P_CLKREG(0x1000)
  34. #define S5P_CLKDIV_STAT1 S5P_CLKREG(0x1004)
  35. #define S5P_CLKMUX_STAT0 S5P_CLKREG(0x1100)
  36. #define S5P_CLKMUX_STAT1 S5P_CLKREG(0x1104)
  37. #define S5P_ARM_MCS_CON S5P_CLKREG(0x6100)
  38. /* CLKSRC0 */
  39. #define S5P_CLKSRC0_MUX200_SHIFT (16)
  40. #define S5P_CLKSRC0_MUX200_MASK (0x1 << S5P_CLKSRC0_MUX200_SHIFT)
  41. #define S5P_CLKSRC0_MUX166_MASK (0x1<<20)
  42. #define S5P_CLKSRC0_MUX133_MASK (0x1<<24)
  43. /* CLKSRC2 */
  44. #define S5P_CLKSRC2_G3D_SHIFT (0)
  45. #define S5P_CLKSRC2_G3D_MASK (0x3 << S5P_CLKSRC2_G3D_SHIFT)
  46. #define S5P_CLKSRC2_MFC_SHIFT (4)
  47. #define S5P_CLKSRC2_MFC_MASK (0x3 << S5P_CLKSRC2_MFC_SHIFT)
  48. /* CLKDIV0 */
  49. #define S5P_CLKDIV0_APLL_SHIFT (0)
  50. #define S5P_CLKDIV0_APLL_MASK (0x7 << S5P_CLKDIV0_APLL_SHIFT)
  51. #define S5P_CLKDIV0_A2M_SHIFT (4)
  52. #define S5P_CLKDIV0_A2M_MASK (0x7 << S5P_CLKDIV0_A2M_SHIFT)
  53. #define S5P_CLKDIV0_HCLK200_SHIFT (8)
  54. #define S5P_CLKDIV0_HCLK200_MASK (0x7 << S5P_CLKDIV0_HCLK200_SHIFT)
  55. #define S5P_CLKDIV0_PCLK100_SHIFT (12)
  56. #define S5P_CLKDIV0_PCLK100_MASK (0x7 << S5P_CLKDIV0_PCLK100_SHIFT)
  57. #define S5P_CLKDIV0_HCLK166_SHIFT (16)
  58. #define S5P_CLKDIV0_HCLK166_MASK (0xF << S5P_CLKDIV0_HCLK166_SHIFT)
  59. #define S5P_CLKDIV0_PCLK83_SHIFT (20)
  60. #define S5P_CLKDIV0_PCLK83_MASK (0x7 << S5P_CLKDIV0_PCLK83_SHIFT)
  61. #define S5P_CLKDIV0_HCLK133_SHIFT (24)
  62. #define S5P_CLKDIV0_HCLK133_MASK (0xF << S5P_CLKDIV0_HCLK133_SHIFT)
  63. #define S5P_CLKDIV0_PCLK66_SHIFT (28)
  64. #define S5P_CLKDIV0_PCLK66_MASK (0x7 << S5P_CLKDIV0_PCLK66_SHIFT)
  65. /* CLKDIV2 */
  66. #define S5P_CLKDIV2_G3D_SHIFT (0)
  67. #define S5P_CLKDIV2_G3D_MASK (0xF << S5P_CLKDIV2_G3D_SHIFT)
  68. #define S5P_CLKDIV2_MFC_SHIFT (4)
  69. #define S5P_CLKDIV2_MFC_MASK (0xF << S5P_CLKDIV2_MFC_SHIFT)
  70. /* CLKDIV6 */
  71. #define S5P_CLKDIV6_ONEDRAM_SHIFT (28)
  72. #define S5P_CLKDIV6_ONEDRAM_MASK (0xF << S5P_CLKDIV6_ONEDRAM_SHIFT)
  73. static struct clk *dmc0_clk;
  74. static struct clk *dmc1_clk;
  75. static DEFINE_MUTEX(set_freq_lock);
  76. /* APLL M,P,S values for 1G/800Mhz */
  77. #define APLL_VAL_1000 ((1 << 31) | (125 << 16) | (3 << 8) | 1)
  78. #define APLL_VAL_800 ((1 << 31) | (100 << 16) | (3 << 8) | 1)
  79. /* Use 800MHz when entering sleep mode */
  80. #define SLEEP_FREQ (800 * 1000)
  81. /* Tracks if cpu freqency can be updated anymore */
  82. static bool no_cpufreq_access;
  83. /*
  84. * DRAM configurations to calculate refresh counter for changing
  85. * frequency of memory.
  86. */
  87. struct dram_conf {
  88. unsigned long freq; /* HZ */
  89. unsigned long refresh; /* DRAM refresh counter * 1000 */
  90. };
  91. /* DRAM configuration (DMC0 and DMC1) */
  92. static struct dram_conf s5pv210_dram_conf[2];
  93. enum perf_level {
  94. L0, L1, L2, L3, L4,
  95. };
  96. enum s5pv210_mem_type {
  97. LPDDR = 0x1,
  98. LPDDR2 = 0x2,
  99. DDR2 = 0x4,
  100. };
  101. enum s5pv210_dmc_port {
  102. DMC0 = 0,
  103. DMC1,
  104. };
  105. static struct cpufreq_frequency_table s5pv210_freq_table[] = {
  106. {0, L0, 1000*1000},
  107. {0, L1, 800*1000},
  108. {0, L2, 400*1000},
  109. {0, L3, 200*1000},
  110. {0, L4, 100*1000},
  111. {0, 0, CPUFREQ_TABLE_END},
  112. };
  113. static struct regulator *arm_regulator;
  114. static struct regulator *int_regulator;
  115. struct s5pv210_dvs_conf {
  116. int arm_volt; /* uV */
  117. int int_volt; /* uV */
  118. };
  119. static const int arm_volt_max = 1350000;
  120. static const int int_volt_max = 1250000;
  121. static struct s5pv210_dvs_conf dvs_conf[] = {
  122. [L0] = {
  123. .arm_volt = 1250000,
  124. .int_volt = 1100000,
  125. },
  126. [L1] = {
  127. .arm_volt = 1200000,
  128. .int_volt = 1100000,
  129. },
  130. [L2] = {
  131. .arm_volt = 1050000,
  132. .int_volt = 1100000,
  133. },
  134. [L3] = {
  135. .arm_volt = 950000,
  136. .int_volt = 1100000,
  137. },
  138. [L4] = {
  139. .arm_volt = 950000,
  140. .int_volt = 1000000,
  141. },
  142. };
  143. static u32 clkdiv_val[5][11] = {
  144. /*
  145. * Clock divider value for following
  146. * { APLL, A2M, HCLK_MSYS, PCLK_MSYS,
  147. * HCLK_DSYS, PCLK_DSYS, HCLK_PSYS, PCLK_PSYS,
  148. * ONEDRAM, MFC, G3D }
  149. */
  150. /* L0 : [1000/200/100][166/83][133/66][200/200] */
  151. {0, 4, 4, 1, 3, 1, 4, 1, 3, 0, 0},
  152. /* L1 : [800/200/100][166/83][133/66][200/200] */
  153. {0, 3, 3, 1, 3, 1, 4, 1, 3, 0, 0},
  154. /* L2 : [400/200/100][166/83][133/66][200/200] */
  155. {1, 3, 1, 1, 3, 1, 4, 1, 3, 0, 0},
  156. /* L3 : [200/200/100][166/83][133/66][200/200] */
  157. {3, 3, 1, 1, 3, 1, 4, 1, 3, 0, 0},
  158. /* L4 : [100/100/100][83/83][66/66][100/100] */
  159. {7, 7, 0, 0, 7, 0, 9, 0, 7, 0, 0},
  160. };
  161. /*
  162. * This function set DRAM refresh counter
  163. * accoriding to operating frequency of DRAM
  164. * ch: DMC port number 0 or 1
  165. * freq: Operating frequency of DRAM(KHz)
  166. */
  167. static void s5pv210_set_refresh(enum s5pv210_dmc_port ch, unsigned long freq)
  168. {
  169. unsigned long tmp, tmp1;
  170. void __iomem *reg = NULL;
  171. if (ch == DMC0) {
  172. reg = (dmc_base[0] + 0x30);
  173. } else if (ch == DMC1) {
  174. reg = (dmc_base[1] + 0x30);
  175. } else {
  176. printk(KERN_ERR "Cannot find DMC port\n");
  177. return;
  178. }
  179. /* Find current DRAM frequency */
  180. tmp = s5pv210_dram_conf[ch].freq;
  181. do_div(tmp, freq);
  182. tmp1 = s5pv210_dram_conf[ch].refresh;
  183. do_div(tmp1, tmp);
  184. __raw_writel(tmp1, reg);
  185. }
  186. static int s5pv210_target(struct cpufreq_policy *policy, unsigned int index)
  187. {
  188. unsigned long reg;
  189. unsigned int priv_index;
  190. unsigned int pll_changing = 0;
  191. unsigned int bus_speed_changing = 0;
  192. unsigned int old_freq, new_freq;
  193. int arm_volt, int_volt;
  194. int ret = 0;
  195. mutex_lock(&set_freq_lock);
  196. if (no_cpufreq_access) {
  197. pr_err("Denied access to %s as it is disabled temporarily\n",
  198. __func__);
  199. ret = -EINVAL;
  200. goto exit;
  201. }
  202. old_freq = policy->cur;
  203. new_freq = s5pv210_freq_table[index].frequency;
  204. /* Finding current running level index */
  205. if (cpufreq_frequency_table_target(policy, s5pv210_freq_table,
  206. old_freq, CPUFREQ_RELATION_H,
  207. &priv_index)) {
  208. ret = -EINVAL;
  209. goto exit;
  210. }
  211. arm_volt = dvs_conf[index].arm_volt;
  212. int_volt = dvs_conf[index].int_volt;
  213. if (new_freq > old_freq) {
  214. ret = regulator_set_voltage(arm_regulator,
  215. arm_volt, arm_volt_max);
  216. if (ret)
  217. goto exit;
  218. ret = regulator_set_voltage(int_regulator,
  219. int_volt, int_volt_max);
  220. if (ret)
  221. goto exit;
  222. }
  223. /* Check if there need to change PLL */
  224. if ((index == L0) || (priv_index == L0))
  225. pll_changing = 1;
  226. /* Check if there need to change System bus clock */
  227. if ((index == L4) || (priv_index == L4))
  228. bus_speed_changing = 1;
  229. if (bus_speed_changing) {
  230. /*
  231. * Reconfigure DRAM refresh counter value for minimum
  232. * temporary clock while changing divider.
  233. * expected clock is 83Mhz : 7.8usec/(1/83Mhz) = 0x287
  234. */
  235. if (pll_changing)
  236. s5pv210_set_refresh(DMC1, 83000);
  237. else
  238. s5pv210_set_refresh(DMC1, 100000);
  239. s5pv210_set_refresh(DMC0, 83000);
  240. }
  241. /*
  242. * APLL should be changed in this level
  243. * APLL -> MPLL(for stable transition) -> APLL
  244. * Some clock source's clock API are not prepared.
  245. * Do not use clock API in below code.
  246. */
  247. if (pll_changing) {
  248. /*
  249. * 1. Temporary Change divider for MFC and G3D
  250. * SCLKA2M(200/1=200)->(200/4=50)Mhz
  251. */
  252. reg = __raw_readl(S5P_CLK_DIV2);
  253. reg &= ~(S5P_CLKDIV2_G3D_MASK | S5P_CLKDIV2_MFC_MASK);
  254. reg |= (3 << S5P_CLKDIV2_G3D_SHIFT) |
  255. (3 << S5P_CLKDIV2_MFC_SHIFT);
  256. __raw_writel(reg, S5P_CLK_DIV2);
  257. /* For MFC, G3D dividing */
  258. do {
  259. reg = __raw_readl(S5P_CLKDIV_STAT0);
  260. } while (reg & ((1 << 16) | (1 << 17)));
  261. /*
  262. * 2. Change SCLKA2M(200Mhz)to SCLKMPLL in MFC_MUX, G3D MUX
  263. * (200/4=50)->(667/4=166)Mhz
  264. */
  265. reg = __raw_readl(S5P_CLK_SRC2);
  266. reg &= ~(S5P_CLKSRC2_G3D_MASK | S5P_CLKSRC2_MFC_MASK);
  267. reg |= (1 << S5P_CLKSRC2_G3D_SHIFT) |
  268. (1 << S5P_CLKSRC2_MFC_SHIFT);
  269. __raw_writel(reg, S5P_CLK_SRC2);
  270. do {
  271. reg = __raw_readl(S5P_CLKMUX_STAT1);
  272. } while (reg & ((1 << 7) | (1 << 3)));
  273. /*
  274. * 3. DMC1 refresh count for 133Mhz if (index == L4) is
  275. * true refresh counter is already programed in upper
  276. * code. 0x287@83Mhz
  277. */
  278. if (!bus_speed_changing)
  279. s5pv210_set_refresh(DMC1, 133000);
  280. /* 4. SCLKAPLL -> SCLKMPLL */
  281. reg = __raw_readl(S5P_CLK_SRC0);
  282. reg &= ~(S5P_CLKSRC0_MUX200_MASK);
  283. reg |= (0x1 << S5P_CLKSRC0_MUX200_SHIFT);
  284. __raw_writel(reg, S5P_CLK_SRC0);
  285. do {
  286. reg = __raw_readl(S5P_CLKMUX_STAT0);
  287. } while (reg & (0x1 << 18));
  288. }
  289. /* Change divider */
  290. reg = __raw_readl(S5P_CLK_DIV0);
  291. reg &= ~(S5P_CLKDIV0_APLL_MASK | S5P_CLKDIV0_A2M_MASK |
  292. S5P_CLKDIV0_HCLK200_MASK | S5P_CLKDIV0_PCLK100_MASK |
  293. S5P_CLKDIV0_HCLK166_MASK | S5P_CLKDIV0_PCLK83_MASK |
  294. S5P_CLKDIV0_HCLK133_MASK | S5P_CLKDIV0_PCLK66_MASK);
  295. reg |= ((clkdiv_val[index][0] << S5P_CLKDIV0_APLL_SHIFT) |
  296. (clkdiv_val[index][1] << S5P_CLKDIV0_A2M_SHIFT) |
  297. (clkdiv_val[index][2] << S5P_CLKDIV0_HCLK200_SHIFT) |
  298. (clkdiv_val[index][3] << S5P_CLKDIV0_PCLK100_SHIFT) |
  299. (clkdiv_val[index][4] << S5P_CLKDIV0_HCLK166_SHIFT) |
  300. (clkdiv_val[index][5] << S5P_CLKDIV0_PCLK83_SHIFT) |
  301. (clkdiv_val[index][6] << S5P_CLKDIV0_HCLK133_SHIFT) |
  302. (clkdiv_val[index][7] << S5P_CLKDIV0_PCLK66_SHIFT));
  303. __raw_writel(reg, S5P_CLK_DIV0);
  304. do {
  305. reg = __raw_readl(S5P_CLKDIV_STAT0);
  306. } while (reg & 0xff);
  307. /* ARM MCS value changed */
  308. reg = __raw_readl(S5P_ARM_MCS_CON);
  309. reg &= ~0x3;
  310. if (index >= L3)
  311. reg |= 0x3;
  312. else
  313. reg |= 0x1;
  314. __raw_writel(reg, S5P_ARM_MCS_CON);
  315. if (pll_changing) {
  316. /* 5. Set Lock time = 30us*24Mhz = 0x2cf */
  317. __raw_writel(0x2cf, S5P_APLL_LOCK);
  318. /*
  319. * 6. Turn on APLL
  320. * 6-1. Set PMS values
  321. * 6-2. Wait untile the PLL is locked
  322. */
  323. if (index == L0)
  324. __raw_writel(APLL_VAL_1000, S5P_APLL_CON);
  325. else
  326. __raw_writel(APLL_VAL_800, S5P_APLL_CON);
  327. do {
  328. reg = __raw_readl(S5P_APLL_CON);
  329. } while (!(reg & (0x1 << 29)));
  330. /*
  331. * 7. Change souce clock from SCLKMPLL(667Mhz)
  332. * to SCLKA2M(200Mhz) in MFC_MUX and G3D MUX
  333. * (667/4=166)->(200/4=50)Mhz
  334. */
  335. reg = __raw_readl(S5P_CLK_SRC2);
  336. reg &= ~(S5P_CLKSRC2_G3D_MASK | S5P_CLKSRC2_MFC_MASK);
  337. reg |= (0 << S5P_CLKSRC2_G3D_SHIFT) |
  338. (0 << S5P_CLKSRC2_MFC_SHIFT);
  339. __raw_writel(reg, S5P_CLK_SRC2);
  340. do {
  341. reg = __raw_readl(S5P_CLKMUX_STAT1);
  342. } while (reg & ((1 << 7) | (1 << 3)));
  343. /*
  344. * 8. Change divider for MFC and G3D
  345. * (200/4=50)->(200/1=200)Mhz
  346. */
  347. reg = __raw_readl(S5P_CLK_DIV2);
  348. reg &= ~(S5P_CLKDIV2_G3D_MASK | S5P_CLKDIV2_MFC_MASK);
  349. reg |= (clkdiv_val[index][10] << S5P_CLKDIV2_G3D_SHIFT) |
  350. (clkdiv_val[index][9] << S5P_CLKDIV2_MFC_SHIFT);
  351. __raw_writel(reg, S5P_CLK_DIV2);
  352. /* For MFC, G3D dividing */
  353. do {
  354. reg = __raw_readl(S5P_CLKDIV_STAT0);
  355. } while (reg & ((1 << 16) | (1 << 17)));
  356. /* 9. Change MPLL to APLL in MSYS_MUX */
  357. reg = __raw_readl(S5P_CLK_SRC0);
  358. reg &= ~(S5P_CLKSRC0_MUX200_MASK);
  359. reg |= (0x0 << S5P_CLKSRC0_MUX200_SHIFT);
  360. __raw_writel(reg, S5P_CLK_SRC0);
  361. do {
  362. reg = __raw_readl(S5P_CLKMUX_STAT0);
  363. } while (reg & (0x1 << 18));
  364. /*
  365. * 10. DMC1 refresh counter
  366. * L4 : DMC1 = 100Mhz 7.8us/(1/100) = 0x30c
  367. * Others : DMC1 = 200Mhz 7.8us/(1/200) = 0x618
  368. */
  369. if (!bus_speed_changing)
  370. s5pv210_set_refresh(DMC1, 200000);
  371. }
  372. /*
  373. * L4 level need to change memory bus speed, hence onedram clock divier
  374. * and memory refresh parameter should be changed
  375. */
  376. if (bus_speed_changing) {
  377. reg = __raw_readl(S5P_CLK_DIV6);
  378. reg &= ~S5P_CLKDIV6_ONEDRAM_MASK;
  379. reg |= (clkdiv_val[index][8] << S5P_CLKDIV6_ONEDRAM_SHIFT);
  380. __raw_writel(reg, S5P_CLK_DIV6);
  381. do {
  382. reg = __raw_readl(S5P_CLKDIV_STAT1);
  383. } while (reg & (1 << 15));
  384. /* Reconfigure DRAM refresh counter value */
  385. if (index != L4) {
  386. /*
  387. * DMC0 : 166Mhz
  388. * DMC1 : 200Mhz
  389. */
  390. s5pv210_set_refresh(DMC0, 166000);
  391. s5pv210_set_refresh(DMC1, 200000);
  392. } else {
  393. /*
  394. * DMC0 : 83Mhz
  395. * DMC1 : 100Mhz
  396. */
  397. s5pv210_set_refresh(DMC0, 83000);
  398. s5pv210_set_refresh(DMC1, 100000);
  399. }
  400. }
  401. if (new_freq < old_freq) {
  402. regulator_set_voltage(int_regulator,
  403. int_volt, int_volt_max);
  404. regulator_set_voltage(arm_regulator,
  405. arm_volt, arm_volt_max);
  406. }
  407. printk(KERN_DEBUG "Perf changed[L%d]\n", index);
  408. exit:
  409. mutex_unlock(&set_freq_lock);
  410. return ret;
  411. }
  412. static int check_mem_type(void __iomem *dmc_reg)
  413. {
  414. unsigned long val;
  415. val = __raw_readl(dmc_reg + 0x4);
  416. val = (val & (0xf << 8));
  417. return val >> 8;
  418. }
  419. static int s5pv210_cpu_init(struct cpufreq_policy *policy)
  420. {
  421. unsigned long mem_type;
  422. int ret;
  423. policy->clk = clk_get(NULL, "armclk");
  424. if (IS_ERR(policy->clk))
  425. return PTR_ERR(policy->clk);
  426. dmc0_clk = clk_get(NULL, "sclk_dmc0");
  427. if (IS_ERR(dmc0_clk)) {
  428. ret = PTR_ERR(dmc0_clk);
  429. goto out_dmc0;
  430. }
  431. dmc1_clk = clk_get(NULL, "hclk_msys");
  432. if (IS_ERR(dmc1_clk)) {
  433. ret = PTR_ERR(dmc1_clk);
  434. goto out_dmc1;
  435. }
  436. if (policy->cpu != 0) {
  437. ret = -EINVAL;
  438. goto out_dmc1;
  439. }
  440. /*
  441. * check_mem_type : This driver only support LPDDR & LPDDR2.
  442. * other memory type is not supported.
  443. */
  444. mem_type = check_mem_type(dmc_base[0]);
  445. if ((mem_type != LPDDR) && (mem_type != LPDDR2)) {
  446. printk(KERN_ERR "CPUFreq doesn't support this memory type\n");
  447. ret = -EINVAL;
  448. goto out_dmc1;
  449. }
  450. /* Find current refresh counter and frequency each DMC */
  451. s5pv210_dram_conf[0].refresh = (__raw_readl(dmc_base[0] + 0x30) * 1000);
  452. s5pv210_dram_conf[0].freq = clk_get_rate(dmc0_clk);
  453. s5pv210_dram_conf[1].refresh = (__raw_readl(dmc_base[1] + 0x30) * 1000);
  454. s5pv210_dram_conf[1].freq = clk_get_rate(dmc1_clk);
  455. policy->suspend_freq = SLEEP_FREQ;
  456. return cpufreq_generic_init(policy, s5pv210_freq_table, 40000);
  457. out_dmc1:
  458. clk_put(dmc0_clk);
  459. out_dmc0:
  460. clk_put(policy->clk);
  461. return ret;
  462. }
  463. static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
  464. unsigned long event, void *ptr)
  465. {
  466. int ret;
  467. ret = cpufreq_driver_target(cpufreq_cpu_get(0), SLEEP_FREQ, 0);
  468. if (ret < 0)
  469. return NOTIFY_BAD;
  470. no_cpufreq_access = true;
  471. return NOTIFY_DONE;
  472. }
  473. static struct cpufreq_driver s5pv210_driver = {
  474. .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK,
  475. .verify = cpufreq_generic_frequency_table_verify,
  476. .target_index = s5pv210_target,
  477. .get = cpufreq_generic_get,
  478. .init = s5pv210_cpu_init,
  479. .name = "s5pv210",
  480. #ifdef CONFIG_PM
  481. .suspend = cpufreq_generic_suspend,
  482. .resume = cpufreq_generic_suspend, /* We need to set SLEEP FREQ again */
  483. #endif
  484. };
  485. static struct notifier_block s5pv210_cpufreq_reboot_notifier = {
  486. .notifier_call = s5pv210_cpufreq_reboot_notifier_event,
  487. };
  488. static int s5pv210_cpufreq_probe(struct platform_device *pdev)
  489. {
  490. struct device_node *np;
  491. int id;
  492. /*
  493. * HACK: This is a temporary workaround to get access to clock
  494. * and DMC controller registers directly and remove static mappings
  495. * and dependencies on platform headers. It is necessary to enable
  496. * S5PV210 multi-platform support and will be removed together with
  497. * this whole driver as soon as S5PV210 gets migrated to use
  498. * cpufreq-dt driver.
  499. */
  500. np = of_find_compatible_node(NULL, NULL, "samsung,s5pv210-clock");
  501. if (!np) {
  502. pr_err("%s: failed to find clock controller DT node\n",
  503. __func__);
  504. return -ENODEV;
  505. }
  506. clk_base = of_iomap(np, 0);
  507. if (!clk_base) {
  508. pr_err("%s: failed to map clock registers\n", __func__);
  509. return -EFAULT;
  510. }
  511. for_each_compatible_node(np, NULL, "samsung,s5pv210-dmc") {
  512. id = of_alias_get_id(np, "dmc");
  513. if (id < 0 || id >= ARRAY_SIZE(dmc_base)) {
  514. pr_err("%s: failed to get alias of dmc node '%s'\n",
  515. __func__, np->name);
  516. return id;
  517. }
  518. dmc_base[id] = of_iomap(np, 0);
  519. if (!dmc_base[id]) {
  520. pr_err("%s: failed to map dmc%d registers\n",
  521. __func__, id);
  522. return -EFAULT;
  523. }
  524. }
  525. for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) {
  526. if (!dmc_base[id]) {
  527. pr_err("%s: failed to find dmc%d node\n", __func__, id);
  528. return -ENODEV;
  529. }
  530. }
  531. arm_regulator = regulator_get(NULL, "vddarm");
  532. if (IS_ERR(arm_regulator)) {
  533. pr_err("failed to get regulator vddarm");
  534. return PTR_ERR(arm_regulator);
  535. }
  536. int_regulator = regulator_get(NULL, "vddint");
  537. if (IS_ERR(int_regulator)) {
  538. pr_err("failed to get regulator vddint");
  539. regulator_put(arm_regulator);
  540. return PTR_ERR(int_regulator);
  541. }
  542. register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
  543. return cpufreq_register_driver(&s5pv210_driver);
  544. }
  545. static struct platform_driver s5pv210_cpufreq_platdrv = {
  546. .driver = {
  547. .name = "s5pv210-cpufreq",
  548. },
  549. .probe = s5pv210_cpufreq_probe,
  550. };
  551. builtin_platform_driver(s5pv210_cpufreq_platdrv);