blob: d72e82e028338b01d149c6f2fda86d6e839bd2e6 [file] [log] [blame]
Steve Sakoman27952012010-07-15 16:19:16 -04001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 *
pekon guptaa0a37182014-05-08 21:43:47 +05305 * 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>
Steve Sakoman27952012010-07-15 16:19:16 -040012 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020013 * SPDX-License-Identifier: GPL-2.0+
Steve Sakoman27952012010-07-15 16:19:16 -040014 */
15
pekon guptaa0a37182014-05-08 21:43:47 +053016#include <common.h>
17#include <asm/io.h>
Steve Sakoman27952012010-07-15 16:19:16 -040018#include <asm/arch/cpu.h>
pekon guptaa0a37182014-05-08 21:43:47 +053019#include <asm/arch/mem.h>
Steve Sakoman27952012010-07-15 16:19:16 -040020#include <asm/arch/sys_proto.h>
pekon guptaa0a37182014-05-08 21:43:47 +053021#include <command.h>
22#include <linux/mtd/omap_gpmc.h>
Ladislav Michl22d6ac42016-07-12 20:28:17 +020023#include <jffs2/load_kernel.h>
Steve Sakoman27952012010-07-15 16:19:16 -040024
Ladislav Michl0568dd02016-07-12 20:28:16 +020025const struct gpmc *gpmc_cfg = (struct gpmc *)GPMC_BASE;
Steve Sakoman27952012010-07-15 16:19:16 -040026
Ladislav Michl22d6ac42016-07-12 20:28:17 +020027#if defined(CONFIG_NOR)
28char gpmc_cs0_flash = MTD_DEV_TYPE_NOR;
29#elif defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
30char gpmc_cs0_flash = MTD_DEV_TYPE_NAND;
31#elif defined(CONFIG_CMD_ONENAND)
32char gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND;
33#else
34char gpmc_cs0_flash = -1;
35#endif
36
pekon guptaa0a37182014-05-08 21:43:47 +053037#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 *******************************************************/
43u32 mem_ok(u32 cs)
44{
45 u32 val1, val2, addr;
46 u32 pattern = 0x12345678;
47
48 addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
49
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 */
56
57 if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
58 return 0;
59 else
60 return 1;
61}
62#endif
63
Ladislav Michl0568dd02016-07-12 20:28:16 +020064void enable_gpmc_cs_config(const u32 *gpmc_config, const struct gpmc_cs *cs,
65 u32 base, u32 size)
pekon guptaa0a37182014-05-08 21:43:47 +053066{
67 writel(0, &cs->config7);
68 sdelay(1000);
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);
79 sdelay(2000);
80}
81
Ladislav Michl22d6ac42016-07-12 20:28:17 +020082void set_gpmc_cs0(int flash_type)
83{
84 const u32 *gpmc_regs;
85 u32 base, size;
86#if defined(CONFIG_NOR)
87 const u32 gpmc_regs_nor[GPMC_MAX_REG] = {
88 STNOR_GPMC_CONFIG1,
89 STNOR_GPMC_CONFIG2,
90 STNOR_GPMC_CONFIG3,
91 STNOR_GPMC_CONFIG4,
92 STNOR_GPMC_CONFIG5,
93 STNOR_GPMC_CONFIG6,
94 STNOR_GPMC_CONFIG7
95 };
96#endif
97#if defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
98 const u32 gpmc_regs_nand[GPMC_MAX_REG] = {
99 M_NAND_GPMC_CONFIG1,
100 M_NAND_GPMC_CONFIG2,
101 M_NAND_GPMC_CONFIG3,
102 M_NAND_GPMC_CONFIG4,
103 M_NAND_GPMC_CONFIG5,
104 M_NAND_GPMC_CONFIG6,
105 0
106 };
107#endif
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,
116 0
117 };
118#endif
119
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 :
129 GPMC_SIZE_16M)));
130 break;
131#endif
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;
137 break;
138#endif
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;
144 break;
145#endif
146 default:
147 /* disable the GPMC0 config set by ROM code */
148 writel(0, &gpmc_cfg->cs[0].config7);
149 sdelay(1000);
150 return;
151 }
152
153 /* enable chip-select specific configurations */
154 enable_gpmc_cs_config(gpmc_regs, &gpmc_cfg->cs[0], base, size);
155}
156
Steve Sakoman27952012010-07-15 16:19:16 -0400157/*****************************************************
158 * gpmc_init(): init gpmc bus
pekon guptaa0a37182014-05-08 21:43:47 +0530159 * Init GPMC for x16, MuxMode (SDRAM in x32).
Steve Sakoman27952012010-07-15 16:19:16 -0400160 * This code can only be executed from SRAM or SDRAM.
161 *****************************************************/
162void gpmc_init(void)
163{
Steve Sakoman27952012010-07-15 16:19:16 -0400164 /* global settings */
pekon guptaa0a37182014-05-08 21:43:47 +0530165 writel(0x00000008, &gpmc_cfg->sysconfig);
166 writel(0x00000000, &gpmc_cfg->irqstatus);
167 writel(0x00000000, &gpmc_cfg->irqenable);
Stefano Babic734af242014-06-17 16:47:40 +0200168 /* disable timeout, set a safe reset value */
169 writel(0x00001ff0, &gpmc_cfg->timeout_control);
Ladislav Michl22d6ac42016-07-12 20:28:17 +0200170 writel(gpmc_cs0_flash == MTD_DEV_TYPE_NOR ?
171 0x00000200 : 0x00000012, &gpmc_cfg->config);
172
173 set_gpmc_cs0(gpmc_cs0_flash);
Steve Sakoman27952012010-07-15 16:19:16 -0400174}