blob: 1832affa5bbb2959a64f794d22bf6468b0ecbcf6 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Dirk Behme595d37b2008-12-14 09:47:14 +010013 */
14
15#include <common.h>
16#include <asm/io.h>
17#include <asm/arch/mem.h>
18#include <asm/arch/sys_proto.h>
19#include <command.h>
20
Dirk Behmea4becd62009-08-08 09:30:22 +020021struct gpmc *gpmc_cfg;
22
Dirk Behme595d37b2008-12-14 09:47:14 +010023#if defined(CONFIG_CMD_NAND)
Nishanth Menon3d0377f2009-10-13 12:49:55 -040024static const u32 gpmc_m_nand[GPMC_MAX_REG] = {
Dirk Behme595d37b2008-12-14 09:47:14 +010025 M_NAND_GPMC_CONFIG1,
26 M_NAND_GPMC_CONFIG2,
27 M_NAND_GPMC_CONFIG3,
28 M_NAND_GPMC_CONFIG4,
29 M_NAND_GPMC_CONFIG5,
30 M_NAND_GPMC_CONFIG6, 0
31};
Robert P. J. Day3bb3c292012-11-13 07:57:54 +000032#endif /* CONFIG_CMD_NAND */
Dirk Behme595d37b2008-12-14 09:47:14 +010033
34#if defined(CONFIG_CMD_ONENAND)
Nishanth Menon3d0377f2009-10-13 12:49:55 -040035static const u32 gpmc_onenand[GPMC_MAX_REG] = {
Dirk Behme595d37b2008-12-14 09:47:14 +010036 ONENAND_GPMC_CONFIG1,
37 ONENAND_GPMC_CONFIG2,
38 ONENAND_GPMC_CONFIG3,
39 ONENAND_GPMC_CONFIG4,
40 ONENAND_GPMC_CONFIG5,
41 ONENAND_GPMC_CONFIG6, 0
42};
Robert P. J. Day3bb3c292012-11-13 07:57:54 +000043#endif /* CONFIG_CMD_ONENAND */
Dirk Behme595d37b2008-12-14 09:47:14 +010044
Dirk Behme595d37b2008-12-14 09:47:14 +010045/********************************************************
46 * mem_ok() - test used to see if timings are correct
47 * for a part. Helps in guessing which part
48 * we are currently using.
49 *******************************************************/
50u32 mem_ok(u32 cs)
51{
52 u32 val1, val2, addr;
53 u32 pattern = 0x12345678;
54
55 addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
56
57 writel(0x0, addr + 0x400); /* clear pos A */
58 writel(pattern, addr); /* pattern to pos B */
59 writel(0x0, addr + 4); /* remove pattern off the bus */
60 val1 = readl(addr + 0x400); /* get pos A value */
61 val2 = readl(addr); /* get val2 */
Tom Rinic8a003a2011-11-18 12:48:01 +000062 writel(0x0, addr + 0x400); /* clear pos A */
Dirk Behme595d37b2008-12-14 09:47:14 +010063
64 if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
65 return 0;
66 else
67 return 1;
68}
69
Nishanth Menon3d0377f2009-10-13 12:49:55 -040070void enable_gpmc_cs_config(const u32 *gpmc_config, struct gpmc_cs *cs, u32 base,
Dirk Behme595d37b2008-12-14 09:47:14 +010071 u32 size)
72{
Matthias Ludwige06da3d2009-05-19 09:09:31 +020073 writel(0, &cs->config7);
Dirk Behme595d37b2008-12-14 09:47:14 +010074 sdelay(1000);
75 /* Delay for settling */
Matthias Ludwige06da3d2009-05-19 09:09:31 +020076 writel(gpmc_config[0], &cs->config1);
77 writel(gpmc_config[1], &cs->config2);
78 writel(gpmc_config[2], &cs->config3);
79 writel(gpmc_config[3], &cs->config4);
80 writel(gpmc_config[4], &cs->config5);
81 writel(gpmc_config[5], &cs->config6);
Tom Rini51b2be52011-11-18 12:47:58 +000082
83 /*
84 * Enable the config. size is the CS size and goes in
85 * bits 11:8. We set bit 6 to enable this CS and the base
86 * address goes into bits 5:0.
87 */
88 writel((size << 8) | (GPMC_CS_ENABLE << 6) |
89 ((base >> 24) & GPMC_BASEADDR_MASK),
90 &cs->config7);
Dirk Behme595d37b2008-12-14 09:47:14 +010091 sdelay(2000);
92}
93
94/*****************************************************
95 * gpmc_init(): init gpmc bus
96 * Init GPMC for x16, MuxMode (SDRAM in x32).
97 * This code can only be executed from SRAM or SDRAM.
98 *****************************************************/
99void gpmc_init(void)
100{
101 /* putting a blanket check on GPMC based on ZeBu for now */
Dirk Behmea4becd62009-08-08 09:30:22 +0200102 gpmc_cfg = (struct gpmc *)GPMC_BASE;
Nishanth Menonf95e4c92009-10-13 12:47:39 -0400103#if defined(CONFIG_CMD_NAND) || defined(CONFIG_CMD_ONENAND)
Nishanth Menon3d0377f2009-10-13 12:49:55 -0400104 const u32 *gpmc_config = NULL;
Dirk Behme595d37b2008-12-14 09:47:14 +0100105 u32 base = 0;
106 u32 size = 0;
Nishanth Menonf95e4c92009-10-13 12:47:39 -0400107#endif
Dirk Behme595d37b2008-12-14 09:47:14 +0100108 u32 config = 0;
109
110 /* global settings */
Dirk Behmea4becd62009-08-08 09:30:22 +0200111 writel(0, &gpmc_cfg->irqenable); /* isr's sources masked */
112 writel(0, &gpmc_cfg->timeout_control);/* timeout disable */
Dirk Behme595d37b2008-12-14 09:47:14 +0100113
Dirk Behmea4becd62009-08-08 09:30:22 +0200114 config = readl(&gpmc_cfg->config);
Dirk Behme595d37b2008-12-14 09:47:14 +0100115 config &= (~0xf00);
Dirk Behmea4becd62009-08-08 09:30:22 +0200116 writel(config, &gpmc_cfg->config);
Dirk Behme595d37b2008-12-14 09:47:14 +0100117
118 /*
119 * Disable the GPMC0 config set by ROM code
120 * It conflicts with our MPDB (both at 0x08000000)
121 */
Dirk Behmea4becd62009-08-08 09:30:22 +0200122 writel(0, &gpmc_cfg->cs[0].config7);
Dirk Behme595d37b2008-12-14 09:47:14 +0100123 sdelay(1000);
124
125#if defined(CONFIG_CMD_NAND) /* CS 0 */
126 gpmc_config = gpmc_m_nand;
Matthias Ludwige06da3d2009-05-19 09:09:31 +0200127
Dirk Behme595d37b2008-12-14 09:47:14 +0100128 base = PISMO1_NAND_BASE;
129 size = PISMO1_NAND_SIZE;
Dirk Behmea4becd62009-08-08 09:30:22 +0200130 enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size);
Dirk Behme595d37b2008-12-14 09:47:14 +0100131#endif
132
133#if defined(CONFIG_CMD_ONENAND)
134 gpmc_config = gpmc_onenand;
Dirk Behme595d37b2008-12-14 09:47:14 +0100135 base = PISMO1_ONEN_BASE;
136 size = PISMO1_ONEN_SIZE;
Dirk Behmea4becd62009-08-08 09:30:22 +0200137 enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size);
Dirk Behme595d37b2008-12-14 09:47:14 +0100138#endif
139}