clock2xxx.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * linux/arch/arm/mach-omap2/clock.c
  3. *
  4. * Copyright (C) 2005-2008 Texas Instruments, Inc.
  5. * Copyright (C) 2004-2008 Nokia Corporation
  6. *
  7. * Contacts:
  8. * Richard Woodruff <r-woodruff2@ti.com>
  9. * Paul Walmsley
  10. *
  11. * Based on earlier work by Tuukka Tikkanen, Tony Lindgren,
  12. * Gordon McNutt and RidgeRun, Inc.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #undef DEBUG
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h>
  22. #include <linux/list.h>
  23. #include <linux/errno.h>
  24. #include <linux/delay.h>
  25. #include <linux/clk.h>
  26. #include <linux/io.h>
  27. #include <linux/cpufreq.h>
  28. #include <linux/bitops.h>
  29. #include <plat/clock.h>
  30. #include <plat/sram.h>
  31. #include <plat/prcm.h>
  32. #include <plat/clkdev_omap.h>
  33. #include <asm/div64.h>
  34. #include <asm/clkdev.h>
  35. #include <plat/sdrc.h>
  36. #include "clock.h"
  37. #include "clock2xxx.h"
  38. #include "opp2xxx.h"
  39. #include "prm.h"
  40. #include "prm-regbits-24xx.h"
  41. #include "cm.h"
  42. #include "cm-regbits-24xx.h"
  43. struct clk *vclk, *sclk, *dclk;
  44. void __iomem *prcm_clksrc_ctrl;
  45. /*-------------------------------------------------------------------------
  46. * Omap24xx specific clock functions
  47. *-------------------------------------------------------------------------*/
  48. /**
  49. * omap2430_clk_i2chs_find_idlest - return CM_IDLEST info for 2430 I2CHS
  50. * @clk: struct clk * being enabled
  51. * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
  52. * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
  53. *
  54. * OMAP2430 I2CHS CM_IDLEST bits are in CM_IDLEST1_CORE, but the
  55. * CM_*CLKEN bits are in CM_{I,F}CLKEN2_CORE. This custom function
  56. * passes back the correct CM_IDLEST register address for I2CHS
  57. * modules. No return value.
  58. */
  59. static void omap2430_clk_i2chs_find_idlest(struct clk *clk,
  60. void __iomem **idlest_reg,
  61. u8 *idlest_bit)
  62. {
  63. *idlest_reg = OMAP_CM_REGADDR(CORE_MOD, CM_IDLEST);
  64. *idlest_bit = clk->enable_bit;
  65. }
  66. /* 2430 I2CHS has non-standard IDLEST register */
  67. const struct clkops clkops_omap2430_i2chs_wait = {
  68. .enable = omap2_dflt_clk_enable,
  69. .disable = omap2_dflt_clk_disable,
  70. .find_idlest = omap2430_clk_i2chs_find_idlest,
  71. .find_companion = omap2_clk_dflt_find_companion,
  72. };
  73. #ifdef OLD_CK
  74. /* Recalculate SYST_CLK */
  75. static void omap2_sys_clk_recalc(struct clk *clk)
  76. {
  77. u32 div = PRCM_CLKSRC_CTRL;
  78. div &= (1 << 7) | (1 << 6); /* Test if ext clk divided by 1 or 2 */
  79. div >>= clk->rate_offset;
  80. clk->rate = (clk->parent->rate / div);
  81. propagate_rate(clk);
  82. }
  83. #endif /* OLD_CK */
  84. u32 omap2xxx_get_sysclkdiv(void)
  85. {
  86. u32 div;
  87. div = __raw_readl(prcm_clksrc_ctrl);
  88. div &= OMAP_SYSCLKDIV_MASK;
  89. div >>= OMAP_SYSCLKDIV_SHIFT;
  90. return div;
  91. }
  92. unsigned long omap2_sys_clk_recalc(struct clk *clk)
  93. {
  94. return clk->parent->rate / omap2xxx_get_sysclkdiv();
  95. }
  96. /*
  97. * Set clocks for bypass mode for reboot to work.
  98. */
  99. void omap2_clk_prepare_for_reboot(void)
  100. {
  101. u32 rate;
  102. if (vclk == NULL || sclk == NULL)
  103. return;
  104. rate = clk_get_rate(sclk);
  105. clk_set_rate(vclk, rate);
  106. }
  107. /*
  108. * Switch the MPU rate if specified on cmdline.
  109. * We cannot do this early until cmdline is parsed.
  110. */
  111. static int __init omap2_clk_arch_init(void)
  112. {
  113. struct clk *virt_prcm_set, *sys_ck, *dpll_ck, *mpu_ck;
  114. unsigned long sys_ck_rate;
  115. if (!mpurate)
  116. return -EINVAL;
  117. virt_prcm_set = clk_get(NULL, "virt_prcm_set");
  118. sys_ck = clk_get(NULL, "sys_ck");
  119. dpll_ck = clk_get(NULL, "dpll_ck");
  120. mpu_ck = clk_get(NULL, "mpu_ck");
  121. if (clk_set_rate(virt_prcm_set, mpurate))
  122. printk(KERN_ERR "Could not find matching MPU rate\n");
  123. recalculate_root_clocks();
  124. sys_ck_rate = clk_get_rate(sys_ck);
  125. pr_info("Switched to new clocking rate (Crystal/DPLL/MPU): "
  126. "%ld.%01ld/%ld/%ld MHz\n",
  127. (sys_ck_rate / 1000000), (sys_ck_rate / 100000) % 10,
  128. (clk_get_rate(dpll_ck) / 1000000),
  129. (clk_get_rate(mpu_ck) / 1000000));
  130. return 0;
  131. }
  132. arch_initcall(omap2_clk_arch_init);