blob: ff1e3125a00f94d588964886fff6e29e5a6cdd47 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Steve Sakoman27952012010-07-15 16:19:16 -04002/*
3 * (C) Copyright 2010
4 * Texas Instruments, <www.ti.com>
5 *
pekon guptaa0a37182014-05-08 21:43:47 +05306 * Author :
7 * Mansoor Ahamed <mansoor.ahamed@ti.com>
8 *
9 * Initial Code from:
10 * Manikandan Pillai <mani.pillai@ti.com>
11 * Richard Woodruff <r-woodruff2@ti.com>
12 * Syed Mohammed Khasim <khasim@ti.com>
Steve Sakoman27952012010-07-15 16:19:16 -040013 */
14
pekon guptaa0a37182014-05-08 21:43:47 +053015#include <common.h>
16#include <asm/io.h>
Steve Sakoman27952012010-07-15 16:19:16 -040017#include <asm/arch/cpu.h>
pekon guptaa0a37182014-05-08 21:43:47 +053018#include <asm/arch/mem.h>
Steve Sakoman27952012010-07-15 16:19:16 -040019#include <asm/arch/sys_proto.h>
pekon guptaa0a37182014-05-08 21:43:47 +053020#include <command.h>
21#include <linux/mtd/omap_gpmc.h>
Ladislav Michl22d6ac42016-07-12 20:28:17 +020022#include <jffs2/load_kernel.h>
Steve Sakoman27952012010-07-15 16:19:16 -040023
Ladislav Michl0568dd02016-07-12 20:28:16 +020024const struct gpmc *gpmc_cfg = (struct gpmc *)GPMC_BASE;
Steve Sakoman27952012010-07-15 16:19:16 -040025
Ladislav Michl22d6ac42016-07-12 20:28:17 +020026#if defined(CONFIG_NOR)
27char gpmc_cs0_flash = MTD_DEV_TYPE_NOR;
28#elif defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
29char gpmc_cs0_flash = MTD_DEV_TYPE_NAND;
30#elif defined(CONFIG_CMD_ONENAND)
31char gpmc_cs0_flash = MTD_DEV_TYPE_ONENAND;
32#else
33char gpmc_cs0_flash = -1;
34#endif
35
pekon guptaa0a37182014-05-08 21:43:47 +053036#if defined(CONFIG_OMAP34XX)
37/********************************************************
38 * mem_ok() - test used to see if timings are correct
39 * for a part. Helps in guessing which part
40 * we are currently using.
41 *******************************************************/
42u32 mem_ok(u32 cs)
43{
44 u32 val1, val2, addr;
45 u32 pattern = 0x12345678;
46
47 addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
48
49 writel(0x0, addr + 0x400); /* clear pos A */
50 writel(pattern, addr); /* pattern to pos B */
51 writel(0x0, addr + 4); /* remove pattern off the bus */
52 val1 = readl(addr + 0x400); /* get pos A value */
53 val2 = readl(addr); /* get val2 */
54 writel(0x0, addr + 0x400); /* clear pos A */
55
56 if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
57 return 0;
58 else
59 return 1;
60}
61#endif
62
Ladislav Michl0568dd02016-07-12 20:28:16 +020063void enable_gpmc_cs_config(const u32 *gpmc_config, const struct gpmc_cs *cs,
64 u32 base, u32 size)
pekon guptaa0a37182014-05-08 21:43:47 +053065{
66 writel(0, &cs->config7);
67 sdelay(1000);
68 /* Delay for settling */
69 writel(gpmc_config[0], &cs->config1);
70 writel(gpmc_config[1], &cs->config2);
71 writel(gpmc_config[2], &cs->config3);
72 writel(gpmc_config[3], &cs->config4);
73 writel(gpmc_config[4], &cs->config5);
74 writel(gpmc_config[5], &cs->config6);
75 /* Enable the config */
76 writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
77 (1 << 6)), &cs->config7);
78 sdelay(2000);
79}
80
Ladislav Michl22d6ac42016-07-12 20:28:17 +020081void set_gpmc_cs0(int flash_type)
82{
83 const u32 *gpmc_regs;
84 u32 base, size;
85#if defined(CONFIG_NOR)
86 const u32 gpmc_regs_nor[GPMC_MAX_REG] = {
87 STNOR_GPMC_CONFIG1,
88 STNOR_GPMC_CONFIG2,
89 STNOR_GPMC_CONFIG3,
90 STNOR_GPMC_CONFIG4,
91 STNOR_GPMC_CONFIG5,
92 STNOR_GPMC_CONFIG6,
93 STNOR_GPMC_CONFIG7
94 };
95#endif
96#if defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
97 const u32 gpmc_regs_nand[GPMC_MAX_REG] = {
98 M_NAND_GPMC_CONFIG1,
99 M_NAND_GPMC_CONFIG2,
100 M_NAND_GPMC_CONFIG3,
101 M_NAND_GPMC_CONFIG4,
102 M_NAND_GPMC_CONFIG5,
103 M_NAND_GPMC_CONFIG6,
104 0
105 };
106#endif
107#if defined(CONFIG_CMD_ONENAND)
108 const u32 gpmc_regs_onenand[GPMC_MAX_REG] = {
109 ONENAND_GPMC_CONFIG1,
110 ONENAND_GPMC_CONFIG2,
111 ONENAND_GPMC_CONFIG3,
112 ONENAND_GPMC_CONFIG4,
113 ONENAND_GPMC_CONFIG5,
114 ONENAND_GPMC_CONFIG6,
115 0
116 };
117#endif
118
119 switch (flash_type) {
120#if defined(CONFIG_NOR)
121 case MTD_DEV_TYPE_NOR:
122 gpmc_regs = gpmc_regs_nor;
123 base = CONFIG_SYS_FLASH_BASE;
124 size = (CONFIG_SYS_FLASH_SIZE > 0x08000000) ? GPMC_SIZE_256M :
125 ((CONFIG_SYS_FLASH_SIZE > 0x04000000) ? GPMC_SIZE_128M :
126 ((CONFIG_SYS_FLASH_SIZE > 0x02000000) ? GPMC_SIZE_64M :
127 ((CONFIG_SYS_FLASH_SIZE > 0x01000000) ? GPMC_SIZE_32M :
128 GPMC_SIZE_16M)));
129 break;
130#endif
131#if defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND)
132 case MTD_DEV_TYPE_NAND:
133 gpmc_regs = gpmc_regs_nand;
134 base = CONFIG_SYS_NAND_BASE;
135 size = GPMC_SIZE_16M;
136 break;
137#endif
138#if defined(CONFIG_CMD_ONENAND)
139 case MTD_DEV_TYPE_ONENAND:
140 gpmc_regs = gpmc_regs_onenand;
141 base = CONFIG_SYS_ONENAND_BASE;
142 size = GPMC_SIZE_128M;
143 break;
144#endif
145 default:
146 /* disable the GPMC0 config set by ROM code */
147 writel(0, &gpmc_cfg->cs[0].config7);
148 sdelay(1000);
149 return;
150 }
151
152 /* enable chip-select specific configurations */
153 enable_gpmc_cs_config(gpmc_regs, &gpmc_cfg->cs[0], base, size);
154}
155
Steve Sakoman27952012010-07-15 16:19:16 -0400156/*****************************************************
157 * gpmc_init(): init gpmc bus
pekon guptaa0a37182014-05-08 21:43:47 +0530158 * Init GPMC for x16, MuxMode (SDRAM in x32).
Steve Sakoman27952012010-07-15 16:19:16 -0400159 * This code can only be executed from SRAM or SDRAM.
160 *****************************************************/
161void gpmc_init(void)
162{
Steve Sakoman27952012010-07-15 16:19:16 -0400163 /* global settings */
pekon guptaa0a37182014-05-08 21:43:47 +0530164 writel(0x00000008, &gpmc_cfg->sysconfig);
165 writel(0x00000000, &gpmc_cfg->irqstatus);
166 writel(0x00000000, &gpmc_cfg->irqenable);
Stefano Babic734af242014-06-17 16:47:40 +0200167 /* disable timeout, set a safe reset value */
168 writel(0x00001ff0, &gpmc_cfg->timeout_control);
Ladislav Michl22d6ac42016-07-12 20:28:17 +0200169 writel(gpmc_cs0_flash == MTD_DEV_TYPE_NOR ?
170 0x00000200 : 0x00000012, &gpmc_cfg->config);
171
172 set_gpmc_cs0(gpmc_cs0_flash);
Steve Sakoman27952012010-07-15 16:19:16 -0400173}