fsl_lbc.c 4.0 KB

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