Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Texas Instruments, <www.ti.com> |
| 4 | * |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 5 | * Author : |
| 6 | * Mansoor Ahamed <mansoor.ahamed@ti.com> |
| 7 | * |
| 8 | * Initial Code from: |
| 9 | * Manikandan Pillai <mani.pillai@ti.com> |
| 10 | * Richard Woodruff <r-woodruff2@ti.com> |
| 11 | * Syed Mohammed Khasim <khasim@ti.com> |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 12 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 13 | * SPDX-License-Identifier: GPL-2.0+ |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 14 | */ |
| 15 | |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 16 | #include <common.h> |
| 17 | #include <asm/io.h> |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 18 | #include <asm/arch/cpu.h> |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 19 | #include <asm/arch/mem.h> |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 20 | #include <asm/arch/sys_proto.h> |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 21 | #include <command.h> |
| 22 | #include <linux/mtd/omap_gpmc.h> |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 23 | |
Ladislav Michl | d5b1c27 | 2016-07-12 20:28:16 +0200 | [diff] [blame^] | 24 | const struct gpmc *gpmc_cfg = (struct gpmc *)GPMC_BASE; |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 25 | |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 26 | #if defined(CONFIG_OMAP34XX) |
| 27 | /******************************************************** |
| 28 | * mem_ok() - test used to see if timings are correct |
| 29 | * for a part. Helps in guessing which part |
| 30 | * we are currently using. |
| 31 | *******************************************************/ |
| 32 | u32 mem_ok(u32 cs) |
| 33 | { |
| 34 | u32 val1, val2, addr; |
| 35 | u32 pattern = 0x12345678; |
| 36 | |
| 37 | addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs); |
| 38 | |
| 39 | writel(0x0, addr + 0x400); /* clear pos A */ |
| 40 | writel(pattern, addr); /* pattern to pos B */ |
| 41 | writel(0x0, addr + 4); /* remove pattern off the bus */ |
| 42 | val1 = readl(addr + 0x400); /* get pos A value */ |
| 43 | val2 = readl(addr); /* get val2 */ |
| 44 | writel(0x0, addr + 0x400); /* clear pos A */ |
| 45 | |
| 46 | if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */ |
| 47 | return 0; |
| 48 | else |
| 49 | return 1; |
| 50 | } |
| 51 | #endif |
| 52 | |
Ladislav Michl | d5b1c27 | 2016-07-12 20:28:16 +0200 | [diff] [blame^] | 53 | void enable_gpmc_cs_config(const u32 *gpmc_config, const struct gpmc_cs *cs, |
| 54 | u32 base, u32 size) |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 55 | { |
| 56 | writel(0, &cs->config7); |
| 57 | sdelay(1000); |
| 58 | /* Delay for settling */ |
| 59 | writel(gpmc_config[0], &cs->config1); |
| 60 | writel(gpmc_config[1], &cs->config2); |
| 61 | writel(gpmc_config[2], &cs->config3); |
| 62 | writel(gpmc_config[3], &cs->config4); |
| 63 | writel(gpmc_config[4], &cs->config5); |
| 64 | writel(gpmc_config[5], &cs->config6); |
| 65 | /* Enable the config */ |
| 66 | writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) | |
| 67 | (1 << 6)), &cs->config7); |
| 68 | sdelay(2000); |
| 69 | } |
| 70 | |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 71 | /***************************************************** |
| 72 | * gpmc_init(): init gpmc bus |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 73 | * Init GPMC for x16, MuxMode (SDRAM in x32). |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 74 | * This code can only be executed from SRAM or SDRAM. |
| 75 | *****************************************************/ |
| 76 | void gpmc_init(void) |
| 77 | { |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 78 | #if defined(CONFIG_NOR) |
| 79 | /* configure GPMC for NOR */ |
| 80 | const u32 gpmc_regs[GPMC_MAX_REG] = { STNOR_GPMC_CONFIG1, |
| 81 | STNOR_GPMC_CONFIG2, |
| 82 | STNOR_GPMC_CONFIG3, |
| 83 | STNOR_GPMC_CONFIG4, |
| 84 | STNOR_GPMC_CONFIG5, |
| 85 | STNOR_GPMC_CONFIG6, |
| 86 | STNOR_GPMC_CONFIG7 |
| 87 | }; |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 88 | u32 base = CONFIG_SYS_FLASH_BASE; |
pekon gupta | 72b3479 | 2014-07-18 17:59:40 +0530 | [diff] [blame] | 89 | u32 size = (CONFIG_SYS_FLASH_SIZE > 0x08000000) ? GPMC_SIZE_256M : |
| 90 | /* > 64MB */ ((CONFIG_SYS_FLASH_SIZE > 0x04000000) ? GPMC_SIZE_128M : |
| 91 | /* > 32MB */ ((CONFIG_SYS_FLASH_SIZE > 0x02000000) ? GPMC_SIZE_64M : |
| 92 | /* > 16MB */ ((CONFIG_SYS_FLASH_SIZE > 0x01000000) ? GPMC_SIZE_32M : |
| 93 | /* min 16MB */ GPMC_SIZE_16M))); |
Stefan Roese | 6999999 | 2014-07-09 17:18:09 +0200 | [diff] [blame] | 94 | #elif defined(CONFIG_NAND) || defined(CONFIG_CMD_NAND) |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 95 | /* configure GPMC for NAND */ |
| 96 | const u32 gpmc_regs[GPMC_MAX_REG] = { M_NAND_GPMC_CONFIG1, |
| 97 | M_NAND_GPMC_CONFIG2, |
| 98 | M_NAND_GPMC_CONFIG3, |
| 99 | M_NAND_GPMC_CONFIG4, |
| 100 | M_NAND_GPMC_CONFIG5, |
| 101 | M_NAND_GPMC_CONFIG6, |
| 102 | 0 |
| 103 | }; |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 104 | u32 base = CONFIG_SYS_NAND_BASE; |
pekon gupta | 72b3479 | 2014-07-18 17:59:40 +0530 | [diff] [blame] | 105 | u32 size = GPMC_SIZE_16M; |
| 106 | |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 107 | #elif defined(CONFIG_CMD_ONENAND) |
| 108 | const u32 gpmc_regs[GPMC_MAX_REG] = { ONENAND_GPMC_CONFIG1, |
| 109 | ONENAND_GPMC_CONFIG2, |
| 110 | ONENAND_GPMC_CONFIG3, |
| 111 | ONENAND_GPMC_CONFIG4, |
| 112 | ONENAND_GPMC_CONFIG5, |
| 113 | ONENAND_GPMC_CONFIG6, |
| 114 | 0 |
| 115 | }; |
pekon gupta | 0a9ec45 | 2014-07-18 17:59:41 +0530 | [diff] [blame] | 116 | u32 size = GPMC_SIZE_128M; |
| 117 | u32 base = CONFIG_SYS_ONENAND_BASE; |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 118 | #else |
| 119 | const u32 gpmc_regs[GPMC_MAX_REG] = { 0, 0, 0, 0, 0, 0, 0 }; |
| 120 | u32 size = 0; |
| 121 | u32 base = 0; |
| 122 | #endif |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 123 | /* global settings */ |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 124 | writel(0x00000008, &gpmc_cfg->sysconfig); |
| 125 | writel(0x00000000, &gpmc_cfg->irqstatus); |
| 126 | writel(0x00000000, &gpmc_cfg->irqenable); |
Stefano Babic | 18db567 | 2014-06-17 16:47:40 +0200 | [diff] [blame] | 127 | /* disable timeout, set a safe reset value */ |
| 128 | writel(0x00001ff0, &gpmc_cfg->timeout_control); |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 129 | #ifdef CONFIG_NOR |
| 130 | writel(0x00000200, &gpmc_cfg->config); |
| 131 | #else |
| 132 | writel(0x00000012, &gpmc_cfg->config); |
| 133 | #endif |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 134 | /* |
| 135 | * Disable the GPMC0 config set by ROM code |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 136 | */ |
| 137 | writel(0, &gpmc_cfg->cs[0].config7); |
pekon gupta | 48e1e15 | 2014-05-08 21:43:47 +0530 | [diff] [blame] | 138 | sdelay(1000); |
| 139 | /* enable chip-select specific configurations */ |
Ash Charles | 123ce9d | 2014-06-06 11:27:28 -0700 | [diff] [blame] | 140 | if (base != 0) |
| 141 | enable_gpmc_cs_config(gpmc_regs, &gpmc_cfg->cs[0], base, size); |
Steve Sakoman | 9b8ea4e | 2010-07-15 16:19:16 -0400 | [diff] [blame] | 142 | } |