sdram.c 1.9 KB

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