blob: 1ca37a9c2df49d552d004ae9d7878c6b1e374a74 [file] [log] [blame]
Dirk Behme595d37b2008-12-14 09:47:14 +01001/*
2 * (C) Copyright 2008
3 * Texas Instruments, <www.ti.com>
4 *
5 * Author :
6 * Manikandan Pillai <mani.pillai@ti.com>
7 *
8 * Initial Code from:
9 * Richard Woodruff <r-woodruff2@ti.com>
10 * Syed Mohammed Khasim <khasim@ti.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <asm/io.h>
30#include <asm/arch/mem.h>
31#include <asm/arch/sys_proto.h>
32#include <command.h>
33
Dirk Behmea4becd62009-08-08 09:30:22 +020034struct gpmc *gpmc_cfg;
35
Dirk Behme595d37b2008-12-14 09:47:14 +010036#if defined(CONFIG_CMD_NAND)
Nishanth Menon3d0377f2009-10-13 12:49:55 -040037static const u32 gpmc_m_nand[GPMC_MAX_REG] = {
Dirk Behme595d37b2008-12-14 09:47:14 +010038 M_NAND_GPMC_CONFIG1,
39 M_NAND_GPMC_CONFIG2,
40 M_NAND_GPMC_CONFIG3,
41 M_NAND_GPMC_CONFIG4,
42 M_NAND_GPMC_CONFIG5,
43 M_NAND_GPMC_CONFIG6, 0
44};
Dirk Behme595d37b2008-12-14 09:47:14 +010045#endif
46
47#if defined(CONFIG_CMD_ONENAND)
Nishanth Menon3d0377f2009-10-13 12:49:55 -040048static const u32 gpmc_onenand[GPMC_MAX_REG] = {
Dirk Behme595d37b2008-12-14 09:47:14 +010049 ONENAND_GPMC_CONFIG1,
50 ONENAND_GPMC_CONFIG2,
51 ONENAND_GPMC_CONFIG3,
52 ONENAND_GPMC_CONFIG4,
53 ONENAND_GPMC_CONFIG5,
54 ONENAND_GPMC_CONFIG6, 0
55};
Dirk Behme595d37b2008-12-14 09:47:14 +010056#endif
57
Dirk Behme595d37b2008-12-14 09:47:14 +010058/********************************************************
59 * mem_ok() - test used to see if timings are correct
60 * for a part. Helps in guessing which part
61 * we are currently using.
62 *******************************************************/
63u32 mem_ok(u32 cs)
64{
65 u32 val1, val2, addr;
66 u32 pattern = 0x12345678;
67
68 addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
69
70 writel(0x0, addr + 0x400); /* clear pos A */
71 writel(pattern, addr); /* pattern to pos B */
72 writel(0x0, addr + 4); /* remove pattern off the bus */
73 val1 = readl(addr + 0x400); /* get pos A value */
74 val2 = readl(addr); /* get val2 */
Tom Rinic8a003a2011-11-18 12:48:01 +000075 writel(0x0, addr + 0x400); /* clear pos A */
Dirk Behme595d37b2008-12-14 09:47:14 +010076
77 if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
78 return 0;
79 else
80 return 1;
81}
82
Nishanth Menon3d0377f2009-10-13 12:49:55 -040083void enable_gpmc_cs_config(const u32 *gpmc_config, struct gpmc_cs *cs, u32 base,
Dirk Behme595d37b2008-12-14 09:47:14 +010084 u32 size)
85{
Matthias Ludwige06da3d2009-05-19 09:09:31 +020086 writel(0, &cs->config7);
Dirk Behme595d37b2008-12-14 09:47:14 +010087 sdelay(1000);
88 /* Delay for settling */
Matthias Ludwige06da3d2009-05-19 09:09:31 +020089 writel(gpmc_config[0], &cs->config1);
90 writel(gpmc_config[1], &cs->config2);
91 writel(gpmc_config[2], &cs->config3);
92 writel(gpmc_config[3], &cs->config4);
93 writel(gpmc_config[4], &cs->config5);
94 writel(gpmc_config[5], &cs->config6);
Tom Rini51b2be52011-11-18 12:47:58 +000095
96 /*
97 * Enable the config. size is the CS size and goes in
98 * bits 11:8. We set bit 6 to enable this CS and the base
99 * address goes into bits 5:0.
100 */
101 writel((size << 8) | (GPMC_CS_ENABLE << 6) |
102 ((base >> 24) & GPMC_BASEADDR_MASK),
103 &cs->config7);
Dirk Behme595d37b2008-12-14 09:47:14 +0100104 sdelay(2000);
105}
106
107/*****************************************************
108 * gpmc_init(): init gpmc bus
109 * Init GPMC for x16, MuxMode (SDRAM in x32).
110 * This code can only be executed from SRAM or SDRAM.
111 *****************************************************/
112void gpmc_init(void)
113{
114 /* putting a blanket check on GPMC based on ZeBu for now */
Dirk Behmea4becd62009-08-08 09:30:22 +0200115 gpmc_cfg = (struct gpmc *)GPMC_BASE;
Nishanth Menonf95e4c92009-10-13 12:47:39 -0400116#if defined(CONFIG_CMD_NAND) || defined(CONFIG_CMD_ONENAND)
Nishanth Menon3d0377f2009-10-13 12:49:55 -0400117 const u32 *gpmc_config = NULL;
Dirk Behme595d37b2008-12-14 09:47:14 +0100118 u32 base = 0;
119 u32 size = 0;
Nishanth Menonf95e4c92009-10-13 12:47:39 -0400120#endif
Dirk Behme595d37b2008-12-14 09:47:14 +0100121 u32 config = 0;
122
123 /* global settings */
Dirk Behmea4becd62009-08-08 09:30:22 +0200124 writel(0, &gpmc_cfg->irqenable); /* isr's sources masked */
125 writel(0, &gpmc_cfg->timeout_control);/* timeout disable */
Dirk Behme595d37b2008-12-14 09:47:14 +0100126
Dirk Behmea4becd62009-08-08 09:30:22 +0200127 config = readl(&gpmc_cfg->config);
Dirk Behme595d37b2008-12-14 09:47:14 +0100128 config &= (~0xf00);
Dirk Behmea4becd62009-08-08 09:30:22 +0200129 writel(config, &gpmc_cfg->config);
Dirk Behme595d37b2008-12-14 09:47:14 +0100130
131 /*
132 * Disable the GPMC0 config set by ROM code
133 * It conflicts with our MPDB (both at 0x08000000)
134 */
Dirk Behmea4becd62009-08-08 09:30:22 +0200135 writel(0, &gpmc_cfg->cs[0].config7);
Dirk Behme595d37b2008-12-14 09:47:14 +0100136 sdelay(1000);
137
138#if defined(CONFIG_CMD_NAND) /* CS 0 */
139 gpmc_config = gpmc_m_nand;
Matthias Ludwige06da3d2009-05-19 09:09:31 +0200140
Dirk Behme595d37b2008-12-14 09:47:14 +0100141 base = PISMO1_NAND_BASE;
142 size = PISMO1_NAND_SIZE;
Dirk Behmea4becd62009-08-08 09:30:22 +0200143 enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size);
Dirk Behme595d37b2008-12-14 09:47:14 +0100144#endif
145
146#if defined(CONFIG_CMD_ONENAND)
147 gpmc_config = gpmc_onenand;
Dirk Behme595d37b2008-12-14 09:47:14 +0100148 base = PISMO1_ONEN_BASE;
149 size = PISMO1_ONEN_SIZE;
Dirk Behmea4becd62009-08-08 09:30:22 +0200150 enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size);
Dirk Behme595d37b2008-12-14 09:47:14 +0100151#endif
152}