Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 34 | /* |
| 35 | * Only One NAND allowed on board at a time. |
| 36 | * The GPMC CS Base for the same |
| 37 | */ |
| 38 | unsigned int boot_flash_base; |
| 39 | unsigned int boot_flash_off; |
| 40 | unsigned int boot_flash_sec; |
| 41 | unsigned int boot_flash_type; |
| 42 | volatile unsigned int boot_flash_env_addr; |
| 43 | |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 44 | struct gpmc *gpmc_cfg; |
| 45 | |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 46 | #if defined(CONFIG_CMD_NAND) |
Nishanth Menon | f8a812a | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 47 | static const u32 gpmc_m_nand[GPMC_MAX_REG] = { |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 48 | M_NAND_GPMC_CONFIG1, |
| 49 | M_NAND_GPMC_CONFIG2, |
| 50 | M_NAND_GPMC_CONFIG3, |
| 51 | M_NAND_GPMC_CONFIG4, |
| 52 | M_NAND_GPMC_CONFIG5, |
| 53 | M_NAND_GPMC_CONFIG6, 0 |
| 54 | }; |
| 55 | |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 56 | #if defined(CONFIG_ENV_IS_IN_NAND) |
| 57 | #define GPMC_CS 0 |
| 58 | #else |
| 59 | #define GPMC_CS 1 |
| 60 | #endif |
| 61 | |
| 62 | #endif |
| 63 | |
| 64 | #if defined(CONFIG_CMD_ONENAND) |
Nishanth Menon | f8a812a | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 65 | static const u32 gpmc_onenand[GPMC_MAX_REG] = { |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 66 | ONENAND_GPMC_CONFIG1, |
| 67 | ONENAND_GPMC_CONFIG2, |
| 68 | ONENAND_GPMC_CONFIG3, |
| 69 | ONENAND_GPMC_CONFIG4, |
| 70 | ONENAND_GPMC_CONFIG5, |
| 71 | ONENAND_GPMC_CONFIG6, 0 |
| 72 | }; |
| 73 | |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 74 | #if defined(CONFIG_ENV_IS_IN_ONENAND) |
| 75 | #define GPMC_CS 0 |
| 76 | #else |
| 77 | #define GPMC_CS 1 |
| 78 | #endif |
| 79 | |
| 80 | #endif |
| 81 | |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 82 | /******************************************************** |
| 83 | * mem_ok() - test used to see if timings are correct |
| 84 | * for a part. Helps in guessing which part |
| 85 | * we are currently using. |
| 86 | *******************************************************/ |
| 87 | u32 mem_ok(u32 cs) |
| 88 | { |
| 89 | u32 val1, val2, addr; |
| 90 | u32 pattern = 0x12345678; |
| 91 | |
| 92 | addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs); |
| 93 | |
| 94 | writel(0x0, addr + 0x400); /* clear pos A */ |
| 95 | writel(pattern, addr); /* pattern to pos B */ |
| 96 | writel(0x0, addr + 4); /* remove pattern off the bus */ |
| 97 | val1 = readl(addr + 0x400); /* get pos A value */ |
| 98 | val2 = readl(addr); /* get val2 */ |
| 99 | |
| 100 | if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */ |
| 101 | return 0; |
| 102 | else |
| 103 | return 1; |
| 104 | } |
| 105 | |
Nishanth Menon | f8a812a | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 106 | void enable_gpmc_cs_config(const u32 *gpmc_config, struct gpmc_cs *cs, u32 base, |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 107 | u32 size) |
| 108 | { |
Matthias Ludwig | 187af95 | 2009-05-19 09:09:31 +0200 | [diff] [blame] | 109 | writel(0, &cs->config7); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 110 | sdelay(1000); |
| 111 | /* Delay for settling */ |
Matthias Ludwig | 187af95 | 2009-05-19 09:09:31 +0200 | [diff] [blame] | 112 | writel(gpmc_config[0], &cs->config1); |
| 113 | writel(gpmc_config[1], &cs->config2); |
| 114 | writel(gpmc_config[2], &cs->config3); |
| 115 | writel(gpmc_config[3], &cs->config4); |
| 116 | writel(gpmc_config[4], &cs->config5); |
| 117 | writel(gpmc_config[5], &cs->config6); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 118 | /* Enable the config */ |
| 119 | writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) | |
Matthias Ludwig | 187af95 | 2009-05-19 09:09:31 +0200 | [diff] [blame] | 120 | (1 << 6)), &cs->config7); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 121 | sdelay(2000); |
| 122 | } |
| 123 | |
| 124 | /***************************************************** |
| 125 | * gpmc_init(): init gpmc bus |
| 126 | * Init GPMC for x16, MuxMode (SDRAM in x32). |
| 127 | * This code can only be executed from SRAM or SDRAM. |
| 128 | *****************************************************/ |
| 129 | void gpmc_init(void) |
| 130 | { |
| 131 | /* putting a blanket check on GPMC based on ZeBu for now */ |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 132 | gpmc_cfg = (struct gpmc *)GPMC_BASE; |
Nishanth Menon | 4e0539d | 2009-10-13 12:47:39 -0400 | [diff] [blame] | 133 | #if defined(CONFIG_CMD_NAND) || defined(CONFIG_CMD_ONENAND) |
Nishanth Menon | f8a812a | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 134 | const u32 *gpmc_config = NULL; |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 135 | u32 base = 0; |
| 136 | u32 size = 0; |
Nishanth Menon | 4e0539d | 2009-10-13 12:47:39 -0400 | [diff] [blame] | 137 | #if defined(CONFIG_ENV_IS_IN_NAND) || defined(CONFIG_ENV_IS_IN_ONENAND) |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 138 | u32 f_off = CONFIG_SYS_MONITOR_LEN; |
| 139 | u32 f_sec = 0; |
Nishanth Menon | 4e0539d | 2009-10-13 12:47:39 -0400 | [diff] [blame] | 140 | #endif |
| 141 | #endif |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 142 | u32 config = 0; |
| 143 | |
| 144 | /* global settings */ |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 145 | writel(0, &gpmc_cfg->irqenable); /* isr's sources masked */ |
| 146 | writel(0, &gpmc_cfg->timeout_control);/* timeout disable */ |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 147 | |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 148 | config = readl(&gpmc_cfg->config); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 149 | config &= (~0xf00); |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 150 | writel(config, &gpmc_cfg->config); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * Disable the GPMC0 config set by ROM code |
| 154 | * It conflicts with our MPDB (both at 0x08000000) |
| 155 | */ |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 156 | writel(0, &gpmc_cfg->cs[0].config7); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 157 | sdelay(1000); |
| 158 | |
| 159 | #if defined(CONFIG_CMD_NAND) /* CS 0 */ |
| 160 | gpmc_config = gpmc_m_nand; |
Matthias Ludwig | 187af95 | 2009-05-19 09:09:31 +0200 | [diff] [blame] | 161 | |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 162 | base = PISMO1_NAND_BASE; |
| 163 | size = PISMO1_NAND_SIZE; |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 164 | enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 165 | #if defined(CONFIG_ENV_IS_IN_NAND) |
| 166 | f_off = SMNAND_ENV_OFFSET; |
Sandeep Paulraj | 9c44ddc | 2009-09-09 11:50:40 -0400 | [diff] [blame] | 167 | f_sec = (128 << 10); /* 128 KiB */ |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 168 | /* env setup */ |
| 169 | boot_flash_base = base; |
| 170 | boot_flash_off = f_off; |
| 171 | boot_flash_sec = f_sec; |
| 172 | boot_flash_env_addr = f_off; |
| 173 | #endif |
| 174 | #endif |
| 175 | |
| 176 | #if defined(CONFIG_CMD_ONENAND) |
| 177 | gpmc_config = gpmc_onenand; |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 178 | base = PISMO1_ONEN_BASE; |
| 179 | size = PISMO1_ONEN_SIZE; |
Dirk Behme | 8941135 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 180 | enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size); |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 181 | #if defined(CONFIG_ENV_IS_IN_ONENAND) |
| 182 | f_off = ONENAND_ENV_OFFSET; |
Sandeep Paulraj | 9c44ddc | 2009-09-09 11:50:40 -0400 | [diff] [blame] | 183 | f_sec = (128 << 10); /* 128 KiB */ |
Dirk Behme | 5ed3e86 | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 184 | /* env setup */ |
| 185 | boot_flash_base = base; |
| 186 | boot_flash_off = f_off; |
| 187 | boot_flash_sec = f_sec; |
| 188 | boot_flash_env_addr = f_off; |
| 189 | #endif |
| 190 | #endif |
| 191 | } |