flash.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * (C) Copyright 2001
  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 flash_init (void)
  22. {
  23. unsigned long size_b0;
  24. int i;
  25. uint pbcr;
  26. unsigned long base_b0;
  27. int size_val = 0;
  28. /* Init: no FLASHes known */
  29. for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
  30. flash_info[i].flash_id = FLASH_UNKNOWN;
  31. }
  32. /* Static FLASH Bank configuration here - FIXME XXX */
  33. size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);
  34. if (flash_info[0].flash_id == FLASH_UNKNOWN) {
  35. printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
  36. size_b0, size_b0<<20);
  37. }
  38. /* Setup offsets */
  39. flash_get_offsets (-size_b0, &flash_info[0]);
  40. /* Re-do sizing to get full correct info */
  41. mtdcr(EBC0_CFGADDR, PB0CR);
  42. pbcr = mfdcr(EBC0_CFGDATA);
  43. mtdcr(EBC0_CFGADDR, PB0CR);
  44. base_b0 = -size_b0;
  45. switch (size_b0) {
  46. case 1 << 20:
  47. size_val = 0;
  48. break;
  49. case 2 << 20:
  50. size_val = 1;
  51. break;
  52. case 4 << 20:
  53. size_val = 2;
  54. break;
  55. case 8 << 20:
  56. size_val = 3;
  57. break;
  58. case 16 << 20:
  59. size_val = 4;
  60. break;
  61. }
  62. pbcr = (pbcr & 0x0001ffff) | base_b0 | (size_val << 17);
  63. mtdcr(EBC0_CFGDATA, pbcr);
  64. /* Monitor protection ON by default */
  65. (void)flash_protect(FLAG_PROTECT_SET,
  66. -CONFIG_SYS_MONITOR_LEN,
  67. 0xffffffff,
  68. &flash_info[0]);
  69. flash_info[0].size = size_b0;
  70. return (size_b0);
  71. }