fsl_lbc.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2010-2011 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <asm/fsl_lbc.h>
  7. #ifdef CONFIG_MPC85xx
  8. /* Boards should provide their own version of this if they use lbc sdram */
  9. static void __lbc_sdram_init(void)
  10. {
  11. /* Do nothing */
  12. }
  13. void lbc_sdram_init(void) __attribute__((weak, alias("__lbc_sdram_init")));
  14. #endif
  15. void print_lbc_regs(void)
  16. {
  17. int i;
  18. printf("\nLocal Bus Controller Registers\n");
  19. for (i = 0; i < 8; i++) {
  20. printf("BR%d\t0x%08X\tOR%d\t0x%08X\n",
  21. i, get_lbc_br(i), i, get_lbc_or(i));
  22. }
  23. printf("LBCR\t0x%08X\tLCRR\t0x%08X\n",
  24. get_lbc_lbcr(), get_lbc_lcrr());
  25. }
  26. void init_early_memctl_regs(void)
  27. {
  28. uint init_br1 = 1;
  29. #ifdef CONFIG_SYS_FSL_ERRATUM_ELBC_A001
  30. /* Set the local bus monitor timeout value to the maximum */
  31. clrsetbits_be32(&(LBC_BASE_ADDR)->lbcr, LBCR_BMT|LBCR_BMTPS, 0xf);
  32. #endif
  33. #ifdef CONFIG_MPC85xx
  34. /* if cs1 is already set via debugger, leave cs0/cs1 alone */
  35. if (get_lbc_br(1) & BR_V)
  36. init_br1 = 0;
  37. #endif
  38. /*
  39. * Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
  40. * preliminary addresses - these have to be modified later
  41. * when FLASH size has been determined
  42. */
  43. #if defined(CONFIG_SYS_OR0_REMAP)
  44. set_lbc_or(0, CONFIG_SYS_OR0_REMAP);
  45. #endif
  46. #if defined(CONFIG_SYS_OR1_REMAP)
  47. set_lbc_or(1, CONFIG_SYS_OR1_REMAP);
  48. #endif
  49. /* now restrict to preliminary range */
  50. if (init_br1) {
  51. #if defined(CONFIG_SYS_BR0_PRELIM) && defined(CONFIG_SYS_OR0_PRELIM)
  52. set_lbc_br(0, CONFIG_SYS_BR0_PRELIM);
  53. set_lbc_or(0, CONFIG_SYS_OR0_PRELIM);
  54. #endif
  55. #if defined(CONFIG_SYS_BR1_PRELIM) && defined(CONFIG_SYS_OR1_PRELIM)
  56. set_lbc_or(1, CONFIG_SYS_OR1_PRELIM);
  57. set_lbc_br(1, CONFIG_SYS_BR1_PRELIM);
  58. #endif
  59. }
  60. #if defined(CONFIG_SYS_BR2_PRELIM) && defined(CONFIG_SYS_OR2_PRELIM)
  61. set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
  62. set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
  63. #endif
  64. #if defined(CONFIG_SYS_BR3_PRELIM) && defined(CONFIG_SYS_OR3_PRELIM)
  65. set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
  66. set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
  67. #endif
  68. #if defined(CONFIG_SYS_BR4_PRELIM) && defined(CONFIG_SYS_OR4_PRELIM)
  69. set_lbc_or(4, CONFIG_SYS_OR4_PRELIM);
  70. set_lbc_br(4, CONFIG_SYS_BR4_PRELIM);
  71. #endif
  72. #if defined(CONFIG_SYS_BR5_PRELIM) && defined(CONFIG_SYS_OR5_PRELIM)
  73. set_lbc_or(5, CONFIG_SYS_OR5_PRELIM);
  74. set_lbc_br(5, CONFIG_SYS_BR5_PRELIM);
  75. #endif
  76. #if defined(CONFIG_SYS_BR6_PRELIM) && defined(CONFIG_SYS_OR6_PRELIM)
  77. set_lbc_or(6, CONFIG_SYS_OR6_PRELIM);
  78. set_lbc_br(6, CONFIG_SYS_BR6_PRELIM);
  79. #endif
  80. #if defined(CONFIG_SYS_BR7_PRELIM) && defined(CONFIG_SYS_OR7_PRELIM)
  81. set_lbc_or(7, CONFIG_SYS_OR7_PRELIM);
  82. set_lbc_br(7, CONFIG_SYS_BR7_PRELIM);
  83. #endif
  84. }
  85. /*
  86. * Configures a UPM. The function requires the respective MxMR to be set
  87. * before calling this function. "size" is the number or entries, not a sizeof.
  88. */
  89. void upmconfig(uint upm, uint *table, uint size)
  90. {
  91. fsl_lbc_t *lbc = LBC_BASE_ADDR;
  92. int i, mad, old_mad = 0;
  93. u32 mask = (~MxMR_OP_MSK & ~MxMR_MAD_MSK);
  94. u32 msel = BR_UPMx_TO_MSEL(upm);
  95. u32 *mxmr = &lbc->mamr + upm;
  96. volatile u8 *dummy = NULL;
  97. if (upm < UPMA || upm > UPMC) {
  98. printf("Error: %s() Bad UPM index %d\n", __func__, upm);
  99. hang();
  100. }
  101. /*
  102. * Find the address for the dummy write - scan all of the BRs until we
  103. * find one matching the UPM and extract the base address bits from it.
  104. */
  105. for (i = 0; i < 8; i++) {
  106. if ((get_lbc_br(i) & (BR_V | BR_MSEL)) == (BR_V | msel)) {
  107. dummy = (volatile u8 *)(get_lbc_br(i) & BR_BA);
  108. break;
  109. }
  110. }
  111. if (!dummy) {
  112. printf("Error: %s() No matching BR\n", __func__);
  113. hang();
  114. }
  115. /* Program UPM using steps outlined by the reference manual */
  116. for (i = 0; i < size; i++) {
  117. out_be32(mxmr, (in_be32(mxmr) & mask) | MxMR_OP_WARR | i);
  118. out_be32(&lbc->mdr, table[i]);
  119. (void)in_be32(&lbc->mdr);
  120. *dummy = 0;
  121. do {
  122. mad = in_be32(mxmr) & MxMR_MAD_MSK;
  123. } while (mad <= old_mad && !(!mad && i == (size-1)));
  124. old_mad = mad;
  125. }
  126. /* Return to normal operation */
  127. out_be32(mxmr, (in_be32(mxmr) & mask) | MxMR_OP_NORM);
  128. }