sdram.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/at91_pmc.h>
  16. #include <asm/arch/at91sam9_sdramc.h>
  17. #include <asm/arch/gpio.h>
  18. int sdramc_initialize(unsigned int sdram_address, const struct sdramc_reg *p)
  19. {
  20. struct sdramc_reg *reg = (struct sdramc_reg *)ATMEL_BASE_SDRAMC;
  21. unsigned int i;
  22. /* SDRAM feature must be in the configuration register */
  23. writel(p->cr, &reg->cr);
  24. /* The SDRAM memory type must be set in the Memory Device Register */
  25. writel(p->mdr, &reg->mdr);
  26. /*
  27. * The minimum pause of 200 us is provided to precede any single
  28. * toggle
  29. */
  30. for (i = 0; i < 1000; i++)
  31. ;
  32. /* A NOP command is issued to the SDRAM devices */
  33. writel(AT91_SDRAMC_MODE_NOP, &reg->mr);
  34. writel(0x00000000, sdram_address);
  35. /* An All Banks Precharge command is issued to the SDRAM devices */
  36. writel(AT91_SDRAMC_MODE_PRECHARGE, &reg->mr);
  37. writel(0x00000000, sdram_address);
  38. for (i = 0; i < 10000; i++)
  39. ;
  40. /* Eight auto-refresh cycles are provided */
  41. for (i = 0; i < 8; i++) {
  42. writel(AT91_SDRAMC_MODE_REFRESH, &reg->mr);
  43. writel(0x00000001 + i, sdram_address + 4 + 4 * i);
  44. }
  45. /*
  46. * A Mode Register set (MRS) cyscle is issued to program the
  47. * SDRAM parameters(TCSR, PASR, DS)
  48. */
  49. writel(AT91_SDRAMC_MODE_LMR, &reg->mr);
  50. writel(0xcafedede, sdram_address + 0x24);
  51. /*
  52. * The application must go into Normal Mode, setting Mode
  53. * to 0 in the Mode Register and perform a write access at
  54. * any location in the SDRAM.
  55. */
  56. writel(AT91_SDRAMC_MODE_NORMAL, &reg->mr);
  57. writel(0x00000000, sdram_address); /* Perform Normal mode */
  58. /*
  59. * Write the refresh rate into the count field in the SDRAMC
  60. * Refresh Timer Rgister.
  61. */
  62. writel(p->tr, &reg->tr);
  63. return 0;
  64. }