clocks-init.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <linux/init.h>
  10. #include <asm/blackfin.h>
  11. #include <asm/dma.h>
  12. #include <asm/clocks.h>
  13. #include <asm/mem_init.h>
  14. #include <asm/dpmc.h>
  15. #define SDGCTL_WIDTH (1 << 31) /* SDRAM external data path width */
  16. #define PLL_CTL_VAL \
  17. (((CONFIG_VCO_MULT & 63) << 9) | CLKIN_HALF | \
  18. (PLL_BYPASS << 8) | (ANOMALY_05000305 ? 0 : 0x8000))
  19. __attribute__((l1_text))
  20. static void do_sync(void)
  21. {
  22. __builtin_bfin_ssync();
  23. }
  24. __attribute__((l1_text))
  25. void init_clocks(void)
  26. {
  27. /* Kill any active DMAs as they may trigger external memory accesses
  28. * in the middle of reprogramming things, and that'll screw us up.
  29. * For example, any automatic DMAs left by U-Boot for splash screens.
  30. */
  31. size_t i;
  32. for (i = 0; i < MAX_DMA_CHANNELS; ++i) {
  33. struct dma_register *dma = dma_io_base_addr[i];
  34. dma->cfg = 0;
  35. }
  36. do_sync();
  37. #ifdef SIC_IWR0
  38. bfin_write_SIC_IWR0(IWR_ENABLE(0));
  39. # ifdef SIC_IWR1
  40. /* BF52x system reset does not properly reset SIC_IWR1 which
  41. * will screw up the bootrom as it relies on MDMA0/1 waking it
  42. * up from IDLE instructions. See this report for more info:
  43. * http://blackfin.uclinux.org/gf/tracker/4323
  44. */
  45. if (ANOMALY_05000435)
  46. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  47. else
  48. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  49. # endif
  50. # ifdef SIC_IWR2
  51. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  52. # endif
  53. #else
  54. bfin_write_SIC_IWR(IWR_ENABLE(0));
  55. #endif
  56. do_sync();
  57. #ifdef EBIU_SDGCTL
  58. bfin_write_EBIU_SDGCTL(bfin_read_EBIU_SDGCTL() | SRFS);
  59. do_sync();
  60. #endif
  61. #ifdef CLKBUFOE
  62. bfin_write16(VR_CTL, bfin_read_VR_CTL() | CLKBUFOE);
  63. do_sync();
  64. __asm__ __volatile__("IDLE;");
  65. #endif
  66. bfin_write_PLL_LOCKCNT(0x300);
  67. do_sync();
  68. /* We always write PLL_CTL thus avoiding Anomaly 05000242 */
  69. bfin_write16(PLL_CTL, PLL_CTL_VAL);
  70. __asm__ __volatile__("IDLE;");
  71. bfin_write_PLL_DIV(CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  72. #ifdef EBIU_SDGCTL
  73. bfin_write_EBIU_SDRRC(mem_SDRRC);
  74. bfin_write_EBIU_SDGCTL((bfin_read_EBIU_SDGCTL() & SDGCTL_WIDTH) | mem_SDGCTL);
  75. #else
  76. bfin_write_EBIU_RSTCTL(bfin_read_EBIU_RSTCTL() & ~(SRREQ));
  77. do_sync();
  78. bfin_write_EBIU_RSTCTL(bfin_read_EBIU_RSTCTL() | 0x1);
  79. bfin_write_EBIU_DDRCTL0(mem_DDRCTL0);
  80. bfin_write_EBIU_DDRCTL1(mem_DDRCTL1);
  81. bfin_write_EBIU_DDRCTL2(mem_DDRCTL2);
  82. #ifdef CONFIG_MEM_EBIU_DDRQUE
  83. bfin_write_EBIU_DDRQUE(CONFIG_MEM_EBIU_DDRQUE);
  84. #endif
  85. #endif
  86. do_sync();
  87. bfin_read16(0);
  88. }