fsl_lbc.c 3.7 KB

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