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