flash.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * (C) Copyright 2004-2005
  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. #undef DEBUG
  36. #ifdef DEBUG
  37. #define DEBUGF(x...) printf(x)
  38. #else
  39. #define DEBUGF(x...)
  40. #endif /* DEBUG */
  41. #define BOOT_SMALL_FLASH 0x40 /* 01000000 */
  42. #define FLASH_ONBD_N 2 /* 00000010 */
  43. #define FLASH_SRAM_SEL 1 /* 00000001 */
  44. #define FLASH_ONBD_N 2 /* 00000010 */
  45. #define FLASH_SRAM_SEL 1 /* 00000001 */
  46. #define BOOT_SMALL_FLASH_VAL 4
  47. #define FLASH_ONBD_N_VAL 2
  48. #define FLASH_SRAM_SEL_VAL 1
  49. flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  50. static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
  51. {0xFF800000, 0xFF880000, 0xFFC00000}, /* 0:000: configuraton 4 */
  52. {0xFF900000, 0xFF980000, 0xFFC00000}, /* 1:001: configuraton 3 */
  53. {0x00000000, 0x00000000, 0x00000000}, /* 2:010: configuraton 8 */
  54. {0x00000000, 0x00000000, 0x00000000}, /* 3:011: configuraton 7 */
  55. {0xFFE00000, 0xFFF00000, 0xFF800000}, /* 4:100: configuraton 2 */
  56. {0xFFF00000, 0xFFF80000, 0xFF800000}, /* 5:101: configuraton 1 */
  57. {0x00000000, 0x00000000, 0x00000000}, /* 6:110: configuraton 6 */
  58. {0x00000000, 0x00000000, 0x00000000} /* 7:111: configuraton 5 */
  59. };
  60. /*
  61. * include common flash code (for amcc boards)
  62. */
  63. #include "../common/flash.c"
  64. /*-----------------------------------------------------------------------
  65. * Functions
  66. */
  67. static ulong flash_get_size(vu_long * addr, flash_info_t * info);
  68. static int write_word(flash_info_t * info, ulong dest, ulong data);
  69. /*-----------------------------------------------------------------------
  70. */
  71. unsigned long flash_init(void)
  72. {
  73. unsigned long total_b = 0;
  74. unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
  75. unsigned char *fpga_base = (unsigned char *)CONFIG_SYS_FPGA_BASE;
  76. unsigned char switch_status;
  77. unsigned short index = 0;
  78. int i;
  79. /* read FPGA base register FPGA_REG0 */
  80. switch_status = *fpga_base;
  81. /* check the bitmap of switch status */
  82. if (switch_status & BOOT_SMALL_FLASH) {
  83. index += BOOT_SMALL_FLASH_VAL;
  84. }
  85. if (switch_status & FLASH_ONBD_N) {
  86. index += FLASH_ONBD_N_VAL;
  87. }
  88. if (switch_status & FLASH_SRAM_SEL) {
  89. index += FLASH_SRAM_SEL_VAL;
  90. }
  91. DEBUGF("\n");
  92. DEBUGF("FLASH: Index: %d\n", index);
  93. /* Init: no FLASHes known */
  94. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  95. flash_info[i].flash_id = FLASH_UNKNOWN;
  96. flash_info[i].sector_count = -1;
  97. flash_info[i].size = 0;
  98. /* check whether the address is 0 */
  99. if (flash_addr_table[index][i] == 0) {
  100. continue;
  101. }
  102. /* call flash_get_size() to initialize sector address */
  103. size_b[i] =
  104. flash_get_size((vu_long *) flash_addr_table[index][i],
  105. &flash_info[i]);
  106. flash_info[i].size = size_b[i];
  107. if (flash_info[i].flash_id == FLASH_UNKNOWN) {
  108. printf
  109. ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
  110. i, size_b[i], size_b[i] << 20);
  111. flash_info[i].sector_count = -1;
  112. flash_info[i].size = 0;
  113. }
  114. /* Monitor protection ON by default */
  115. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  116. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  117. &flash_info[i]);
  118. #ifdef CONFIG_ENV_IS_IN_FLASH
  119. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  120. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  121. &flash_info[i]);
  122. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  123. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  124. &flash_info[i]);
  125. #endif
  126. total_b += flash_info[i].size;
  127. }
  128. return total_b;
  129. }