cpufreq-utils.c 1.5 KB

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