m5235evb.c 2.5 KB

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