sdram.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * (C) Copyright 2014
  3. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  4. *
  5. * Based on:
  6. * (C) Copyright 2007-2008
  7. * Stelian Pop <stelian@popies.net>
  8. * Lead Tech Design <www.leadtechdesign.com>
  9. *
  10. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <asm/io.h>
  14. #include <asm/arch/at91_common.h>
  15. #include <asm/arch/at91sam9_sdramc.h>
  16. #include <asm/arch/gpio.h>
  17. int sdramc_initialize(unsigned int sdram_address, const struct sdramc_reg *p)
  18. {
  19. struct sdramc_reg *reg = (struct sdramc_reg *)ATMEL_BASE_SDRAMC;
  20. unsigned int i;
  21. /* SDRAM feature must be in the configuration register */
  22. writel(p->cr, &reg->cr);
  23. /* The SDRAM memory type must be set in the Memory Device Register */
  24. writel(p->mdr, &reg->mdr);
  25. /*
  26. * The minimum pause of 200 us is provided to precede any single
  27. * toggle
  28. */
  29. for (i = 0; i < 1000; i++)
  30. ;
  31. /* A NOP command is issued to the SDRAM devices */
  32. writel(AT91_SDRAMC_MODE_NOP, &reg->mr);
  33. writel(0x00000000, sdram_address);
  34. /* An All Banks Precharge command is issued to the SDRAM devices */
  35. writel(AT91_SDRAMC_MODE_PRECHARGE, &reg->mr);
  36. writel(0x00000000, sdram_address);
  37. for (i = 0; i < 10000; i++)
  38. ;
  39. /* Eight auto-refresh cycles are provided */
  40. for (i = 0; i < 8; i++) {
  41. writel(AT91_SDRAMC_MODE_REFRESH, &reg->mr);
  42. writel(0x00000001 + i, sdram_address + 4 + 4 * i);
  43. }
  44. /*
  45. * A Mode Register set (MRS) cyscle is issued to program the
  46. * SDRAM parameters(TCSR, PASR, DS)
  47. */
  48. writel(AT91_SDRAMC_MODE_LMR, &reg->mr);
  49. writel(0xcafedede, sdram_address + 0x24);
  50. /*
  51. * The application must go into Normal Mode, setting Mode
  52. * to 0 in the Mode Register and perform a write access at
  53. * any location in the SDRAM.
  54. */
  55. writel(AT91_SDRAMC_MODE_NORMAL, &reg->mr);
  56. writel(0x00000000, sdram_address); /* Perform Normal mode */
  57. /*
  58. * Write the refresh rate into the count field in the SDRAMC
  59. * Refresh Timer Rgister.
  60. */
  61. writel(p->tr, &reg->tr);
  62. return 0;
  63. }