memory.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * (C) Copyright 2007
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /* define DEBUG for debugging output (obviously ;-)) */
  8. #if 0
  9. #define DEBUG
  10. #endif
  11. #include <common.h>
  12. #include <asm/processor.h>
  13. #include <asm/io.h>
  14. #include <asm/ppc4xx-gpio.h>
  15. extern void board_pll_init_f(void);
  16. static void cram_bcr_write(u32 wr_val)
  17. {
  18. wr_val <<= 2;
  19. /* set CRAM_CRE to 1 */
  20. gpio_write_bit(CONFIG_SYS_GPIO_CRAM_CRE, 1);
  21. /* Write BCR to CRAM on CS1 */
  22. out32(wr_val + 0x00200000, 0);
  23. debug("CRAM VAL: %08x for CS1 ", wr_val + 0x00200000);
  24. /* Write BCR to CRAM on CS2 */
  25. out32(wr_val + 0x02200000, 0);
  26. debug("CRAM VAL: %08x for CS2\n", wr_val + 0x02200000);
  27. sync();
  28. eieio();
  29. /* set CRAM_CRE back to 0 (normal operation) */
  30. gpio_write_bit(CONFIG_SYS_GPIO_CRAM_CRE, 0);
  31. return;
  32. }
  33. phys_size_t initdram(int board_type)
  34. {
  35. int i;
  36. u32 val;
  37. /* 1. EBC need to program READY, CLK, ADV for ASync mode */
  38. gpio_config(CONFIG_SYS_GPIO_CRAM_CLK, GPIO_OUT, GPIO_SEL, GPIO_OUT_0);
  39. gpio_config(CONFIG_SYS_GPIO_CRAM_ADV, GPIO_OUT, GPIO_SEL, GPIO_OUT_0);
  40. gpio_config(CONFIG_SYS_GPIO_CRAM_CRE, GPIO_OUT, GPIO_SEL, GPIO_OUT_0);
  41. gpio_config(CONFIG_SYS_GPIO_CRAM_WAIT, GPIO_IN, GPIO_SEL, GPIO_OUT_NO_CHG);
  42. /* 2. EBC in Async mode */
  43. mtebc(PB1AP, 0x078F1EC0);
  44. mtebc(PB2AP, 0x078F1EC0);
  45. mtebc(PB1CR, 0x000BC000);
  46. mtebc(PB2CR, 0x020BC000);
  47. /* 3. Set CRAM in Sync mode */
  48. cram_bcr_write(0x7012); /* CRAM burst setting */
  49. /* 4. EBC in Sync mode */
  50. mtebc(PB1AP, 0x9C0201C0);
  51. mtebc(PB2AP, 0x9C0201C0);
  52. /* Set GPIO pins back to alternate function */
  53. gpio_config(CONFIG_SYS_GPIO_CRAM_CLK, GPIO_OUT, GPIO_ALT1, GPIO_OUT_NO_CHG);
  54. gpio_config(CONFIG_SYS_GPIO_CRAM_ADV, GPIO_OUT, GPIO_ALT1, GPIO_OUT_NO_CHG);
  55. /* Config EBC to use RDY */
  56. mfsdr(SDR0_ULTRA0, val);
  57. mtsdr(SDR0_ULTRA0, val | SDR_ULTRA0_EBCRDYEN);
  58. /* Wait a short while, since for NAND booting this is too fast */
  59. for (i=0; i<200000; i++)
  60. ;
  61. return (CONFIG_SYS_MBYTES_RAM << 20);
  62. }