3 * Texas Instruments, <www.ti.com>
6 * Mansoor Ahamed <mansoor.ahamed@ti.com>
9 * Manikandan Pillai <mani.pillai@ti.com>
10 * Richard Woodruff <r-woodruff2@ti.com>
11 * Syed Mohammed Khasim <khasim@ti.com>
13 * SPDX-License-Identifier: GPL-2.0+
18 #include <asm/arch/cpu.h>
19 #include <asm/arch/mem.h>
20 #include <asm/arch/sys_proto.h>
22 #include <linux/mtd/omap_gpmc.h>
23 #include <jffs2/load_kernel.h>
25 const struct gpmc *gpmc_cfg = (struct gpmc *)GPMC_BASE;
27 #if defined(CONFIG_NOR)
28 char gpmc_cs0_flash = MTD_DEV_TYPE_NOR;
29 #elif defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
30 char gpmc_cs0_flash = MTD_DEV_TYPE_NAND;
31 #elif defined(CONFIG_CMD_ONENAND)
32 char gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND;
34 char gpmc_cs0_flash = -1;
37 #if defined(CONFIG_OMAP34XX)
38 /********************************************************
39 * mem_ok() - test used to see if timings are correct
40 * for a part. Helps in guessing which part
41 * we are currently using.
42 *******************************************************/
46 u32 pattern = 0x12345678;
48 addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
50 writel(0x0, addr + 0x400); /* clear pos A */
51 writel(pattern, addr); /* pattern to pos B */
52 writel(0x0, addr + 4); /* remove pattern off the bus */
53 val1 = readl(addr + 0x400); /* get pos A value */
54 val2 = readl(addr); /* get val2 */
55 writel(0x0, addr + 0x400); /* clear pos A */
57 if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
64 void enable_gpmc_cs_config(const u32 *gpmc_config, const struct gpmc_cs *cs,
67 writel(0, &cs->config7);
69 /* Delay for settling */
70 writel(gpmc_config[0], &cs->config1);
71 writel(gpmc_config[1], &cs->config2);
72 writel(gpmc_config[2], &cs->config3);
73 writel(gpmc_config[3], &cs->config4);
74 writel(gpmc_config[4], &cs->config5);
75 writel(gpmc_config[5], &cs->config6);
76 /* Enable the config */
77 writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
78 (1 << 6)), &cs->config7);
82 void set_gpmc_cs0(int flash_type)
86 #if defined(CONFIG_NOR)
87 const u32 gpmc_regs_nor[GPMC_MAX_REG] = {
97 #if defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
98 const u32 gpmc_regs_nand[GPMC_MAX_REG] = {
108 #if defined(CONFIG_CMD_ONENAND)
109 const u32 gpmc_regs_onenand[GPMC_MAX_REG] = {
110 ONENAND_GPMC_CONFIG1,
111 ONENAND_GPMC_CONFIG2,
112 ONENAND_GPMC_CONFIG3,
113 ONENAND_GPMC_CONFIG4,
114 ONENAND_GPMC_CONFIG5,
115 ONENAND_GPMC_CONFIG6,
120 switch (flash_type) {
121 #if defined(CONFIG_NOR)
122 case MTD_DEV_TYPE_NOR:
123 gpmc_regs = gpmc_regs_nor;
124 base = CONFIG_SYS_FLASH_BASE;
125 size = (CONFIG_SYS_FLASH_SIZE > 0x08000000) ? GPMC_SIZE_256M :
126 ((CONFIG_SYS_FLASH_SIZE > 0x04000000) ? GPMC_SIZE_128M :
127 ((CONFIG_SYS_FLASH_SIZE > 0x02000000) ? GPMC_SIZE_64M :
128 ((CONFIG_SYS_FLASH_SIZE > 0x01000000) ? GPMC_SIZE_32M :
132 #if defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
133 case MTD_DEV_TYPE_NAND:
134 gpmc_regs = gpmc_regs_nand;
135 base = CONFIG_SYS_NAND_BASE;
136 size = GPMC_SIZE_16M;
139 #if defined(CONFIG_CMD_ONENAND)
140 case MTD_DEV_TYPE_ONENAND:
141 gpmc_regs = gpmc_regs_onenand;
142 base = CONFIG_SYS_ONENAND_BASE;
143 size = GPMC_SIZE_128M;
147 /* disable the GPMC0 config set by ROM code */
148 writel(0, &gpmc_cfg->cs[0].config7);
153 /* enable chip-select specific configurations */
154 enable_gpmc_cs_config(gpmc_regs, &gpmc_cfg->cs[0], base, size);
157 /*****************************************************
158 * gpmc_init(): init gpmc bus
159 * Init GPMC for x16, MuxMode (SDRAM in x32).
160 * This code can only be executed from SRAM or SDRAM.
161 *****************************************************/
164 /* global settings */
165 writel(0x00000008, &gpmc_cfg->sysconfig);
166 writel(0x00000000, &gpmc_cfg->irqstatus);
167 writel(0x00000000, &gpmc_cfg->irqenable);
168 /* disable timeout, set a safe reset value */
169 writel(0x00001ff0, &gpmc_cfg->timeout_control);
170 writel(gpmc_cs0_flash == MTD_DEV_TYPE_NOR ?
171 0x00000200 : 0x00000012, &gpmc_cfg->config);
173 set_gpmc_cs0(gpmc_cs0_flash);