s3c24xx-cpufreq.c 16 KB

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