mem-common.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * (C) Copyright 2010
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Author :
  6. * Mansoor Ahamed <mansoor.ahamed@ti.com>
  7. *
  8. * Initial Code from:
  9. * Manikandan Pillai <mani.pillai@ti.com>
  10. * Richard Woodruff <r-woodruff2@ti.com>
  11. * Syed Mohammed Khasim <khasim@ti.com>
  12. *
  13. * SPDX-License-Identifier: GPL-2.0+
  14. */
  15. #include <common.h>
  16. #include <asm/io.h>
  17. #include <asm/arch/cpu.h>
  18. #include <asm/arch/mem.h>
  19. #include <asm/arch/sys_proto.h>
  20. #include <command.h>
  21. #include <linux/mtd/omap_gpmc.h>
  22. struct gpmc *gpmc_cfg;
  23. #if defined(CONFIG_OMAP34XX)
  24. /********************************************************
  25. * mem_ok() - test used to see if timings are correct
  26. * for a part. Helps in guessing which part
  27. * we are currently using.
  28. *******************************************************/
  29. u32 mem_ok(u32 cs)
  30. {
  31. u32 val1, val2, addr;
  32. u32 pattern = 0x12345678;
  33. addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
  34. writel(0x0, addr + 0x400); /* clear pos A */
  35. writel(pattern, addr); /* pattern to pos B */
  36. writel(0x0, addr + 4); /* remove pattern off the bus */
  37. val1 = readl(addr + 0x400); /* get pos A value */
  38. val2 = readl(addr); /* get val2 */
  39. writel(0x0, addr + 0x400); /* clear pos A */
  40. if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
  41. return 0;
  42. else
  43. return 1;
  44. }
  45. #endif
  46. void enable_gpmc_cs_config(const u32 *gpmc_config, struct gpmc_cs *cs, u32 base,
  47. u32 size)
  48. {
  49. writel(0, &cs->config7);
  50. sdelay(1000);
  51. /* Delay for settling */
  52. writel(gpmc_config[0], &cs->config1);
  53. writel(gpmc_config[1], &cs->config2);
  54. writel(gpmc_config[2], &cs->config3);
  55. writel(gpmc_config[3], &cs->config4);
  56. writel(gpmc_config[4], &cs->config5);
  57. writel(gpmc_config[5], &cs->config6);
  58. /* Enable the config */
  59. writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
  60. (1 << 6)), &cs->config7);
  61. sdelay(2000);
  62. }
  63. /*****************************************************
  64. * gpmc_init(): init gpmc bus
  65. * Init GPMC for x16, MuxMode (SDRAM in x32).
  66. * This code can only be executed from SRAM or SDRAM.
  67. *****************************************************/
  68. void gpmc_init(void)
  69. {
  70. /* putting a blanket check on GPMC based on ZeBu for now */
  71. gpmc_cfg = (struct gpmc *)GPMC_BASE;
  72. #if defined(CONFIG_NOR)
  73. /* configure GPMC for NOR */
  74. const u32 gpmc_regs[GPMC_MAX_REG] = { STNOR_GPMC_CONFIG1,
  75. STNOR_GPMC_CONFIG2,
  76. STNOR_GPMC_CONFIG3,
  77. STNOR_GPMC_CONFIG4,
  78. STNOR_GPMC_CONFIG5,
  79. STNOR_GPMC_CONFIG6,
  80. STNOR_GPMC_CONFIG7
  81. };
  82. u32 base = CONFIG_SYS_FLASH_BASE;
  83. u32 size = (CONFIG_SYS_FLASH_SIZE > 0x08000000) ? GPMC_SIZE_256M :
  84. /* > 64MB */ ((CONFIG_SYS_FLASH_SIZE > 0x04000000) ? GPMC_SIZE_128M :
  85. /* > 32MB */ ((CONFIG_SYS_FLASH_SIZE > 0x02000000) ? GPMC_SIZE_64M :
  86. /* > 16MB */ ((CONFIG_SYS_FLASH_SIZE > 0x01000000) ? GPMC_SIZE_32M :
  87. /* min 16MB */ GPMC_SIZE_16M)));
  88. #elif defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
  89. /* configure GPMC for NAND */
  90. const u32 gpmc_regs[GPMC_MAX_REG] = { M_NAND_GPMC_CONFIG1,
  91. M_NAND_GPMC_CONFIG2,
  92. M_NAND_GPMC_CONFIG3,
  93. M_NAND_GPMC_CONFIG4,
  94. M_NAND_GPMC_CONFIG5,
  95. M_NAND_GPMC_CONFIG6,
  96. 0
  97. };
  98. u32 base = CONFIG_SYS_NAND_BASE;
  99. u32 size = GPMC_SIZE_16M;
  100. #elif defined(CONFIG_CMD_ONENAND)
  101. const u32 gpmc_regs[GPMC_MAX_REG] = { ONENAND_GPMC_CONFIG1,
  102. ONENAND_GPMC_CONFIG2,
  103. ONENAND_GPMC_CONFIG3,
  104. ONENAND_GPMC_CONFIG4,
  105. ONENAND_GPMC_CONFIG5,
  106. ONENAND_GPMC_CONFIG6,
  107. 0
  108. };
  109. u32 size = GPMC_SIZE_128M;
  110. u32 base = CONFIG_SYS_ONENAND_BASE;
  111. #else
  112. const u32 gpmc_regs[GPMC_MAX_REG] = { 0, 0, 0, 0, 0, 0, 0 };
  113. u32 size = 0;
  114. u32 base = 0;
  115. #endif
  116. /* global settings */
  117. writel(0x00000008, &gpmc_cfg->sysconfig);
  118. writel(0x00000000, &gpmc_cfg->irqstatus);
  119. writel(0x00000000, &gpmc_cfg->irqenable);
  120. /* disable timeout, set a safe reset value */
  121. writel(0x00001ff0, &gpmc_cfg->timeout_control);
  122. #ifdef CONFIG_NOR
  123. writel(0x00000200, &gpmc_cfg->config);
  124. #else
  125. writel(0x00000012, &gpmc_cfg->config);
  126. #endif
  127. /*
  128. * Disable the GPMC0 config set by ROM code
  129. */
  130. writel(0, &gpmc_cfg->cs[0].config7);
  131. sdelay(1000);
  132. /* enable chip-select specific configurations */
  133. if (base != 0)
  134. enable_gpmc_cs_config(gpmc_regs, &gpmc_cfg->cs[0], base, size);
  135. }