cpufreq-utils-s3c24xx.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (c) 2009 Simtec Electronics
  4. // http://armlinux.simtec.co.uk/
  5. // Ben Dooks <[email protected]>
  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 "map.h"
  14. #include "regs-clock.h"
  15. #include <linux/soc/samsung/s3c-cpufreq-core.h>
  16. #include "regs-mem-s3c24xx.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. }
  53. #if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2442)
  54. u32 s3c2440_read_camdivn(void)
  55. {
  56. return __raw_readl(S3C2440_CAMDIVN);
  57. }
  58. void s3c2440_write_camdivn(u32 camdiv)
  59. {
  60. __raw_writel(camdiv, S3C2440_CAMDIVN);
  61. }
  62. #endif
  63. u32 s3c24xx_read_clkdivn(void)
  64. {
  65. return __raw_readl(S3C2410_CLKDIVN);
  66. }
  67. void s3c24xx_write_clkdivn(u32 clkdiv)
  68. {
  69. __raw_writel(clkdiv, S3C2410_CLKDIVN);
  70. }
  71. u32 s3c24xx_read_mpllcon(void)
  72. {
  73. return __raw_readl(S3C2410_MPLLCON);
  74. }
  75. void s3c24xx_write_locktime(u32 locktime)
  76. {
  77. return __raw_writel(locktime, S3C2410_LOCKTIME);
  78. }