clocks-init.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * arch/blackfin/mach-common/clocks-init.c - reprogram clocks / memory
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/linkage.h>
  9. #include <asm/blackfin.h>
  10. #include <asm/dma.h>
  11. #include <asm/clocks.h>
  12. #include <asm/mem_init.h>
  13. #include <asm/dpmc.h>
  14. #ifdef CONFIG_BF60x
  15. #define CGU_CTL_VAL ((CONFIG_VCO_MULT << 8) | CLKIN_HALF)
  16. #define CGU_DIV_VAL \
  17. ((CONFIG_CCLK_DIV << CSEL_OFFSET) | \
  18. (CONFIG_SCLK_DIV << SYSSEL_OFFSET) | \
  19. (CONFIG_SCLK0_DIV << S0SEL_OFFSET) | \
  20. (CONFIG_SCLK1_DIV << S1SEL_OFFSET) | \
  21. (CONFIG_DCLK_DIV << DSEL_OFFSET))
  22. #define CONFIG_BFIN_DCLK (((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT) / CONFIG_DCLK_DIV) / 1000000)
  23. #if ((CONFIG_BFIN_DCLK != 125) && \
  24. (CONFIG_BFIN_DCLK != 133) && (CONFIG_BFIN_DCLK != 150) && \
  25. (CONFIG_BFIN_DCLK != 166) && (CONFIG_BFIN_DCLK != 200) && \
  26. (CONFIG_BFIN_DCLK != 225) && (CONFIG_BFIN_DCLK != 250))
  27. #error "DCLK must be in (125, 133, 150, 166, 200, 225, 250)MHz"
  28. #endif
  29. #else
  30. #define SDGCTL_WIDTH (1 << 31) /* SDRAM external data path width */
  31. #define PLL_CTL_VAL \
  32. (((CONFIG_VCO_MULT & 63) << 9) | CLKIN_HALF | \
  33. (PLL_BYPASS << 8) | (ANOMALY_05000305 ? 0 : 0x8000))
  34. #endif
  35. __attribute__((l1_text))
  36. static void do_sync(void)
  37. {
  38. __builtin_bfin_ssync();
  39. }
  40. __attribute__((l1_text))
  41. void init_clocks(void)
  42. {
  43. /* Kill any active DMAs as they may trigger external memory accesses
  44. * in the middle of reprogramming things, and that'll screw us up.
  45. * For example, any automatic DMAs left by U-Boot for splash screens.
  46. */
  47. #ifdef CONFIG_BF60x
  48. init_cgu(CGU_DIV_VAL, CGU_CTL_VAL);
  49. init_dmc(CONFIG_BFIN_DCLK);
  50. #else
  51. size_t i;
  52. for (i = 0; i < MAX_DMA_CHANNELS; ++i) {
  53. struct dma_register *dma = dma_io_base_addr[i];
  54. dma->cfg = 0;
  55. }
  56. do_sync();
  57. #ifdef SIC_IWR0
  58. bfin_write_SIC_IWR0(IWR_ENABLE(0));
  59. # ifdef SIC_IWR1
  60. /* BF52x system reset does not properly reset SIC_IWR1 which
  61. * will screw up the bootrom as it relies on MDMA0/1 waking it
  62. * up from IDLE instructions. See this report for more info:
  63. * http://blackfin.uclinux.org/gf/tracker/4323
  64. */
  65. if (ANOMALY_05000435)
  66. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  67. else
  68. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  69. # endif
  70. # ifdef SIC_IWR2
  71. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  72. # endif
  73. #else
  74. bfin_write_SIC_IWR(IWR_ENABLE(0));
  75. #endif
  76. do_sync();
  77. #ifdef EBIU_SDGCTL
  78. bfin_write_EBIU_SDGCTL(bfin_read_EBIU_SDGCTL() | SRFS);
  79. do_sync();
  80. #endif
  81. #ifdef CLKBUFOE
  82. bfin_write16(VR_CTL, bfin_read_VR_CTL() | CLKBUFOE);
  83. do_sync();
  84. __asm__ __volatile__("IDLE;");
  85. #endif
  86. bfin_write_PLL_LOCKCNT(0x300);
  87. do_sync();
  88. /* We always write PLL_CTL thus avoiding Anomaly 05000242 */
  89. bfin_write16(PLL_CTL, PLL_CTL_VAL);
  90. __asm__ __volatile__("IDLE;");
  91. bfin_write_PLL_DIV(CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  92. #ifdef EBIU_SDGCTL
  93. bfin_write_EBIU_SDRRC(mem_SDRRC);
  94. bfin_write_EBIU_SDGCTL((bfin_read_EBIU_SDGCTL() & SDGCTL_WIDTH) | mem_SDGCTL);
  95. #else
  96. bfin_write_EBIU_RSTCTL(bfin_read_EBIU_RSTCTL() & ~(SRREQ));
  97. do_sync();
  98. bfin_write_EBIU_RSTCTL(bfin_read_EBIU_RSTCTL() | 0x1);
  99. bfin_write_EBIU_DDRCTL0(mem_DDRCTL0);
  100. bfin_write_EBIU_DDRCTL1(mem_DDRCTL1);
  101. bfin_write_EBIU_DDRCTL2(mem_DDRCTL2);
  102. #ifdef CONFIG_MEM_EBIU_DDRQUE
  103. bfin_write_EBIU_DDRQUE(CONFIG_MEM_EBIU_DDRQUE);
  104. #endif
  105. #endif
  106. #endif
  107. do_sync();
  108. bfin_read16(0);
  109. }