flash.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2002 Jun Gu <jung@artesyncp.com>
  6. * Add support for Am29F016D and dynamic switch setting.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * Modified 4/5/2001
  28. * Wait for completion of each sector erase command issued
  29. * 4/5/2001
  30. * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
  31. */
  32. #include <common.h>
  33. #include <ppc4xx.h>
  34. #include <asm/processor.h>
  35. #include <asm/io.h>
  36. #undef DEBUG
  37. #ifdef DEBUG
  38. #define DEBUGF(x...) printf(x)
  39. #else
  40. #define DEBUGF(x...)
  41. #endif /* DEBUG */
  42. #define BOOT_SMALL_FLASH 32 /* 00100000 */
  43. #define FLASH_ONBD_N 2 /* 00000010 */
  44. #define FLASH_SRAM_SEL 1 /* 00000001 */
  45. #define BOOT_SMALL_FLASH_VAL 4
  46. #define FLASH_ONBD_N_VAL 2
  47. #define FLASH_SRAM_SEL_VAL 1
  48. static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
  49. {0xffc00000, 0xffe00000, 0xff880000}, /* 0:000: configuraton 3 */
  50. {0xffc00000, 0xffe00000, 0xff800000}, /* 1:001: configuraton 4 */
  51. {0xffc00000, 0xffe00000, 0x00000000}, /* 2:010: configuraton 7 */
  52. {0xffc00000, 0xffe00000, 0x00000000}, /* 3:011: configuraton 8 */
  53. {0xff800000, 0xffa00000, 0xfff80000}, /* 4:100: configuraton 1 */
  54. {0xff800000, 0xffa00000, 0xfff00000}, /* 5:101: configuraton 2 */
  55. {0xffc00000, 0xffe00000, 0x00000000}, /* 6:110: configuraton 5 */
  56. {0xffc00000, 0xffe00000, 0x00000000} /* 7:111: configuraton 6 */
  57. };
  58. /*
  59. * include common flash code (for amcc boards)
  60. */
  61. #include "../common/flash.c"
  62. /*-----------------------------------------------------------------------
  63. * Functions
  64. */
  65. static ulong flash_get_size(vu_long * addr, flash_info_t * info);
  66. /*
  67. * Override the weak default mapping function with a board specific one
  68. */
  69. u32 flash_get_bank_size(int cs, int idx)
  70. {
  71. u8 reg = in_8((void *)CONFIG_SYS_FPGA_BASE);
  72. if ((reg & BOOT_SMALL_FLASH) && !(reg & FLASH_ONBD_N)) {
  73. /*
  74. * cs0: small flash (512KiB)
  75. * cs2: 2 * big flash (2 * 2MiB)
  76. */
  77. if (cs == 0)
  78. return flash_info[2].size;
  79. if (cs == 2)
  80. return flash_info[0].size + flash_info[1].size;
  81. } else {
  82. /*
  83. * cs0: 2 * big flash (2 * 2MiB)
  84. * cs2: small flash (512KiB)
  85. */
  86. if (cs == 0)
  87. return flash_info[0].size + flash_info[1].size;
  88. if (cs == 2)
  89. return flash_info[2].size;
  90. }
  91. return 0;
  92. }
  93. unsigned long flash_init(void)
  94. {
  95. unsigned long total_b = 0;
  96. unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
  97. unsigned char *fpga_base = (unsigned char *)CONFIG_SYS_FPGA_BASE;
  98. unsigned char switch_status;
  99. unsigned short index = 0;
  100. int i;
  101. /* read FPGA base register FPGA_REG0 */
  102. switch_status = *fpga_base;
  103. /* check the bitmap of switch status */
  104. if (switch_status & BOOT_SMALL_FLASH) {
  105. index += BOOT_SMALL_FLASH_VAL;
  106. }
  107. if (switch_status & FLASH_ONBD_N) {
  108. index += FLASH_ONBD_N_VAL;
  109. }
  110. if (switch_status & FLASH_SRAM_SEL) {
  111. index += FLASH_SRAM_SEL_VAL;
  112. }
  113. DEBUGF("\n");
  114. DEBUGF("FLASH: Index: %d\n", index);
  115. /* Init: no FLASHes known */
  116. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  117. flash_info[i].flash_id = FLASH_UNKNOWN;
  118. flash_info[i].sector_count = -1;
  119. flash_info[i].size = 0;
  120. /* check whether the address is 0 */
  121. if (flash_addr_table[index][i] == 0) {
  122. continue;
  123. }
  124. /* call flash_get_size() to initialize sector address */
  125. size_b[i] = flash_get_size((vu_long *)
  126. flash_addr_table[index][i],
  127. &flash_info[i]);
  128. flash_info[i].size = size_b[i];
  129. if (flash_info[i].flash_id == FLASH_UNKNOWN) {
  130. printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
  131. i, size_b[i], size_b[i] << 20);
  132. flash_info[i].sector_count = -1;
  133. flash_info[i].size = 0;
  134. }
  135. /* Monitor protection ON by default */
  136. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  137. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  138. &flash_info[2]);
  139. #ifdef CONFIG_ENV_IS_IN_FLASH
  140. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  141. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  142. &flash_info[2]);
  143. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  144. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  145. &flash_info[2]);
  146. #endif
  147. total_b += flash_info[i].size;
  148. }
  149. return total_b;
  150. }