cpufreq-utils.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2009 Simtec Electronics
  3. * http://armlinux.simtec.co.uk/
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C24XX CPU Frequency scaling - utils for S3C2410/S3C2440/S3C2442
  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/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/cpufreq.h>
  15. #include <linux/io.h>
  16. #include <mach/map.h>
  17. #include <mach/regs-clock.h>
  18. #include <plat/cpu-freq-core.h>
  19. #include "regs-mem.h"
  20. /**
  21. * s3c2410_cpufreq_setrefresh - set SDRAM refresh value
  22. * @cfg: The frequency configuration
  23. *
  24. * Set the SDRAM refresh value appropriately for the configured
  25. * frequency.
  26. */
  27. void s3c2410_cpufreq_setrefresh(struct s3c_cpufreq_config *cfg)
  28. {
  29. struct s3c_cpufreq_board *board = cfg->board;
  30. unsigned long refresh;
  31. unsigned long refval;
  32. /* Reduce both the refresh time (in ns) and the frequency (in MHz)
  33. * down to ensure that we do not overflow 32 bit numbers.
  34. *
  35. * This should work for HCLK up to 133MHz and refresh period up
  36. * to 30usec.
  37. */
  38. refresh = (cfg->freq.hclk / 100) * (board->refresh / 10);
  39. refresh = DIV_ROUND_UP(refresh, (1000 * 1000)); /* apply scale */
  40. refresh = (1 << 11) + 1 - refresh;
  41. s3c_freq_dbg("%s: refresh value %lu\n", __func__, refresh);
  42. refval = __raw_readl(S3C2410_REFRESH);
  43. refval &= ~((1 << 12) - 1);
  44. refval |= refresh;
  45. __raw_writel(refval, S3C2410_REFRESH);
  46. }
  47. /**
  48. * s3c2410_set_fvco - set the PLL value
  49. * @cfg: The frequency configuration
  50. */
  51. void s3c2410_set_fvco(struct s3c_cpufreq_config *cfg)
  52. {
  53. __raw_writel(cfg->pll.index, S3C2410_MPLLCON);
  54. }