m5235evb.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000-2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
  7. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  8. */
  9. #include <config.h>
  10. #include <common.h>
  11. #include <asm/immap.h>
  12. #include <asm/io.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. int checkboard(void)
  15. {
  16. puts("Board: ");
  17. puts("Freescale M5235 EVB\n");
  18. return 0;
  19. };
  20. int dram_init(void)
  21. {
  22. sdram_t *sdram = (sdram_t *)(MMAP_SDRAM);
  23. gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
  24. u32 dramsize, i, dramclk;
  25. /*
  26. * When booting from external Flash, the port-size is less than
  27. * the port-size of SDRAM. In this case it is necessary to enable
  28. * Data[15:0] on Port Address/Data.
  29. */
  30. out_8(&gpio->par_ad,
  31. GPIO_PAR_AD_ADDR23 | GPIO_PAR_AD_ADDR22 | GPIO_PAR_AD_ADDR21 |
  32. GPIO_PAR_AD_DATAL);
  33. /* Initialize PAR to enable SDRAM signals */
  34. out_8(&gpio->par_sdram,
  35. GPIO_PAR_SDRAM_SDWE | GPIO_PAR_SDRAM_SCAS |
  36. GPIO_PAR_SDRAM_SRAS | GPIO_PAR_SDRAM_SCKE |
  37. GPIO_PAR_SDRAM_SDCS(3));
  38. dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
  39. for (i = 0x13; i < 0x20; i++) {
  40. if (dramsize == (1 << i))
  41. break;
  42. }
  43. i--;
  44. if (!(in_be32(&sdram->dacr0) & SDRAMC_DARCn_RE)) {
  45. dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
  46. /* Initialize DRAM Control Register: DCR */
  47. out_be16(&sdram->dcr, SDRAMC_DCR_RTIM_9CLKS |
  48. SDRAMC_DCR_RTIM_6CLKS |
  49. SDRAMC_DCR_RC((15 * dramclk) >> 4));
  50. /* Initialize DACR0 */
  51. out_be32(&sdram->dacr0,
  52. SDRAMC_DARCn_BA(CONFIG_SYS_SDRAM_BASE) |
  53. SDRAMC_DARCn_CASL_C1 | SDRAMC_DARCn_CBM_CMD20 |
  54. SDRAMC_DARCn_PS_32);
  55. asm("nop");
  56. /* Initialize DMR0 */
  57. out_be32(&sdram->dmr0,
  58. ((dramsize - 1) & 0xFFFC0000) | SDRAMC_DMRn_V);
  59. asm("nop");
  60. /* Set IP (bit 3) in DACR */
  61. setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IP);
  62. /* Wait 30ns to allow banks to precharge */
  63. for (i = 0; i < 5; i++) {
  64. asm("nop");
  65. }
  66. /* Write to this block to initiate precharge */
  67. *(u32 *) (CONFIG_SYS_SDRAM_BASE) = 0xA5A59696;
  68. /* Set RE (bit 15) in DACR */
  69. setbits_be32(&sdram->dacr0, SDRAMC_DARCn_RE);
  70. /* Wait for at least 8 auto refresh cycles to occur */
  71. for (i = 0; i < 0x2000; i++) {
  72. asm("nop");
  73. }
  74. /* Finish the configuration by issuing the MRS. */
  75. setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IMRS);
  76. asm("nop");
  77. /* Write to the SDRAM Mode Register */
  78. *(u32 *) (CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
  79. }
  80. gd->ram_size = dramsize;
  81. return 0;
  82. };
  83. int testdram(void)
  84. {
  85. /* TODO: XXX XXX XXX */
  86. printf("DRAM test not implemented!\n");
  87. return (0);
  88. }