Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * Version 2 as published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/fsl_ddr_sdram.h> |
| 11 | |
| 12 | #include "ddr.h" |
| 13 | |
| 14 | /* Board-specific functions defined in each board's ddr.c */ |
| 15 | extern void fsl_ddr_board_options(memctl_options_t *popts, |
| 16 | unsigned int ctrl_num); |
| 17 | |
| 18 | unsigned int populate_memctl_options(int all_DIMMs_registered, |
| 19 | memctl_options_t *popts, |
| 20 | unsigned int ctrl_num) |
| 21 | { |
| 22 | unsigned int i; |
| 23 | |
| 24 | /* Chip select options. */ |
| 25 | |
| 26 | /* Pick chip-select local options. */ |
| 27 | for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) { |
| 28 | /* If not DDR2, odt_rd_cfg and odt_wr_cfg need to be 0. */ |
| 29 | |
| 30 | /* only for single CS? */ |
| 31 | popts->cs_local_opts[i].odt_rd_cfg = 0; |
| 32 | |
| 33 | popts->cs_local_opts[i].odt_wr_cfg = 1; |
| 34 | popts->cs_local_opts[i].auto_precharge = 0; |
| 35 | } |
| 36 | |
| 37 | /* Pick interleaving mode. */ |
| 38 | |
| 39 | /* |
| 40 | * 0 = no interleaving |
| 41 | * 1 = interleaving between 2 controllers |
| 42 | */ |
| 43 | popts->memctl_interleaving = 0; |
| 44 | |
| 45 | /* |
| 46 | * 0 = cacheline |
| 47 | * 1 = page |
| 48 | * 2 = (logical) bank |
| 49 | * 3 = superbank (only if CS interleaving is enabled) |
| 50 | */ |
| 51 | popts->memctl_interleaving_mode = 0; |
| 52 | |
| 53 | /* |
| 54 | * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl |
| 55 | * 1: page: bit to the left of the column bits selects the memctl |
| 56 | * 2: bank: bit to the left of the bank bits selects the memctl |
| 57 | * 3: superbank: bit to the left of the chip select selects the memctl |
| 58 | * |
| 59 | * NOTE: ba_intlv (rank interleaving) is independent of memory |
| 60 | * controller interleaving; it is only within a memory controller. |
| 61 | * Must use superbank interleaving if rank interleaving is used and |
| 62 | * memory controller interleaving is enabled. |
| 63 | */ |
| 64 | |
| 65 | /* |
| 66 | * 0 = no |
| 67 | * 0x40 = CS0,CS1 |
| 68 | * 0x20 = CS2,CS3 |
| 69 | * 0x60 = CS0,CS1 + CS2,CS3 |
| 70 | * 0x04 = CS0,CS1,CS2,CS3 |
| 71 | */ |
| 72 | popts->ba_intlv_ctl = 0; |
| 73 | |
| 74 | /* Memory Organization Parameters */ |
| 75 | popts->registered_dimm_en = all_DIMMs_registered; |
| 76 | |
| 77 | /* Operational Mode Paramters */ |
| 78 | |
| 79 | /* Pick ECC modes */ |
| 80 | #ifdef CONFIG_DDR_ECC |
| 81 | popts->ECC_mode = 1; /* 0 = disabled, 1 = enabled */ |
| 82 | #else |
| 83 | popts->ECC_mode = 0; /* 0 = disabled, 1 = enabled */ |
| 84 | #endif |
| 85 | popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */ |
| 86 | |
| 87 | /* |
| 88 | * Choose DQS config |
| 89 | * 0 for DDR1 |
| 90 | * 1 for DDR2 |
| 91 | */ |
| 92 | #if defined(CONFIG_FSL_DDR1) |
| 93 | popts->DQS_config = 0; |
| 94 | #elif defined(CONFIG_FSL_DDR2) |
| 95 | popts->DQS_config = 1; |
| 96 | #else |
| 97 | #error "Fix DQS for DDR3" |
| 98 | #endif |
| 99 | |
| 100 | /* Choose self-refresh during sleep. */ |
| 101 | popts->self_refresh_in_sleep = 1; |
| 102 | |
| 103 | /* Choose dynamic power management mode. */ |
| 104 | popts->dynamic_power = 0; |
| 105 | |
| 106 | /* 0 = 64-bit, 1 = 32-bit, 2 = 16-bit */ |
| 107 | popts->data_bus_width = 0; |
| 108 | |
| 109 | /* Choose burst length. */ |
| 110 | popts->burst_length = 4; /* has to be 4 for DDR2 */ |
| 111 | |
| 112 | /* Global Timing Parameters. */ |
| 113 | debug("mclk_ps = %u ps\n", get_memory_clk_period_ps()); |
| 114 | |
| 115 | /* Pick a caslat override. */ |
| 116 | popts->cas_latency_override = 0; |
| 117 | popts->cas_latency_override_value = 3; |
| 118 | if (popts->cas_latency_override) { |
| 119 | debug("using caslat override value = %u\n", |
| 120 | popts->cas_latency_override_value); |
| 121 | } |
| 122 | |
| 123 | /* Decide whether to use the computed derated latency */ |
| 124 | popts->use_derated_caslat = 0; |
| 125 | |
| 126 | /* Choose an additive latency. */ |
| 127 | popts->additive_latency_override = 0; |
| 128 | popts->additive_latency_override_value = 3; |
| 129 | if (popts->additive_latency_override) { |
| 130 | debug("using additive latency override value = %u\n", |
| 131 | popts->additive_latency_override_value); |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * 2T_EN setting |
| 136 | * |
| 137 | * Factors to consider for 2T_EN: |
| 138 | * - number of DIMMs installed |
| 139 | * - number of components, number of active ranks |
| 140 | * - how much time you want to spend playing around |
| 141 | */ |
| 142 | popts->twoT_en = 1; |
| 143 | popts->threeT_en = 0; |
| 144 | |
| 145 | /* |
| 146 | * BSTTOPRE precharge interval |
| 147 | * |
| 148 | * Set this to 0 for global auto precharge |
| 149 | * |
| 150 | * FIXME: Should this be configured in picoseconds? |
| 151 | * Why it should be in ps: better understanding of this |
| 152 | * relative to actual DRAM timing parameters such as tRAS. |
| 153 | * e.g. tRAS(min) = 40 ns |
| 154 | */ |
| 155 | popts->bstopre = 0x100; |
| 156 | |
| 157 | /* Minimum CKE pulse width -- tCKE(MIN) */ |
| 158 | popts->tCKE_clock_pulse_width_ps |
| 159 | = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR); |
| 160 | |
| 161 | /* |
| 162 | * Window for four activates -- tFAW |
| 163 | * |
| 164 | * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only |
| 165 | * FIXME: varies depending upon number of column addresses or data |
| 166 | * FIXME: width, was considering looking at pdimm->primary_sdram_width |
| 167 | */ |
| 168 | #if defined(CONFIG_FSL_DDR1) |
| 169 | popts->tFAW_window_four_activates_ps = mclk_to_picos(1); |
| 170 | |
| 171 | #elif defined(CONFIG_FSL_DDR2) |
| 172 | /* |
| 173 | * x4/x8; some datasheets have 35000 |
| 174 | * x16 wide columns only? Use 50000? |
| 175 | */ |
| 176 | popts->tFAW_window_four_activates_ps = 37500; |
| 177 | |
| 178 | #elif defined(CONFIG_FSL_DDR3) |
| 179 | #error "FIXME determine four activates for DDR3" |
| 180 | #endif |
| 181 | |
| 182 | /* ODT should only be used for DDR2 */ |
| 183 | |
| 184 | /* FIXME? */ |
| 185 | |
| 186 | /* |
| 187 | * Interleaving checks. |
| 188 | * |
| 189 | * If memory controller interleaving is enabled, then the data |
| 190 | * bus widths must be programmed identically for the 2 memory |
| 191 | * controllers. |
| 192 | */ |
| 193 | |
| 194 | fsl_ddr_board_options(popts, ctrl_num); |
| 195 | |
| 196 | return 0; |
| 197 | } |