flash.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. /*
  11. * Modified 4/5/2001
  12. * Wait for completion of each sector erase command issued
  13. * 4/5/2001
  14. * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
  15. */
  16. #include <common.h>
  17. #include <asm/ppc4xx.h>
  18. #include <asm/processor.h>
  19. #undef DEBUG
  20. #ifdef DEBUG
  21. #define DEBUGF(x...) printf(x)
  22. #else
  23. #define DEBUGF(x...)
  24. #endif /* DEBUG */
  25. #define BOOT_SMALL_FLASH 0x40 /* 01000000 */
  26. #define FLASH_ONBD_N 2 /* 00000010 */
  27. #define FLASH_SRAM_SEL 1 /* 00000001 */
  28. #define FLASH_ONBD_N 2 /* 00000010 */
  29. #define FLASH_SRAM_SEL 1 /* 00000001 */
  30. #define BOOT_SMALL_FLASH_VAL 4
  31. #define FLASH_ONBD_N_VAL 2
  32. #define FLASH_SRAM_SEL_VAL 1
  33. flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  34. static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
  35. {0xFF800000, 0xFF880000, 0xFFC00000}, /* 0:000: configuraton 4 */
  36. {0xFF900000, 0xFF980000, 0xFFC00000}, /* 1:001: configuraton 3 */
  37. {0x00000000, 0x00000000, 0x00000000}, /* 2:010: configuraton 8 */
  38. {0x00000000, 0x00000000, 0x00000000}, /* 3:011: configuraton 7 */
  39. {0xFFE00000, 0xFFF00000, 0xFF800000}, /* 4:100: configuraton 2 */
  40. {0xFFF00000, 0xFFF80000, 0xFF800000}, /* 5:101: configuraton 1 */
  41. {0x00000000, 0x00000000, 0x00000000}, /* 6:110: configuraton 6 */
  42. {0x00000000, 0x00000000, 0x00000000} /* 7:111: configuraton 5 */
  43. };
  44. /*
  45. * include common flash code (for amcc boards)
  46. */
  47. #include "../common/flash.c"
  48. /*-----------------------------------------------------------------------
  49. * Functions
  50. */
  51. static ulong flash_get_size(vu_long * addr, flash_info_t * info);
  52. static int write_word(flash_info_t * info, ulong dest, ulong data);
  53. /*-----------------------------------------------------------------------
  54. */
  55. unsigned long flash_init(void)
  56. {
  57. unsigned long total_b = 0;
  58. unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
  59. unsigned char *fpga_base = (unsigned char *)CONFIG_SYS_FPGA_BASE;
  60. unsigned char switch_status;
  61. unsigned short index = 0;
  62. int i;
  63. /* read FPGA base register FPGA_REG0 */
  64. switch_status = *fpga_base;
  65. /* check the bitmap of switch status */
  66. if (switch_status & BOOT_SMALL_FLASH) {
  67. index += BOOT_SMALL_FLASH_VAL;
  68. }
  69. if (switch_status & FLASH_ONBD_N) {
  70. index += FLASH_ONBD_N_VAL;
  71. }
  72. if (switch_status & FLASH_SRAM_SEL) {
  73. index += FLASH_SRAM_SEL_VAL;
  74. }
  75. DEBUGF("\n");
  76. DEBUGF("FLASH: Index: %d\n", index);
  77. /* Init: no FLASHes known */
  78. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  79. flash_info[i].flash_id = FLASH_UNKNOWN;
  80. flash_info[i].sector_count = -1;
  81. flash_info[i].size = 0;
  82. /* check whether the address is 0 */
  83. if (flash_addr_table[index][i] == 0) {
  84. continue;
  85. }
  86. /* call flash_get_size() to initialize sector address */
  87. size_b[i] =
  88. flash_get_size((vu_long *) flash_addr_table[index][i],
  89. &flash_info[i]);
  90. flash_info[i].size = size_b[i];
  91. if (flash_info[i].flash_id == FLASH_UNKNOWN) {
  92. printf
  93. ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
  94. i, size_b[i], size_b[i] << 20);
  95. flash_info[i].sector_count = -1;
  96. flash_info[i].size = 0;
  97. }
  98. /* Monitor protection ON by default */
  99. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
  100. CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
  101. &flash_info[i]);
  102. #ifdef CONFIG_ENV_IS_IN_FLASH
  103. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
  104. CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
  105. &flash_info[i]);
  106. (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
  107. CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
  108. &flash_info[i]);
  109. #endif
  110. total_b += flash_info[i].size;
  111. }
  112. return total_b;
  113. }