flash.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * (C) Copyright 2001-2003
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/ppc4xx.h>
  9. #include <asm/processor.h>
  10. /*
  11. * include common flash code (for esd boards)
  12. */
  13. #include "../common/flash.c"
  14. /*-----------------------------------------------------------------------
  15. * Functions
  16. */
  17. static ulong flash_get_size (vu_long * addr, flash_info_t * info);
  18. static void flash_get_offsets (ulong base, flash_info_t * info);
  19. /*-----------------------------------------------------------------------
  20. */
  21. unsigned long calc_size(unsigned long size)
  22. {
  23. switch (size) {
  24. case 1 << 20:
  25. return 0;
  26. case 2 << 20:
  27. return 1;
  28. case 4 << 20:
  29. return 2;
  30. case 8 << 20:
  31. return 3;
  32. case 16 << 20:
  33. return 4;
  34. default:
  35. return 0;
  36. }
  37. }
  38. unsigned long flash_init (void)
  39. {
  40. unsigned long size_b0, size_b1;
  41. int i;
  42. uint pbcr;
  43. unsigned long base_b0, base_b1;
  44. /* Init: no FLASHes known */
  45. for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  46. flash_info[i].flash_id = FLASH_UNKNOWN;
  47. }
  48. /* Static FLASH Bank configuration here - FIXME XXX */
  49. base_b0 = FLASH_BASE0_PRELIM;
  50. size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
  51. if (flash_info[0].flash_id == FLASH_UNKNOWN) {
  52. printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
  53. size_b0, size_b0 << 20);
  54. }
  55. base_b1 = FLASH_BASE1_PRELIM;
  56. size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
  57. /* Re-do sizing to get full correct info */
  58. if (size_b1) {
  59. if (size_b1 < (1 << 20)) {
  60. /* minimum CS size on PPC405GP is 1MB !!! */
  61. size_b1 = 1 << 20;
  62. }
  63. base_b1 = -size_b1;
  64. mtdcr (EBC0_CFGADDR, PB0CR);
  65. pbcr = mfdcr (EBC0_CFGDATA);
  66. mtdcr (EBC0_CFGADDR, PB0CR);
  67. pbcr = (pbcr & 0x0001ffff) | base_b1 | (calc_size(size_b1) << 17);
  68. mtdcr (EBC0_CFGDATA, pbcr);
  69. #if 0 /* test-only */
  70. printf("size_b1=%x base_b1=%x PB1CR = %x\n",
  71. size_b1, base_b1, pbcr); /* test-only */
  72. #endif
  73. }
  74. if (size_b0) {
  75. if (size_b0 < (1 << 20)) {
  76. /* minimum CS size on PPC405GP is 1MB !!! */
  77. size_b0 = 1 << 20;
  78. }
  79. base_b0 = base_b1 - size_b0;
  80. mtdcr (EBC0_CFGADDR, PB1CR);
  81. pbcr = mfdcr (EBC0_CFGDATA);
  82. mtdcr (EBC0_CFGADDR, PB1CR);
  83. pbcr = (pbcr & 0x0001ffff) | base_b0 | (calc_size(size_b0) << 17);
  84. mtdcr (EBC0_CFGDATA, pbcr);
  85. #if 0 /* test-only */
  86. printf("size_b0=%x base_b0=%x PB0CR = %x\n",
  87. size_b0, base_b0, pbcr); /* test-only */
  88. #endif
  89. }
  90. size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
  91. flash_get_offsets (base_b0, &flash_info[0]);
  92. /* monitor protection ON by default */
  93. flash_protect (FLAG_PROTECT_SET,
  94. base_b0 + size_b0 - monitor_flash_len,
  95. base_b0 + size_b0 - 1, &flash_info[0]);
  96. if (size_b1) {
  97. /* Re-do sizing to get full correct info */
  98. size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
  99. flash_get_offsets (base_b1, &flash_info[1]);
  100. /* monitor protection ON by default */
  101. flash_protect (FLAG_PROTECT_SET,
  102. base_b1 + size_b1 - monitor_flash_len,
  103. base_b1 + size_b1 - 1, &flash_info[1]);
  104. /* monitor protection OFF by default (one is enough) */
  105. flash_protect (FLAG_PROTECT_CLEAR,
  106. base_b0 + size_b0 - monitor_flash_len,
  107. base_b0 + size_b0 - 1, &flash_info[0]);
  108. } else {
  109. flash_info[1].flash_id = FLASH_UNKNOWN;
  110. flash_info[1].sector_count = -1;
  111. }
  112. flash_info[0].size = size_b0;
  113. flash_info[1].size = size_b1;
  114. return (size_b0 + size_b1);
  115. }