Vaibhav Hiremath | 598f702 | 2010-06-07 15:20:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Author : |
| 3 | * Vaibhav Hiremath <hvaibhav@ti.com> |
| 4 | * |
| 5 | * Based on mem.c and sdrc.c |
| 6 | * |
| 7 | * Copyright (C) 2010 |
| 8 | * Texas Instruments Incorporated - http://www.ti.com/ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <asm/arch/mem.h> |
| 29 | #include <asm/arch/sys_proto.h> |
| 30 | #include <asm/arch/emif4.h> |
| 31 | |
Nishanth Menon | edded0e4 | 2010-12-11 11:41:42 -0500 | [diff] [blame^] | 32 | DECLARE_GLOBAL_DATA_PTR; |
Vaibhav Hiremath | 598f702 | 2010-06-07 15:20:53 -0400 | [diff] [blame] | 33 | extern omap3_sysinfo sysinfo; |
| 34 | |
| 35 | static emif4_t *emif4_base = (emif4_t *)OMAP34XX_SDRC_BASE; |
| 36 | |
| 37 | /* |
| 38 | * is_mem_sdr - |
| 39 | * - Return 1 if mem type in use is SDR |
| 40 | */ |
| 41 | u32 is_mem_sdr(void) |
| 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * get_sdr_cs_size - |
| 48 | * - Get size of chip select 0/1 |
| 49 | */ |
| 50 | u32 get_sdr_cs_size(u32 cs) |
| 51 | { |
Vaibhav Hiremath | 8313946 | 2010-11-29 16:36:10 -0500 | [diff] [blame] | 52 | u32 size = 0; |
Vaibhav Hiremath | 598f702 | 2010-06-07 15:20:53 -0400 | [diff] [blame] | 53 | |
| 54 | /* TODO: Calculate the size based on EMIF4 configuration */ |
Vaibhav Hiremath | 8313946 | 2010-11-29 16:36:10 -0500 | [diff] [blame] | 55 | if (cs == CS0) |
| 56 | size = CONFIG_SYS_CS0_SIZE; |
Vaibhav Hiremath | 598f702 | 2010-06-07 15:20:53 -0400 | [diff] [blame] | 57 | |
| 58 | return size; |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | * get_sdr_cs_offset - |
| 63 | * - Get offset of cs from cs0 start |
| 64 | */ |
| 65 | u32 get_sdr_cs_offset(u32 cs) |
| 66 | { |
| 67 | u32 offset = 0; |
| 68 | |
| 69 | return offset; |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * do_emif4_init - |
| 74 | * - Init the emif4 module for DDR access |
| 75 | * - Early init routines, called from flash or SRAM. |
| 76 | */ |
| 77 | void do_emif4_init(void) |
| 78 | { |
| 79 | unsigned int regval; |
| 80 | /* Set the DDR PHY parameters in PHY ctrl registers */ |
| 81 | regval = (EMIF4_DDR1_READ_LAT | EMIF4_DDR1_PWRDN_DIS | |
| 82 | EMIF4_DDR1_EXT_STRB_DIS); |
| 83 | writel(regval, &emif4_base->ddr_phyctrl1); |
| 84 | writel(regval, &emif4_base->ddr_phyctrl1_shdw); |
| 85 | writel(0, &emif4_base->ddr_phyctrl2); |
| 86 | |
| 87 | /* Reset the DDR PHY and wait till completed */ |
| 88 | regval = readl(&emif4_base->sdram_iodft_tlgc); |
| 89 | regval |= (1<<10); |
| 90 | writel(regval, &emif4_base->sdram_iodft_tlgc); |
| 91 | /*Wait till that bit clears*/ |
| 92 | while ((readl(&emif4_base->sdram_iodft_tlgc) & (1<<10)) == 0x1); |
| 93 | /*Re-verify the DDR PHY status*/ |
| 94 | while ((readl(&emif4_base->sdram_sts) & (1<<2)) == 0x0); |
| 95 | |
| 96 | regval |= (1<<0); |
| 97 | writel(regval, &emif4_base->sdram_iodft_tlgc); |
| 98 | /* Set SDR timing registers */ |
| 99 | regval = (EMIF4_TIM1_T_WTR | EMIF4_TIM1_T_RRD | |
| 100 | EMIF4_TIM1_T_RC | EMIF4_TIM1_T_RAS | |
| 101 | EMIF4_TIM1_T_WR | EMIF4_TIM1_T_RCD | |
| 102 | EMIF4_TIM1_T_RP); |
| 103 | writel(regval, &emif4_base->sdram_time1); |
| 104 | writel(regval, &emif4_base->sdram_time1_shdw); |
| 105 | |
| 106 | regval = (EMIF4_TIM2_T_CKE | EMIF4_TIM2_T_RTP | |
| 107 | EMIF4_TIM2_T_XSRD | EMIF4_TIM2_T_XSNR | |
| 108 | EMIF4_TIM2_T_ODT | EMIF4_TIM2_T_XP); |
| 109 | writel(regval, &emif4_base->sdram_time2); |
| 110 | writel(regval, &emif4_base->sdram_time2_shdw); |
| 111 | |
| 112 | regval = (EMIF4_TIM3_T_RAS_MAX | EMIF4_TIM3_T_RFC); |
| 113 | writel(regval, &emif4_base->sdram_time3); |
| 114 | writel(regval, &emif4_base->sdram_time3_shdw); |
| 115 | |
| 116 | /* Set the PWR control register */ |
| 117 | regval = (EMIF4_PWR_PM_TIM | EMIF4_PWR_LP_MODE | |
| 118 | EMIF4_PWR_DPD_DIS | EMIF4_PWR_IDLE_MODE); |
| 119 | writel(regval, &emif4_base->sdram_pwr_mgmt); |
| 120 | writel(regval, &emif4_base->sdram_pwr_mgmt_shdw); |
| 121 | |
| 122 | /* Set the DDR refresh rate control register */ |
| 123 | regval = (EMIF4_REFRESH_RATE | EMIF4_INITREF_DIS); |
| 124 | writel(regval, &emif4_base->sdram_refresh_ctrl); |
| 125 | writel(regval, &emif4_base->sdram_refresh_ctrl_shdw); |
| 126 | |
| 127 | /* set the SDRAM configuration register */ |
| 128 | regval = (EMIF4_CFG_PGSIZE | EMIF4_CFG_EBANK | |
| 129 | EMIF4_CFG_IBANK | EMIF4_CFG_ROWSIZE | |
| 130 | EMIF4_CFG_CL | EMIF4_CFG_NARROW_MD | |
| 131 | EMIF4_CFG_SDR_DRV | EMIF4_CFG_DDR_DIS_DLL | |
| 132 | EMIF4_CFG_DDR2_DDQS | EMIF4_CFG_DDR_TERM | |
| 133 | EMIF4_CFG_IBANK_POS | EMIF4_CFG_SDRAM_TYP); |
| 134 | writel(regval, &emif4_base->sdram_config); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * dram_init - |
| 139 | * - Sets uboots idea of sdram size |
| 140 | */ |
| 141 | int dram_init(void) |
| 142 | { |
Vaibhav Hiremath | 598f702 | 2010-06-07 15:20:53 -0400 | [diff] [blame] | 143 | unsigned int size0 = 0, size1 = 0; |
| 144 | |
| 145 | size0 = get_sdr_cs_size(CS0); |
| 146 | /* |
| 147 | * If a second bank of DDR is attached to CS1 this is |
| 148 | * where it can be started. Early init code will init |
| 149 | * memory on CS0. |
| 150 | */ |
| 151 | if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED)) |
| 152 | size1 = get_sdr_cs_size(CS1); |
| 153 | |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 154 | gd->ram_size = size0 + size1; |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | void dram_init_banksize (void) |
| 159 | { |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 160 | unsigned int size0 = 0, size1 = 0; |
| 161 | |
| 162 | size0 = get_sdr_cs_size(CS0); |
| 163 | size1 = get_sdr_cs_size(CS1); |
| 164 | |
| 165 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 166 | gd->bd->bi_dram[0].size = size0; |
| 167 | gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1); |
| 168 | gd->bd->bi_dram[1].size = size1; |
| 169 | } |
Vaibhav Hiremath | 598f702 | 2010-06-07 15:20:53 -0400 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * mem_init() - |
| 173 | * - Initialize memory subsystem |
| 174 | */ |
| 175 | void mem_init(void) |
| 176 | { |
| 177 | do_emif4_init(); |
| 178 | } |