Dirk Behme | 595d37b | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 12 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 13 | */ |
| 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 Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 21 | struct gpmc *gpmc_cfg; |
| 22 | |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 23 | #if defined(CONFIG_CMD_NAND) |
Stefan Roese | df3d222 | 2013-06-14 10:55:00 +0200 | [diff] [blame] | 24 | #if defined(GPMC_NAND_ECC_SP_x8_LAYOUT) || defined(GPMC_NAND_ECC_LP_x8_LAYOUT) |
| 25 | static const u32 gpmc_m_nand[GPMC_MAX_REG] = { |
| 26 | SMNAND_GPMC_CONFIG1, |
| 27 | SMNAND_GPMC_CONFIG2, |
| 28 | SMNAND_GPMC_CONFIG3, |
| 29 | SMNAND_GPMC_CONFIG4, |
| 30 | SMNAND_GPMC_CONFIG5, |
| 31 | SMNAND_GPMC_CONFIG6, |
| 32 | 0, |
| 33 | }; |
| 34 | #else |
Nishanth Menon | 3d0377f | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 35 | static const u32 gpmc_m_nand[GPMC_MAX_REG] = { |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 36 | M_NAND_GPMC_CONFIG1, |
| 37 | M_NAND_GPMC_CONFIG2, |
| 38 | M_NAND_GPMC_CONFIG3, |
| 39 | M_NAND_GPMC_CONFIG4, |
| 40 | M_NAND_GPMC_CONFIG5, |
| 41 | M_NAND_GPMC_CONFIG6, 0 |
| 42 | }; |
Stefan Roese | df3d222 | 2013-06-14 10:55:00 +0200 | [diff] [blame] | 43 | #endif |
Robert P. J. Day | 3bb3c29 | 2012-11-13 07:57:54 +0000 | [diff] [blame] | 44 | #endif /* CONFIG_CMD_NAND */ |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 45 | |
| 46 | #if defined(CONFIG_CMD_ONENAND) |
Nishanth Menon | 3d0377f | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 47 | static const u32 gpmc_onenand[GPMC_MAX_REG] = { |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 48 | ONENAND_GPMC_CONFIG1, |
| 49 | ONENAND_GPMC_CONFIG2, |
| 50 | ONENAND_GPMC_CONFIG3, |
| 51 | ONENAND_GPMC_CONFIG4, |
| 52 | ONENAND_GPMC_CONFIG5, |
| 53 | ONENAND_GPMC_CONFIG6, 0 |
| 54 | }; |
Robert P. J. Day | 3bb3c29 | 2012-11-13 07:57:54 +0000 | [diff] [blame] | 55 | #endif /* CONFIG_CMD_ONENAND */ |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 56 | |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 57 | /******************************************************** |
| 58 | * mem_ok() - test used to see if timings are correct |
| 59 | * for a part. Helps in guessing which part |
| 60 | * we are currently using. |
| 61 | *******************************************************/ |
| 62 | u32 mem_ok(u32 cs) |
| 63 | { |
| 64 | u32 val1, val2, addr; |
| 65 | u32 pattern = 0x12345678; |
| 66 | |
| 67 | addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs); |
| 68 | |
| 69 | writel(0x0, addr + 0x400); /* clear pos A */ |
| 70 | writel(pattern, addr); /* pattern to pos B */ |
| 71 | writel(0x0, addr + 4); /* remove pattern off the bus */ |
| 72 | val1 = readl(addr + 0x400); /* get pos A value */ |
| 73 | val2 = readl(addr); /* get val2 */ |
Tom Rini | c8a003a | 2011-11-18 12:48:01 +0000 | [diff] [blame] | 74 | writel(0x0, addr + 0x400); /* clear pos A */ |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 75 | |
| 76 | if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */ |
| 77 | return 0; |
| 78 | else |
| 79 | return 1; |
| 80 | } |
| 81 | |
Nishanth Menon | 3d0377f | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 82 | void enable_gpmc_cs_config(const u32 *gpmc_config, struct gpmc_cs *cs, u32 base, |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 83 | u32 size) |
| 84 | { |
Matthias Ludwig | e06da3d | 2009-05-19 09:09:31 +0200 | [diff] [blame] | 85 | writel(0, &cs->config7); |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 86 | sdelay(1000); |
| 87 | /* Delay for settling */ |
Matthias Ludwig | e06da3d | 2009-05-19 09:09:31 +0200 | [diff] [blame] | 88 | writel(gpmc_config[0], &cs->config1); |
| 89 | writel(gpmc_config[1], &cs->config2); |
| 90 | writel(gpmc_config[2], &cs->config3); |
| 91 | writel(gpmc_config[3], &cs->config4); |
| 92 | writel(gpmc_config[4], &cs->config5); |
| 93 | writel(gpmc_config[5], &cs->config6); |
Tom Rini | 51b2be5 | 2011-11-18 12:47:58 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Enable the config. size is the CS size and goes in |
| 97 | * bits 11:8. We set bit 6 to enable this CS and the base |
| 98 | * address goes into bits 5:0. |
| 99 | */ |
| 100 | writel((size << 8) | (GPMC_CS_ENABLE << 6) | |
| 101 | ((base >> 24) & GPMC_BASEADDR_MASK), |
| 102 | &cs->config7); |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 103 | sdelay(2000); |
| 104 | } |
| 105 | |
| 106 | /***************************************************** |
| 107 | * gpmc_init(): init gpmc bus |
| 108 | * Init GPMC for x16, MuxMode (SDRAM in x32). |
| 109 | * This code can only be executed from SRAM or SDRAM. |
| 110 | *****************************************************/ |
| 111 | void gpmc_init(void) |
| 112 | { |
| 113 | /* putting a blanket check on GPMC based on ZeBu for now */ |
Dirk Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 114 | gpmc_cfg = (struct gpmc *)GPMC_BASE; |
Nishanth Menon | f95e4c9 | 2009-10-13 12:47:39 -0400 | [diff] [blame] | 115 | #if defined(CONFIG_CMD_NAND) || defined(CONFIG_CMD_ONENAND) |
Nishanth Menon | 3d0377f | 2009-10-13 12:49:55 -0400 | [diff] [blame] | 116 | const u32 *gpmc_config = NULL; |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 117 | u32 base = 0; |
| 118 | u32 size = 0; |
Nishanth Menon | f95e4c9 | 2009-10-13 12:47:39 -0400 | [diff] [blame] | 119 | #endif |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 120 | u32 config = 0; |
| 121 | |
| 122 | /* global settings */ |
Dirk Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 123 | writel(0, &gpmc_cfg->irqenable); /* isr's sources masked */ |
| 124 | writel(0, &gpmc_cfg->timeout_control);/* timeout disable */ |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 125 | |
Dirk Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 126 | config = readl(&gpmc_cfg->config); |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 127 | config &= (~0xf00); |
Dirk Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 128 | writel(config, &gpmc_cfg->config); |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * Disable the GPMC0 config set by ROM code |
| 132 | * It conflicts with our MPDB (both at 0x08000000) |
| 133 | */ |
Dirk Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 134 | writel(0, &gpmc_cfg->cs[0].config7); |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 135 | sdelay(1000); |
| 136 | |
| 137 | #if defined(CONFIG_CMD_NAND) /* CS 0 */ |
| 138 | gpmc_config = gpmc_m_nand; |
Matthias Ludwig | e06da3d | 2009-05-19 09:09:31 +0200 | [diff] [blame] | 139 | |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 140 | base = PISMO1_NAND_BASE; |
| 141 | size = PISMO1_NAND_SIZE; |
Dirk Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 142 | enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size); |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 143 | #endif |
| 144 | |
| 145 | #if defined(CONFIG_CMD_ONENAND) |
| 146 | gpmc_config = gpmc_onenand; |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 147 | base = PISMO1_ONEN_BASE; |
| 148 | size = PISMO1_ONEN_SIZE; |
Dirk Behme | a4becd6 | 2009-08-08 09:30:22 +0200 | [diff] [blame] | 149 | enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size); |
Dirk Behme | 595d37b | 2008-12-14 09:47:14 +0100 | [diff] [blame] | 150 | #endif |
| 151 | } |