fsl_lbc.c 3.5 KB

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