cpu-freq.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /* linux/arch/arm/plat-s3c24xx/cpu-freq.c
  2. *
  3. * Copyright (c) 2006-2008 Simtec Electronics
  4. * http://armlinux.simtec.co.uk/
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * S3C24XX CPU Frequency scaling
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/ioport.h>
  17. #include <linux/cpufreq.h>
  18. #include <linux/cpu.h>
  19. #include <linux/clk.h>
  20. #include <linux/err.h>
  21. #include <linux/io.h>
  22. #include <linux/sysdev.h>
  23. #include <linux/kobject.h>
  24. #include <linux/sysfs.h>
  25. #include <linux/slab.h>
  26. #include <asm/mach/arch.h>
  27. #include <asm/mach/map.h>
  28. #include <plat/cpu.h>
  29. #include <plat/clock.h>
  30. #include <plat/cpu-freq-core.h>
  31. #include <mach/regs-clock.h>
  32. /* note, cpufreq support deals in kHz, no Hz */
  33. static struct cpufreq_driver s3c24xx_driver;
  34. static struct s3c_cpufreq_config cpu_cur;
  35. static struct s3c_iotimings s3c24xx_iotiming;
  36. static struct cpufreq_frequency_table *pll_reg;
  37. static unsigned int last_target = ~0;
  38. static unsigned int ftab_size;
  39. static struct cpufreq_frequency_table *ftab;
  40. static struct clk *_clk_mpll;
  41. static struct clk *_clk_xtal;
  42. static struct clk *clk_fclk;
  43. static struct clk *clk_hclk;
  44. static struct clk *clk_pclk;
  45. static struct clk *clk_arm;
  46. #ifdef CONFIG_CPU_FREQ_S3C24XX_DEBUGFS
  47. struct s3c_cpufreq_config *s3c_cpufreq_getconfig(void)
  48. {
  49. return &cpu_cur;
  50. }
  51. struct s3c_iotimings *s3c_cpufreq_getiotimings(void)
  52. {
  53. return &s3c24xx_iotiming;
  54. }
  55. #endif /* CONFIG_CPU_FREQ_S3C24XX_DEBUGFS */
  56. static void s3c_cpufreq_getcur(struct s3c_cpufreq_config *cfg)
  57. {
  58. unsigned long fclk, pclk, hclk, armclk;
  59. cfg->freq.fclk = fclk = clk_get_rate(clk_fclk);
  60. cfg->freq.hclk = hclk = clk_get_rate(clk_hclk);
  61. cfg->freq.pclk = pclk = clk_get_rate(clk_pclk);
  62. cfg->freq.armclk = armclk = clk_get_rate(clk_arm);
  63. cfg->pll.index = __raw_readl(S3C2410_MPLLCON);
  64. cfg->pll.frequency = fclk;
  65. cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10);
  66. cfg->divs.h_divisor = fclk / hclk;
  67. cfg->divs.p_divisor = fclk / pclk;
  68. }
  69. static inline void s3c_cpufreq_calc(struct s3c_cpufreq_config *cfg)
  70. {
  71. unsigned long pll = cfg->pll.frequency;
  72. cfg->freq.fclk = pll;
  73. cfg->freq.hclk = pll / cfg->divs.h_divisor;
  74. cfg->freq.pclk = pll / cfg->divs.p_divisor;
  75. /* convert hclk into 10ths of nanoseconds for io calcs */
  76. cfg->freq.hclk_tns = 1000000000 / (cfg->freq.hclk / 10);
  77. }
  78. static inline int closer(unsigned int target, unsigned int n, unsigned int c)
  79. {
  80. int diff_cur = abs(target - c);
  81. int diff_new = abs(target - n);
  82. return (diff_new < diff_cur);
  83. }
  84. static void s3c_cpufreq_show(const char *pfx,
  85. struct s3c_cpufreq_config *cfg)
  86. {
  87. s3c_freq_dbg("%s: Fvco=%u, F=%lu, A=%lu, H=%lu (%u), P=%lu (%u)\n",
  88. pfx, cfg->pll.frequency, cfg->freq.fclk, cfg->freq.armclk,
  89. cfg->freq.hclk, cfg->divs.h_divisor,
  90. cfg->freq.pclk, cfg->divs.p_divisor);
  91. }
  92. /* functions to wrapper the driver info calls to do the cpu specific work */
  93. static void s3c_cpufreq_setio(struct s3c_cpufreq_config *cfg)
  94. {
  95. if (cfg->info->set_iotiming)
  96. (cfg->info->set_iotiming)(cfg, &s3c24xx_iotiming);
  97. }
  98. static int s3c_cpufreq_calcio(struct s3c_cpufreq_config *cfg)
  99. {
  100. if (cfg->info->calc_iotiming)
  101. return (cfg->info->calc_iotiming)(cfg, &s3c24xx_iotiming);
  102. return 0;
  103. }
  104. static void s3c_cpufreq_setrefresh(struct s3c_cpufreq_config *cfg)
  105. {
  106. (cfg->info->set_refresh)(cfg);
  107. }
  108. static void s3c_cpufreq_setdivs(struct s3c_cpufreq_config *cfg)
  109. {
  110. (cfg->info->set_divs)(cfg);
  111. }
  112. static int s3c_cpufreq_calcdivs(struct s3c_cpufreq_config *cfg)
  113. {
  114. return (cfg->info->calc_divs)(cfg);
  115. }
  116. static void s3c_cpufreq_setfvco(struct s3c_cpufreq_config *cfg)
  117. {
  118. (cfg->info->set_fvco)(cfg);
  119. }
  120. static inline void s3c_cpufreq_resume_clocks(void)
  121. {
  122. cpu_cur.info->resume_clocks();
  123. }
  124. static inline void s3c_cpufreq_updateclk(struct clk *clk,
  125. unsigned int freq)
  126. {
  127. clk_set_rate(clk, freq);
  128. }
  129. static int s3c_cpufreq_settarget(struct cpufreq_policy *policy,
  130. unsigned int target_freq,
  131. struct cpufreq_frequency_table *pll)
  132. {
  133. struct s3c_cpufreq_freqs freqs;
  134. struct s3c_cpufreq_config cpu_new;
  135. unsigned long flags;
  136. cpu_new = cpu_cur; /* copy new from current */
  137. s3c_cpufreq_show("cur", &cpu_cur);
  138. /* TODO - check for DMA currently outstanding */
  139. cpu_new.pll = pll ? *pll : cpu_cur.pll;
  140. if (pll)
  141. freqs.pll_changing = 1;
  142. /* update our frequencies */
  143. cpu_new.freq.armclk = target_freq;
  144. cpu_new.freq.fclk = cpu_new.pll.frequency;
  145. if (s3c_cpufreq_calcdivs(&cpu_new) < 0) {
  146. printk(KERN_ERR "no divisors for %d\n", target_freq);
  147. goto err_notpossible;
  148. }
  149. s3c_freq_dbg("%s: got divs\n", __func__);
  150. s3c_cpufreq_calc(&cpu_new);
  151. s3c_freq_dbg("%s: calculated frequencies for new\n", __func__);
  152. if (cpu_new.freq.hclk != cpu_cur.freq.hclk) {
  153. if (s3c_cpufreq_calcio(&cpu_new) < 0) {
  154. printk(KERN_ERR "%s: no IO timings\n", __func__);
  155. goto err_notpossible;
  156. }
  157. }
  158. s3c_cpufreq_show("new", &cpu_new);
  159. /* setup our cpufreq parameters */
  160. freqs.old = cpu_cur.freq;
  161. freqs.new = cpu_new.freq;
  162. freqs.freqs.cpu = 0;
  163. freqs.freqs.old = cpu_cur.freq.armclk / 1000;
  164. freqs.freqs.new = cpu_new.freq.armclk / 1000;
  165. /* update f/h/p clock settings before we issue the change
  166. * notification, so that drivers do not need to do anything
  167. * special if they want to recalculate on CPUFREQ_PRECHANGE. */
  168. s3c_cpufreq_updateclk(_clk_mpll, cpu_new.pll.frequency);
  169. s3c_cpufreq_updateclk(clk_fclk, cpu_new.freq.fclk);
  170. s3c_cpufreq_updateclk(clk_hclk, cpu_new.freq.hclk);
  171. s3c_cpufreq_updateclk(clk_pclk, cpu_new.freq.pclk);
  172. /* start the frequency change */
  173. if (policy)
  174. cpufreq_notify_transition(&freqs.freqs, CPUFREQ_PRECHANGE);
  175. /* If hclk is staying the same, then we do not need to
  176. * re-write the IO or the refresh timings whilst we are changing
  177. * speed. */
  178. local_irq_save(flags);
  179. /* is our memory clock slowing down? */
  180. if (cpu_new.freq.hclk < cpu_cur.freq.hclk) {
  181. s3c_cpufreq_setrefresh(&cpu_new);
  182. s3c_cpufreq_setio(&cpu_new);
  183. }
  184. if (cpu_new.freq.fclk == cpu_cur.freq.fclk) {
  185. /* not changing PLL, just set the divisors */
  186. s3c_cpufreq_setdivs(&cpu_new);
  187. } else {
  188. if (cpu_new.freq.fclk < cpu_cur.freq.fclk) {
  189. /* slow the cpu down, then set divisors */
  190. s3c_cpufreq_setfvco(&cpu_new);
  191. s3c_cpufreq_setdivs(&cpu_new);
  192. } else {
  193. /* set the divisors, then speed up */
  194. s3c_cpufreq_setdivs(&cpu_new);
  195. s3c_cpufreq_setfvco(&cpu_new);
  196. }
  197. }
  198. /* did our memory clock speed up */
  199. if (cpu_new.freq.hclk > cpu_cur.freq.hclk) {
  200. s3c_cpufreq_setrefresh(&cpu_new);
  201. s3c_cpufreq_setio(&cpu_new);
  202. }
  203. /* update our current settings */
  204. cpu_cur = cpu_new;
  205. local_irq_restore(flags);
  206. /* notify everyone we've done this */
  207. if (policy)
  208. cpufreq_notify_transition(&freqs.freqs, CPUFREQ_POSTCHANGE);
  209. s3c_freq_dbg("%s: finished\n", __func__);
  210. return 0;
  211. err_notpossible:
  212. printk(KERN_ERR "no compatible settings for %d\n", target_freq);
  213. return -EINVAL;
  214. }
  215. /* s3c_cpufreq_target
  216. *
  217. * called by the cpufreq core to adjust the frequency that the CPU
  218. * is currently running at.
  219. */
  220. static int s3c_cpufreq_target(struct cpufreq_policy *policy,
  221. unsigned int target_freq,
  222. unsigned int relation)
  223. {
  224. struct cpufreq_frequency_table *pll;
  225. unsigned int index;
  226. /* avoid repeated calls which cause a needless amout of duplicated
  227. * logging output (and CPU time as the calculation process is
  228. * done) */
  229. if (target_freq == last_target)
  230. return 0;
  231. last_target = target_freq;
  232. s3c_freq_dbg("%s: policy %p, target %u, relation %u\n",
  233. __func__, policy, target_freq, relation);
  234. if (ftab) {
  235. if (cpufreq_frequency_table_target(policy, ftab,
  236. target_freq, relation,
  237. &index)) {
  238. s3c_freq_dbg("%s: table failed\n", __func__);
  239. return -EINVAL;
  240. }
  241. s3c_freq_dbg("%s: adjust %d to entry %d (%u)\n", __func__,
  242. target_freq, index, ftab[index].frequency);
  243. target_freq = ftab[index].frequency;
  244. }
  245. target_freq *= 1000; /* convert target to Hz */
  246. /* find the settings for our new frequency */
  247. if (!pll_reg || cpu_cur.lock_pll) {
  248. /* either we've not got any PLL values, or we've locked
  249. * to the current one. */
  250. pll = NULL;
  251. } else {
  252. struct cpufreq_policy tmp_policy;
  253. int ret;
  254. /* we keep the cpu pll table in Hz, to ensure we get an
  255. * accurate value for the PLL output. */
  256. tmp_policy.min = policy->min * 1000;
  257. tmp_policy.max = policy->max * 1000;
  258. tmp_policy.cpu = policy->cpu;
  259. /* cpufreq_frequency_table_target uses a pointer to 'index'
  260. * which is the number of the table entry, not the value of
  261. * the table entry's index field. */
  262. ret = cpufreq_frequency_table_target(&tmp_policy, pll_reg,
  263. target_freq, relation,
  264. &index);
  265. if (ret < 0) {
  266. printk(KERN_ERR "%s: no PLL available\n", __func__);
  267. goto err_notpossible;
  268. }
  269. pll = pll_reg + index;
  270. s3c_freq_dbg("%s: target %u => %u\n",
  271. __func__, target_freq, pll->frequency);
  272. target_freq = pll->frequency;
  273. }
  274. return s3c_cpufreq_settarget(policy, target_freq, pll);
  275. err_notpossible:
  276. printk(KERN_ERR "no compatible settings for %d\n", target_freq);
  277. return -EINVAL;
  278. }
  279. static unsigned int s3c_cpufreq_get(unsigned int cpu)
  280. {
  281. return clk_get_rate(clk_arm) / 1000;
  282. }
  283. struct clk *s3c_cpufreq_clk_get(struct device *dev, const char *name)
  284. {
  285. struct clk *clk;
  286. clk = clk_get(dev, name);
  287. if (IS_ERR(clk))
  288. printk(KERN_ERR "cpufreq: failed to get clock '%s'\n", name);
  289. return clk;
  290. }
  291. static int s3c_cpufreq_init(struct cpufreq_policy *policy)
  292. {
  293. printk(KERN_INFO "%s: initialising policy %p\n", __func__, policy);
  294. if (policy->cpu != 0)
  295. return -EINVAL;
  296. policy->cur = s3c_cpufreq_get(0);
  297. policy->min = policy->cpuinfo.min_freq = 0;
  298. policy->max = policy->cpuinfo.max_freq = cpu_cur.info->max.fclk / 1000;
  299. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  300. /* feed the latency information from the cpu driver */
  301. policy->cpuinfo.transition_latency = cpu_cur.info->latency;
  302. if (ftab)
  303. cpufreq_frequency_table_cpuinfo(policy, ftab);
  304. return 0;
  305. }
  306. static __init int s3c_cpufreq_initclks(void)
  307. {
  308. _clk_mpll = s3c_cpufreq_clk_get(NULL, "mpll");
  309. _clk_xtal = s3c_cpufreq_clk_get(NULL, "xtal");
  310. clk_fclk = s3c_cpufreq_clk_get(NULL, "fclk");
  311. clk_hclk = s3c_cpufreq_clk_get(NULL, "hclk");
  312. clk_pclk = s3c_cpufreq_clk_get(NULL, "pclk");
  313. clk_arm = s3c_cpufreq_clk_get(NULL, "armclk");
  314. if (IS_ERR(clk_fclk) || IS_ERR(clk_hclk) || IS_ERR(clk_pclk) ||
  315. IS_ERR(_clk_mpll) || IS_ERR(clk_arm) || IS_ERR(_clk_xtal)) {
  316. printk(KERN_ERR "%s: could not get clock(s)\n", __func__);
  317. return -ENOENT;
  318. }
  319. printk(KERN_INFO "%s: clocks f=%lu,h=%lu,p=%lu,a=%lu\n", __func__,
  320. clk_get_rate(clk_fclk) / 1000,
  321. clk_get_rate(clk_hclk) / 1000,
  322. clk_get_rate(clk_pclk) / 1000,
  323. clk_get_rate(clk_arm) / 1000);
  324. return 0;
  325. }
  326. static int s3c_cpufreq_verify(struct cpufreq_policy *policy)
  327. {
  328. if (policy->cpu != 0)
  329. return -EINVAL;
  330. return 0;
  331. }
  332. #ifdef CONFIG_PM
  333. static struct cpufreq_frequency_table suspend_pll;
  334. static unsigned int suspend_freq;
  335. static int s3c_cpufreq_suspend(struct cpufreq_policy *policy, pm_message_t pmsg)
  336. {
  337. suspend_pll.frequency = clk_get_rate(_clk_mpll);
  338. suspend_pll.index = __raw_readl(S3C2410_MPLLCON);
  339. suspend_freq = s3c_cpufreq_get(0) * 1000;
  340. return 0;
  341. }
  342. static int s3c_cpufreq_resume(struct cpufreq_policy *policy)
  343. {
  344. int ret;
  345. s3c_freq_dbg("%s: resuming with policy %p\n", __func__, policy);
  346. last_target = ~0; /* invalidate last_target setting */
  347. /* first, find out what speed we resumed at. */
  348. s3c_cpufreq_resume_clocks();
  349. /* whilst we will be called later on, we try and re-set the
  350. * cpu frequencies as soon as possible so that we do not end
  351. * up resuming devices and then immediatley having to re-set
  352. * a number of settings once these devices have restarted.
  353. *
  354. * as a note, it is expected devices are not used until they
  355. * have been un-suspended and at that time they should have
  356. * used the updated clock settings.
  357. */
  358. ret = s3c_cpufreq_settarget(NULL, suspend_freq, &suspend_pll);
  359. if (ret) {
  360. printk(KERN_ERR "%s: failed to reset pll/freq\n", __func__);
  361. return ret;
  362. }
  363. return 0;
  364. }
  365. #else
  366. #define s3c_cpufreq_resume NULL
  367. #define s3c_cpufreq_suspend NULL
  368. #endif
  369. static struct cpufreq_driver s3c24xx_driver = {
  370. .flags = CPUFREQ_STICKY,
  371. .verify = s3c_cpufreq_verify,
  372. .target = s3c_cpufreq_target,
  373. .get = s3c_cpufreq_get,
  374. .init = s3c_cpufreq_init,
  375. .suspend = s3c_cpufreq_suspend,
  376. .resume = s3c_cpufreq_resume,
  377. .name = "s3c24xx",
  378. };
  379. int __init s3c_cpufreq_register(struct s3c_cpufreq_info *info)
  380. {
  381. if (!info || !info->name) {
  382. printk(KERN_ERR "%s: failed to pass valid information\n",
  383. __func__);
  384. return -EINVAL;
  385. }
  386. printk(KERN_INFO "S3C24XX CPU Frequency driver, %s cpu support\n",
  387. info->name);
  388. /* check our driver info has valid data */
  389. BUG_ON(info->set_refresh == NULL);
  390. BUG_ON(info->set_divs == NULL);
  391. BUG_ON(info->calc_divs == NULL);
  392. /* info->set_fvco is optional, depending on whether there
  393. * is a need to set the clock code. */
  394. cpu_cur.info = info;
  395. /* Note, driver registering should probably update locktime */
  396. return 0;
  397. }
  398. int __init s3c_cpufreq_setboard(struct s3c_cpufreq_board *board)
  399. {
  400. struct s3c_cpufreq_board *ours;
  401. if (!board) {
  402. printk(KERN_INFO "%s: no board data\n", __func__);
  403. return -EINVAL;
  404. }
  405. /* Copy the board information so that each board can make this
  406. * initdata. */
  407. ours = kzalloc(sizeof(struct s3c_cpufreq_board), GFP_KERNEL);
  408. if (ours == NULL) {
  409. printk(KERN_ERR "%s: no memory\n", __func__);
  410. return -ENOMEM;
  411. }
  412. *ours = *board;
  413. cpu_cur.board = ours;
  414. return 0;
  415. }
  416. int __init s3c_cpufreq_auto_io(void)
  417. {
  418. int ret;
  419. if (!cpu_cur.info->get_iotiming) {
  420. printk(KERN_ERR "%s: get_iotiming undefined\n", __func__);
  421. return -ENOENT;
  422. }
  423. printk(KERN_INFO "%s: working out IO settings\n", __func__);
  424. ret = (cpu_cur.info->get_iotiming)(&cpu_cur, &s3c24xx_iotiming);
  425. if (ret)
  426. printk(KERN_ERR "%s: failed to get timings\n", __func__);
  427. return ret;
  428. }
  429. /* if one or is zero, then return the other, otherwise return the min */
  430. #define do_min(_a, _b) ((_a) == 0 ? (_b) : (_b) == 0 ? (_a) : min(_a, _b))
  431. /**
  432. * s3c_cpufreq_freq_min - find the minimum settings for the given freq.
  433. * @dst: The destination structure
  434. * @a: One argument.
  435. * @b: The other argument.
  436. *
  437. * Create a minimum of each frequency entry in the 'struct s3c_freq',
  438. * unless the entry is zero when it is ignored and the non-zero argument
  439. * used.
  440. */
  441. static void s3c_cpufreq_freq_min(struct s3c_freq *dst,
  442. struct s3c_freq *a, struct s3c_freq *b)
  443. {
  444. dst->fclk = do_min(a->fclk, b->fclk);
  445. dst->hclk = do_min(a->hclk, b->hclk);
  446. dst->pclk = do_min(a->pclk, b->pclk);
  447. dst->armclk = do_min(a->armclk, b->armclk);
  448. }
  449. static inline u32 calc_locktime(u32 freq, u32 time_us)
  450. {
  451. u32 result;
  452. result = freq * time_us;
  453. result = DIV_ROUND_UP(result, 1000 * 1000);
  454. return result;
  455. }
  456. static void s3c_cpufreq_update_loctkime(void)
  457. {
  458. unsigned int bits = cpu_cur.info->locktime_bits;
  459. u32 rate = (u32)clk_get_rate(_clk_xtal);
  460. u32 val;
  461. if (bits == 0) {
  462. WARN_ON(1);
  463. return;
  464. }
  465. val = calc_locktime(rate, cpu_cur.info->locktime_u) << bits;
  466. val |= calc_locktime(rate, cpu_cur.info->locktime_m);
  467. printk(KERN_INFO "%s: new locktime is 0x%08x\n", __func__, val);
  468. __raw_writel(val, S3C2410_LOCKTIME);
  469. }
  470. static int s3c_cpufreq_build_freq(void)
  471. {
  472. int size, ret;
  473. if (!cpu_cur.info->calc_freqtable)
  474. return -EINVAL;
  475. kfree(ftab);
  476. ftab = NULL;
  477. size = cpu_cur.info->calc_freqtable(&cpu_cur, NULL, 0);
  478. size++;
  479. ftab = kmalloc(sizeof(struct cpufreq_frequency_table) * size, GFP_KERNEL);
  480. if (!ftab) {
  481. printk(KERN_ERR "%s: no memory for tables\n", __func__);
  482. return -ENOMEM;
  483. }
  484. ftab_size = size;
  485. ret = cpu_cur.info->calc_freqtable(&cpu_cur, ftab, size);
  486. s3c_cpufreq_addfreq(ftab, ret, size, CPUFREQ_TABLE_END);
  487. return 0;
  488. }
  489. static int __init s3c_cpufreq_initcall(void)
  490. {
  491. int ret = 0;
  492. if (cpu_cur.info && cpu_cur.board) {
  493. ret = s3c_cpufreq_initclks();
  494. if (ret)
  495. goto out;
  496. /* get current settings */
  497. s3c_cpufreq_getcur(&cpu_cur);
  498. s3c_cpufreq_show("cur", &cpu_cur);
  499. if (cpu_cur.board->auto_io) {
  500. ret = s3c_cpufreq_auto_io();
  501. if (ret) {
  502. printk(KERN_ERR "%s: failed to get io timing\n",
  503. __func__);
  504. goto out;
  505. }
  506. }
  507. if (cpu_cur.board->need_io && !cpu_cur.info->set_iotiming) {
  508. printk(KERN_ERR "%s: no IO support registered\n",
  509. __func__);
  510. ret = -EINVAL;
  511. goto out;
  512. }
  513. if (!cpu_cur.info->need_pll)
  514. cpu_cur.lock_pll = 1;
  515. s3c_cpufreq_update_loctkime();
  516. s3c_cpufreq_freq_min(&cpu_cur.max, &cpu_cur.board->max,
  517. &cpu_cur.info->max);
  518. if (cpu_cur.info->calc_freqtable)
  519. s3c_cpufreq_build_freq();
  520. ret = cpufreq_register_driver(&s3c24xx_driver);
  521. }
  522. out:
  523. return ret;
  524. }
  525. late_initcall(s3c_cpufreq_initcall);
  526. /**
  527. * s3c_plltab_register - register CPU PLL table.
  528. * @plls: The list of PLL entries.
  529. * @plls_no: The size of the PLL entries @plls.
  530. *
  531. * Register the given set of PLLs with the system.
  532. */
  533. int __init s3c_plltab_register(struct cpufreq_frequency_table *plls,
  534. unsigned int plls_no)
  535. {
  536. struct cpufreq_frequency_table *vals;
  537. unsigned int size;
  538. size = sizeof(struct cpufreq_frequency_table) * (plls_no + 1);
  539. vals = kmalloc(size, GFP_KERNEL);
  540. if (vals) {
  541. memcpy(vals, plls, size);
  542. pll_reg = vals;
  543. /* write a terminating entry, we don't store it in the
  544. * table that is stored in the kernel */
  545. vals += plls_no;
  546. vals->frequency = CPUFREQ_TABLE_END;
  547. printk(KERN_INFO "cpufreq: %d PLL entries\n", plls_no);
  548. } else
  549. printk(KERN_ERR "cpufreq: no memory for PLL tables\n");
  550. return vals ? 0 : -ENOMEM;
  551. }