fsl_lbc.c 4.1 KB

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