clkt34xx_dpll3m2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * OMAP34xx M2 divider clock code
  3. *
  4. * Copyright (C) 2007-2008 Texas Instruments, Inc.
  5. * Copyright (C) 2007-2010 Nokia Corporation
  6. *
  7. * Paul Walmsley
  8. * Jouni Högander
  9. *
  10. * Parts of this code are based on code written by
  11. * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #undef DEBUG
  18. #include <linux/kernel.h>
  19. #include <linux/errno.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include "clock.h"
  23. #include "clock3xxx.h"
  24. #include "clock34xx.h"
  25. #include "sdrc.h"
  26. #include "sram.h"
  27. #define CYCLES_PER_MHZ 1000000
  28. /*
  29. * CORE DPLL (DPLL3) M2 divider rate programming functions
  30. *
  31. * These call into SRAM code to do the actual CM writes, since the SDRAM
  32. * is clocked from DPLL3.
  33. */
  34. /**
  35. * omap3_core_dpll_m2_set_rate - set CORE DPLL M2 divider
  36. * @clk: struct clk * of DPLL to set
  37. * @rate: rounded target rate
  38. *
  39. * Program the DPLL M2 divider with the rounded target rate. Returns
  40. * -EINVAL upon error, or 0 upon success.
  41. */
  42. int omap3_core_dpll_m2_set_rate(struct clk_hw *hw, unsigned long rate,
  43. unsigned long parent_rate)
  44. {
  45. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  46. u32 new_div = 0;
  47. u32 unlock_dll = 0;
  48. u32 c;
  49. unsigned long validrate, sdrcrate, _mpurate;
  50. struct omap_sdrc_params *sdrc_cs0;
  51. struct omap_sdrc_params *sdrc_cs1;
  52. int ret;
  53. unsigned long clkrate;
  54. if (!clk || !rate)
  55. return -EINVAL;
  56. validrate = omap2_clksel_round_rate_div(clk, rate, &new_div);
  57. if (validrate != rate)
  58. return -EINVAL;
  59. sdrcrate = __clk_get_rate(sdrc_ick_p);
  60. clkrate = __clk_get_rate(hw->clk);
  61. if (rate > clkrate)
  62. sdrcrate <<= ((rate / clkrate) >> 1);
  63. else
  64. sdrcrate >>= ((clkrate / rate) >> 1);
  65. ret = omap2_sdrc_get_params(sdrcrate, &sdrc_cs0, &sdrc_cs1);
  66. if (ret)
  67. return -EINVAL;
  68. if (sdrcrate < MIN_SDRC_DLL_LOCK_FREQ) {
  69. pr_debug("clock: will unlock SDRC DLL\n");
  70. unlock_dll = 1;
  71. }
  72. /*
  73. * XXX This only needs to be done when the CPU frequency changes
  74. */
  75. _mpurate = __clk_get_rate(arm_fck_p) / CYCLES_PER_MHZ;
  76. c = (_mpurate << SDRC_MPURATE_SCALE) >> SDRC_MPURATE_BASE_SHIFT;
  77. c += 1; /* for safety */
  78. c *= SDRC_MPURATE_LOOPS;
  79. c >>= SDRC_MPURATE_SCALE;
  80. if (c == 0)
  81. c = 1;
  82. pr_debug("clock: changing CORE DPLL rate from %lu to %lu\n",
  83. clkrate, validrate);
  84. pr_debug("clock: SDRC CS0 timing params used: RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",
  85. sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
  86. sdrc_cs0->actim_ctrlb, sdrc_cs0->mr);
  87. if (sdrc_cs1)
  88. pr_debug("clock: SDRC CS1 timing params used: RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",
  89. sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,
  90. sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);
  91. if (sdrc_cs1)
  92. omap3_configure_core_dpll(
  93. new_div, unlock_dll, c, rate > clkrate,
  94. sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
  95. sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,
  96. sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,
  97. sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);
  98. else
  99. omap3_configure_core_dpll(
  100. new_div, unlock_dll, c, rate > clkrate,
  101. sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
  102. sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,
  103. 0, 0, 0, 0);
  104. return 0;
  105. }