mem-common.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #include <jffs2/load_kernel.h>
  23. const struct gpmc *gpmc_cfg = (struct gpmc *)GPMC_BASE;
  24. #if defined(CONFIG_NOR)
  25. char gpmc_cs0_flash = MTD_DEV_TYPE_NOR;
  26. #elif defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
  27. char gpmc_cs0_flash = MTD_DEV_TYPE_NAND;
  28. #elif defined(CONFIG_CMD_ONENAND)
  29. char gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND;
  30. #else
  31. char gpmc_cs0_flash = -1;
  32. #endif
  33. #if defined(CONFIG_OMAP34XX)
  34. /********************************************************
  35. * mem_ok() - test used to see if timings are correct
  36. * for a part. Helps in guessing which part
  37. * we are currently using.
  38. *******************************************************/
  39. u32 mem_ok(u32 cs)
  40. {
  41. u32 val1, val2, addr;
  42. u32 pattern = 0x12345678;
  43. addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
  44. writel(0x0, addr + 0x400); /* clear pos A */
  45. writel(pattern, addr); /* pattern to pos B */
  46. writel(0x0, addr + 4); /* remove pattern off the bus */
  47. val1 = readl(addr + 0x400); /* get pos A value */
  48. val2 = readl(addr); /* get val2 */
  49. writel(0x0, addr + 0x400); /* clear pos A */
  50. if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
  51. return 0;
  52. else
  53. return 1;
  54. }
  55. #endif
  56. void enable_gpmc_cs_config(const u32 *gpmc_config, const struct gpmc_cs *cs,
  57. u32 base, u32 size)
  58. {
  59. writel(0, &cs->config7);
  60. sdelay(1000);
  61. /* Delay for settling */
  62. writel(gpmc_config[0], &cs->config1);
  63. writel(gpmc_config[1], &cs->config2);
  64. writel(gpmc_config[2], &cs->config3);
  65. writel(gpmc_config[3], &cs->config4);
  66. writel(gpmc_config[4], &cs->config5);
  67. writel(gpmc_config[5], &cs->config6);
  68. /* Enable the config */
  69. writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
  70. (1 << 6)), &cs->config7);
  71. sdelay(2000);
  72. }
  73. void set_gpmc_cs0(int flash_type)
  74. {
  75. const u32 *gpmc_regs;
  76. u32 base, size;
  77. #if defined(CONFIG_NOR)
  78. const u32 gpmc_regs_nor[GPMC_MAX_REG] = {
  79. STNOR_GPMC_CONFIG1,
  80. STNOR_GPMC_CONFIG2,
  81. STNOR_GPMC_CONFIG3,
  82. STNOR_GPMC_CONFIG4,
  83. STNOR_GPMC_CONFIG5,
  84. STNOR_GPMC_CONFIG6,
  85. STNOR_GPMC_CONFIG7
  86. };
  87. #endif
  88. #if defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
  89. const u32 gpmc_regs_nand[GPMC_MAX_REG] = {
  90. 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. #endif
  99. #if defined(CONFIG_CMD_ONENAND)
  100. const u32 gpmc_regs_onenand[GPMC_MAX_REG] = {
  101. 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. #endif
  110. switch (flash_type) {
  111. #if defined(CONFIG_NOR)
  112. case MTD_DEV_TYPE_NOR:
  113. gpmc_regs = gpmc_regs_nor;
  114. base = CONFIG_SYS_FLASH_BASE;
  115. size = (CONFIG_SYS_FLASH_SIZE > 0x08000000) ? GPMC_SIZE_256M :
  116. ((CONFIG_SYS_FLASH_SIZE > 0x04000000) ? GPMC_SIZE_128M :
  117. ((CONFIG_SYS_FLASH_SIZE > 0x02000000) ? GPMC_SIZE_64M :
  118. ((CONFIG_SYS_FLASH_SIZE > 0x01000000) ? GPMC_SIZE_32M :
  119. GPMC_SIZE_16M)));
  120. break;
  121. #endif
  122. #if defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
  123. case MTD_DEV_TYPE_NAND:
  124. gpmc_regs = gpmc_regs_nand;
  125. base = CONFIG_SYS_NAND_BASE;
  126. size = GPMC_SIZE_16M;
  127. break;
  128. #endif
  129. #if defined(CONFIG_CMD_ONENAND)
  130. case MTD_DEV_TYPE_ONENAND:
  131. gpmc_regs = gpmc_regs_onenand;
  132. base = CONFIG_SYS_ONENAND_BASE;
  133. size = GPMC_SIZE_128M;
  134. break;
  135. #endif
  136. default:
  137. /* disable the GPMC0 config set by ROM code */
  138. writel(0, &gpmc_cfg->cs[0].config7);
  139. sdelay(1000);
  140. return;
  141. }
  142. /* enable chip-select specific configurations */
  143. enable_gpmc_cs_config(gpmc_regs, &gpmc_cfg->cs[0], base, size);
  144. }
  145. /*****************************************************
  146. * gpmc_init(): init gpmc bus
  147. * Init GPMC for x16, MuxMode (SDRAM in x32).
  148. * This code can only be executed from SRAM or SDRAM.
  149. *****************************************************/
  150. void gpmc_init(void)
  151. {
  152. /* global settings */
  153. writel(0x00000008, &gpmc_cfg->sysconfig);
  154. writel(0x00000000, &gpmc_cfg->irqstatus);
  155. writel(0x00000000, &gpmc_cfg->irqenable);
  156. /* disable timeout, set a safe reset value */
  157. writel(0x00001ff0, &gpmc_cfg->timeout_control);
  158. writel(gpmc_cs0_flash == MTD_DEV_TYPE_NOR ?
  159. 0x00000200 : 0x00000012, &gpmc_cfg->config);
  160. set_gpmc_cs0(gpmc_cs0_flash);
  161. }