s3c24xx-cpufreq.c 17 KB

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