flash.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #include <ppc440.h>
  36. #include "bamboo.h"
  37. #undef DEBUG
  38. #ifdef DEBUG
  39. #define DEBUGF(x...) printf(x)
  40. #else
  41. #define DEBUGF(x...)
  42. #endif /* DEBUG */
  43. flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  44. /*
  45. * Mark big flash bank (16 bit instead of 8 bit access) in address with bit 0
  46. */
  47. static unsigned long flash_addr_table[][CONFIG_SYS_MAX_FLASH_BANKS] = {
  48. {0x87800001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
  49. {0x00000000, 0x00000000, 0x00000000}, /* 1:boot from pci 66 */
  50. {0x87800001, 0x00000000, 0x00000000}, /* 0:boot from nand flash */
  51. {0x87F00000, 0x87F80000, 0xFFC00001}, /* 3:boot from big flash 33*/
  52. {0x87F00000, 0x87F80000, 0xFFC00001}, /* 4:boot from big flash 66*/
  53. {0x00000000, 0x00000000, 0x00000000}, /* 5:boot from */
  54. {0x00000000, 0x00000000, 0x00000000}, /* 6:boot from pci 66 */
  55. {0x00000000, 0x00000000, 0x00000000}, /* 7:boot from */
  56. {0x87C00001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
  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. static int write_word(flash_info_t * info, ulong dest, ulong data);
  67. /*-----------------------------------------------------------------------
  68. */
  69. unsigned long flash_init(void)
  70. {
  71. unsigned long total_b = 0;
  72. unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
  73. unsigned short index = 0;
  74. int i;
  75. unsigned long val;
  76. unsigned long ebc_boot_size;
  77. unsigned long boot_selection;
  78. mfsdr(sdr_pstrp0, val);
  79. index = (val & SDR0_PSTRP0_BOOTSTRAP_MASK) >> 29;
  80. if ((index == 5) || (index == 7)) {
  81. /*
  82. * Boot Settings in IIC EEprom address 0xA8 or 0xA4
  83. * Read Serial Device Strap Register1 in PPC440EP
  84. */
  85. mfsdr(sdr_sdstp1, val);
  86. boot_selection = val & SDR0_SDSTP1_BOOT_SEL_MASK;
  87. ebc_boot_size = val & SDR0_SDSTP1_EBC_ROM_BS_MASK;
  88. switch(boot_selection) {
  89. case SDR0_SDSTP1_BOOT_SEL_EBC:
  90. switch(ebc_boot_size) {
  91. case SDR0_SDSTP1_EBC_ROM_BS_16BIT:
  92. index = 3;
  93. break;
  94. case SDR0_SDSTP1_EBC_ROM_BS_8BIT:
  95. index = 0;
  96. break;
  97. }
  98. break;
  99. case SDR0_SDSTP1_BOOT_SEL_PCI:
  100. index = 1;
  101. break;
  102. case SDR0_SDSTP1_BOOT_SEL_NDFC:
  103. index = 2;
  104. break;
  105. }
  106. } else if (index == 0) {
  107. if (in8(FPGA_SETTING_REG) & FPGA_SET_REG_OP_CODE_FLASH_ABOVE) {
  108. index = 8; /* sram below op code flash -> new index 8 */
  109. }
  110. }
  111. DEBUGF("\n");
  112. DEBUGF("FLASH: Index: %d\n", index);
  113. /* Init: no FLASHes known */
  114. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  115. flash_info[i].flash_id = FLASH_UNKNOWN;
  116. flash_info[i].sector_count = -1;
  117. flash_info[i].size = 0;
  118. /* check whether the address is 0 */
  119. if (flash_addr_table[index][i] == 0)
  120. continue;
  121. DEBUGF("Detection bank %d...\n", i);
  122. /* call flash_get_size() to initialize sector address */
  123. size_b[i] = flash_get_size((vu_long *) flash_addr_table[index][i],
  124. &flash_info[i]);
  125. flash_info[i].size = size_b[i];
  126. if (flash_info[i].flash_id == FLASH_UNKNOWN) {
  127. printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
  128. i, size_b[i], size_b[i] << 20);
  129. flash_info[i].sector_count = -1;
  130. flash_info[i].size = 0;
  131. }
  132. /* Monitor protection ON by default */
  133. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  134. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  135. &flash_info[i]);
  136. #if defined(CONFIG_ENV_IS_IN_FLASH)
  137. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  138. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  139. &flash_info[i]);
  140. #if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR_REDUND)
  141. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  142. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  143. &flash_info[i]);
  144. #endif
  145. #endif
  146. total_b += flash_info[i].size;
  147. }
  148. return total_b;
  149. }