s5pv210-cpufreq.c 17 KB

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