cpu_init.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2014 Angelo Dureghello <angelo@sysam.it>
  4. *
  5. */
  6. #include <common.h>
  7. #include <watchdog.h>
  8. #include <asm/immap.h>
  9. #include <asm/io.h>
  10. #if defined(CONFIG_M5307)
  11. /*
  12. * Simple mcf5307 chip select module init.
  13. *
  14. * Note: this chip has an issue reported in the device "errata":
  15. * MCF5307ER Rev 4.2 reports @ section 35:
  16. * Corrupted Return PC in Exception Stack Frame
  17. * When processing an autovectored interrupt an error can occur that
  18. * causes 0xFFFFFFFF to be written as the return PC value in the
  19. * exception stack frame. The problem is caused by a conflict between
  20. * an internal autovector access and a chip select mapped to the IACK
  21. * address space (0xFFFFXXXX).
  22. * Workaround:
  23. * Set the C/I bit in the chip select mask register (CSMR) for the
  24. * chip select that is mapped to 0xFFFFXXXX.
  25. * This will prevent the chip select from asserting for IACK accesses.
  26. */
  27. #define MCF5307_SP_ERR_FIX(cs_base, mask) \
  28. do { \
  29. if (((cs_base<<16)+(in_be32(&mask)&0xffff0000)) >= \
  30. 0xffff0000) \
  31. setbits_be32(&mask, CSMR_CI); \
  32. } while (0)
  33. void init_csm(void)
  34. {
  35. csm_t *csm = (csm_t *)(MMAP_CSM);
  36. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && \
  37. defined(CONFIG_SYS_CS0_CTRL))
  38. out_be16(&csm->csar0, CONFIG_SYS_CS0_BASE);
  39. out_be32(&csm->csmr0, CONFIG_SYS_CS0_MASK);
  40. out_be16(&csm->cscr0, CONFIG_SYS_CS0_CTRL);
  41. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS0_BASE, csm->csmr0);
  42. #else
  43. #warning "Chip Select 0 are not initialized/used"
  44. #endif
  45. #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && \
  46. defined(CONFIG_SYS_CS1_CTRL))
  47. out_be16(&csm->csar1, CONFIG_SYS_CS1_BASE);
  48. out_be32(&csm->csmr1, CONFIG_SYS_CS1_MASK);
  49. out_be16(&csm->cscr1, CONFIG_SYS_CS1_CTRL);
  50. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS1_BASE, csm->csmr1);
  51. #endif
  52. #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && \
  53. defined(CONFIG_SYS_CS2_CTRL))
  54. out_be16(&csm->csar2, CONFIG_SYS_CS2_BASE);
  55. out_be32(&csm->csmr2, CONFIG_SYS_CS2_MASK);
  56. out_be16(&csm->cscr2, CONFIG_SYS_CS2_CTRL);
  57. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS2_BASE, csm->csmr2);
  58. #endif
  59. #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && \
  60. defined(CONFIG_SYS_CS3_CTRL))
  61. out_be16(&csm->csar3, CONFIG_SYS_CS3_BASE);
  62. out_be32(&csm->csmr3, CONFIG_SYS_CS3_MASK);
  63. out_be16(&csm->cscr3, CONFIG_SYS_CS3_CTRL);
  64. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS3_BASE, csm->csmr3);
  65. #endif
  66. #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && \
  67. defined(CONFIG_SYS_CS4_CTRL))
  68. out_be16(&csm->csar4, CONFIG_SYS_CS4_BASE);
  69. out_be32(&csm->csmr4, CONFIG_SYS_CS4_MASK);
  70. out_be16(&csm->cscr4, CONFIG_SYS_CS4_CTRL);
  71. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS4_BASE, csm->csmr4);
  72. #endif
  73. #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && \
  74. defined(CONFIG_SYS_CS5_CTRL))
  75. out_be16(&csm->csar5, CONFIG_SYS_CS5_BASE);
  76. out_be32(&csm->csmr5, CONFIG_SYS_CS5_MASK);
  77. out_be16(&csm->cscr5, CONFIG_SYS_CS5_CTRL);
  78. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS5_BASE, csm->csmr5);
  79. #endif
  80. #if (defined(CONFIG_SYS_CS6_BASE) && defined(CONFIG_SYS_CS6_MASK) && \
  81. defined(CONFIG_SYS_CS6_CTRL))
  82. out_be16(&csm->csar6, CONFIG_SYS_CS6_BASE);
  83. out_be32(&csm->csmr6, CONFIG_SYS_CS6_MASK);
  84. out_be16(&csm->cscr6, CONFIG_SYS_CS6_CTRL);
  85. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS6_BASE, csm->csmr6);
  86. #endif
  87. #if (defined(CONFIG_SYS_CS7_BASE) && defined(CONFIG_SYS_CS7_MASK) && \
  88. defined(CONFIG_SYS_CS7_CTRL))
  89. out_be16(&csm->csar7, CONFIG_SYS_CS7_BASE);
  90. out_be32(&csm->csmr7, CONFIG_SYS_CS7_MASK);
  91. out_be16(&csm->cscr7, CONFIG_SYS_CS7_CTRL);
  92. MCF5307_SP_ERR_FIX(CONFIG_SYS_CS7_BASE, csm->csmr7);
  93. #endif
  94. }
  95. /*
  96. * Set up the memory map and initialize registers
  97. */
  98. void cpu_init_f(void)
  99. {
  100. sim_t *sim = (sim_t *)(MMAP_SIM);
  101. out_8(&sim->sypcr, 0x00);
  102. out_8(&sim->swivr, 0x0f);
  103. out_8(&sim->swsr, 0x00);
  104. out_8(&sim->mpark, 0x00);
  105. intctrl_t *icr = (intctrl_t *)(MMAP_INTC);
  106. /* timer 2 not masked */
  107. out_be32(&icr->imr, 0xfffffbff);
  108. out_8(&icr->icr0, 0x00); /* sw watchdog */
  109. out_8(&icr->icr1, 0x00); /* timer 1 */
  110. out_8(&icr->icr2, 0x88); /* timer 2 */
  111. out_8(&icr->icr3, 0x00); /* i2c */
  112. out_8(&icr->icr4, 0x00); /* uart 0 */
  113. out_8(&icr->icr5, 0x00); /* uart 1 */
  114. out_8(&icr->icr6, 0x00); /* dma 0 */
  115. out_8(&icr->icr7, 0x00); /* dma 1 */
  116. out_8(&icr->icr8, 0x00); /* dma 2 */
  117. out_8(&icr->icr9, 0x00); /* dma 3 */
  118. /* Chipselect Init */
  119. init_csm();
  120. /* enable data/instruction cache now */
  121. icache_enable();
  122. }
  123. /*
  124. * initialize higher level parts of CPU like timers
  125. */
  126. int cpu_init_r(void)
  127. {
  128. return 0;
  129. }
  130. void uart_port_conf(int port)
  131. {
  132. }
  133. void arch_preboot_os(void)
  134. {
  135. /*
  136. * OS can change interrupt offsets and are about to boot the OS so
  137. * we need to make sure we disable all async interrupts.
  138. */
  139. intctrl_t *icr = (intctrl_t *)(MMAP_INTC);
  140. out_8(&icr->icr1, 0x00); /* timer 1 */
  141. out_8(&icr->icr2, 0x00); /* timer 2 */
  142. }
  143. #endif