~ubuntu-branches/ubuntu/karmic/linux-mvl-dove/karmic-proposed

« back to all changes in this revision

Viewing changes to arch/arm/plat-orion/mv_hal_drivers/mv_hal/ddr/ddrmc/mvDramTmng.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader
  • Date: 2010-03-10 22:24:12 UTC
  • mto: (15.1.2 karmic-security)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20100310222412-k86m3r53jw0je7x1
Tags: upstream-2.6.31
ImportĀ upstreamĀ versionĀ 2.6.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
Copyright (C) Marvell International Ltd. and its affiliates
3
 
 
4
 
This software file (the "File") is owned and distributed by Marvell 
5
 
International Ltd. and/or its affiliates ("Marvell") under the following
6
 
alternative licensing terms.  Once you have made an election to distribute the
7
 
File under one of the following license alternatives, please (i) delete this
8
 
introductory statement regarding license alternatives, (ii) delete the two
9
 
license alternatives that you have not elected to use and (iii) preserve the
10
 
Marvell copyright notice above.
11
 
 
12
 
********************************************************************************
13
 
Marvell Commercial License Option
14
 
 
15
 
If you received this File from Marvell and you have entered into a commercial
16
 
license agreement (a "Commercial License") with Marvell, the File is licensed
17
 
to you under the terms of the applicable Commercial License.
18
 
 
19
 
********************************************************************************
20
 
Marvell GPL License Option
21
 
 
22
 
If you received this File from Marvell, you may opt to use, redistribute and/or 
23
 
modify this File in accordance with the terms and conditions of the General 
24
 
Public License Version 2, June 1991 (the "GPL License"), a copy of which is 
25
 
available along with the File in the license.txt file or by writing to the Free 
26
 
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or 
27
 
on the worldwide web at http://www.gnu.org/licenses/gpl.txt. 
28
 
 
29
 
THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED 
30
 
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY 
31
 
DISCLAIMED.  The GPL License provides additional details about this warranty 
32
 
disclaimer.
33
 
********************************************************************************
34
 
Marvell BSD License Option
35
 
 
36
 
If you received this File from Marvell, you may opt to use, redistribute and/or 
37
 
modify this File under the following licensing terms. 
38
 
Redistribution and use in source and binary forms, with or without modification, 
39
 
are permitted provided that the following conditions are met:
40
 
 
41
 
    *   Redistributions of source code must retain the above copyright notice,
42
 
            this list of conditions and the following disclaimer. 
43
 
 
44
 
    *   Redistributions in binary form must reproduce the above copyright
45
 
        notice, this list of conditions and the following disclaimer in the
46
 
        documentation and/or other materials provided with the distribution. 
47
 
 
48
 
    *   Neither the name of Marvell nor the names of its contributors may be 
49
 
        used to endorse or promote products derived from this software without 
50
 
        specific prior written permission. 
51
 
    
52
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
53
 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
54
 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
55
 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
56
 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
57
 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
58
 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
59
 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
60
 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
61
 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
 
 
63
 
*******************************************************************************/
64
 
 
65
 
 
66
 
/* includes */
67
 
#include "mvCommon.h"
68
 
#include "mvOs.h"
69
 
#include "ctrlEnv/mvCtrlEnvSpec.h"
70
 
#include "mvSysDdrConfig.h"
71
 
#include "mvDramIfConfig.h"
72
 
#include "mvDramIfRegs.h"
73
 
#include "../mvDramIf.h"
74
 
 
75
 
#warning "Fix this include...."
76
 
#include "pmu/mvPmuRegs.h"
77
 
#include <asm/setup.h>
78
 
 
79
 
#if defined (CONFIG_PM) && defined (CONFIG_ARCH_DOVE)
80
 
 
81
 
/* DDR speed to mask map table */
82
 
MV_U32 ddr_freq_mask[][2] = {{100, MV_DDR_100},
83
 
                             {133, MV_DDR_133},
84
 
                             {167, MV_DDR_167},
85
 
                             {200, MV_DDR_200},
86
 
                             {233, MV_DDR_233},
87
 
                             {250, MV_DDR_250},
88
 
                             {267, MV_DDR_267},
89
 
                             {333, MV_DDR_333},
90
 
                             {400, MV_DDR_400},
91
 
                             {500, MV_DDR_500},
92
 
                             {533, MV_DDR_533},
93
 
                             };
94
 
#define MV_DRAM_FREQ_MASK_CNT   (sizeof(ddr_freq_mask)/sizeof(ddr_freq_mask[0]))
95
 
 
96
 
/* Mandatory address decoding configurations */
97
 
MV_DDR_MC_PARAMS dove_windows[]={{0xD0800010, 0xF1800000},      /* Set DDR register space */
98
 
                                 {0xD00D025C, 0x000F1890},      /* Set NB register space */
99
 
                                 {0xD0020080, 0xF1000000},      /* Set SB register space */
100
 
                                 };
101
 
#define MV_DRAM_ADDR_DEC_CNT    (sizeof(dove_windows)/sizeof(dove_windows[0]))
102
 
 
103
 
/* Mandatory DDR reconfig configurations */
104
 
MV_DDR_MC_PARAMS ddr_reconfig[]={{0x00120, 0x03000100}, /* Load Mode Register */
105
 
                                 {0x00120, 0x03000200}, /* load Extended Mode Register */
106
 
                                 };
107
 
#define MV_DRAM_RECONFIG_CNT    (sizeof(ddr_reconfig)/sizeof(ddr_reconfig[0]))
108
 
 
109
 
extern MV_DRAM_INIT     mv_dram_init_info;
110
 
extern u32              mv_dram_init_valid;
111
 
 
112
 
/*******************************************************************************
113
 
* mvDramIfParamCountGet - Get the number of Addr/Value configuration needed 
114
 
*                         to init the DDR
115
 
*
116
 
* DESCRIPTION:
117
 
*       Get the number of Addr/Value configuration needed to init the DDR
118
 
*
119
 
* INPUT:
120
 
*       None.
121
 
*
122
 
* OUTPUT:
123
 
*       None.
124
 
*
125
 
* RETURN:
126
 
*       Number of Address Value couples
127
 
*
128
 
*******************************************************************************/
129
 
MV_U32 mvDramIfParamCountGet(MV_VOID)
130
 
{
131
 
        MV_U32 cnt=0;
132
 
        MV_U32 hdr;
133
 
 
134
 
        if (!mv_dram_init_valid)
135
 
        {
136
 
                mvOsPrintf("Warning: DRAM Initialization Parameters Not Found (Check Tags)!");  
137
 
                return 0;
138
 
        }
139
 
 
140
 
        /* scan all available frequencies and decide MAX parameters count */
141
 
        for (hdr = 0; hdr < MV_DRAM_HEADERS_CNT; hdr++) {
142
 
                if (mv_dram_init_info.dram_init_ctrl[hdr].freq_mask != 0) {
143
 
                        if (mv_dram_init_info.dram_init_ctrl[hdr].size > cnt) {                         
144
 
                                cnt = mv_dram_init_info.dram_init_ctrl[hdr].size;
145
 
                        }
146
 
                }
147
 
        }
148
 
 
149
 
        /* Add the FIXED count used for address decoding or reconfig; the bigger */
150
 
        if (MV_DRAM_ADDR_DEC_CNT > MV_DRAM_RECONFIG_CNT)
151
 
                cnt += MV_DRAM_ADDR_DEC_CNT;
152
 
        else
153
 
                cnt += MV_DRAM_RECONFIG_CNT;
154
 
 
155
 
        /* Add 1 entry for the DLL reset clearing in DDR reconfig */
156
 
        cnt++;
157
 
 
158
 
        return cnt;
159
 
}
160
 
 
161
 
/*******************************************************************************
162
 
* mvDramIfParamFill - Fill in the Address/Value couples
163
 
*
164
 
* DESCRIPTION:
165
 
*       This function fills in the addr/val couples needed to init the DDR
166
 
*       controller based on the requesed frequency
167
 
*
168
 
* INPUT:
169
 
*       ddrFreq - Target frequency
170
 
*
171
 
* OUTPUT:
172
 
*       params - pointer to the first addr/value element.
173
 
*       paramcnt - Number of paramters filled in the addr/value array.
174
 
*
175
 
* RETURN:
176
 
*       STATUS
177
 
*
178
 
*******************************************************************************/
179
 
MV_STATUS mvDramIfParamFill(MV_U32 ddrFreq, MV_DDR_MC_PARAMS * params, MV_U32 * paramcnt)
180
 
{
181
 
        MV_U32  reg_index, i, mask;
182
 
 
183
 
        /* Check that the Uboot passed valid parameters in the TAG */
184
 
        if (!mv_dram_init_valid) {
185
 
                *paramcnt = 0;
186
 
                mvOsPrintf("Warning: DRAM Initialization Parameters Not Found (Check Tags)!");
187
 
                return MV_FAIL;
188
 
        }
189
 
        
190
 
        /* Lookup the appropriate frequency mask */
191
 
        for (i=0; i<MV_DRAM_FREQ_MASK_CNT; i++) {
192
 
                if (ddr_freq_mask[i][0] == ddrFreq) {
193
 
                        mask = ddr_freq_mask[i][1];
194
 
                        break;
195
 
                }
196
 
        }
197
 
 
198
 
        /* Verify that the mask was found in the lookup table */
199
 
        if (i == MV_DRAM_FREQ_MASK_CNT) {
200
 
                *paramcnt = 0;
201
 
                return MV_FAIL;
202
 
        }
203
 
 
204
 
        /* Lookup the configurations entry in the table */
205
 
        for (i=0; i<MV_DRAM_HEADERS_CNT; i++) {
206
 
                if (mv_dram_init_info.dram_init_ctrl[i].freq_mask & mask) {
207
 
                        reg_index = mv_dram_init_info.dram_init_ctrl[i].start_index;
208
 
                        *paramcnt = mv_dram_init_info.dram_init_ctrl[i].size;
209
 
                        break;
210
 
                }
211
 
        }
212
 
 
213
 
        /* Check if frequency is not available OR zero configurations */
214
 
        if ((i == MV_DRAM_HEADERS_CNT) || (*paramcnt == 0))
215
 
                return MV_FAIL;
216
 
 
217
 
        /* First copy the address decoding PREFIX */
218
 
        for (i=0; i<MV_DRAM_ADDR_DEC_CNT; i++) {
219
 
                params->addr = dove_windows[i].addr;
220
 
                params->val = dove_windows[i].val;
221
 
                params++;
222
 
        }
223
 
 
224
 
        /* Copy the parameters in 32bit access */
225
 
        for (i=0; i<*paramcnt; i++) {
226
 
                params->addr = mv_dram_init_info.reg_init[reg_index].reg_addr;
227
 
                params->val = mv_dram_init_info.reg_init[reg_index].reg_value;
228
 
                reg_index++;
229
 
                params++;
230
 
        }
231
 
 
232
 
        /* Add the count of the Address decoding registers */
233
 
        *paramcnt += MV_DRAM_ADDR_DEC_CNT;
234
 
 
235
 
        return MV_OK;
236
 
}
237
 
 
238
 
 
239
 
/*******************************************************************************
240
 
* mvDramReconfigParamFill - Fill in the Address/Value couples
241
 
*
242
 
* DESCRIPTION:
243
 
*       This function fills in the addr/val couples needed to init the DDR
244
 
*       controller based on the requesed frequency
245
 
*
246
 
* INPUT:
247
 
*       ddrFreq - Target frequency
248
 
*       cpuFreq - cpu frequency to calculate Timing against
249
 
*
250
 
* OUTPUT:
251
 
*       params - pointer to the first addr/value element.
252
 
*       paramcnt - Number of paramters filled in the addr/value array.
253
 
*
254
 
* RETURN:
255
 
*       STATUS
256
 
*
257
 
*******************************************************************************/
258
 
MV_STATUS mvDramReconfigParamFill(MV_U32 ddrFreq, MV_U32 cpuFreq, MV_DDR_MC_PARAMS * params, MV_U32 * paramcnt)
259
 
{
260
 
        MV_U32 reg_index, i, mask;
261
 
        MV_U32 dll_rst = 0;
262
 
 
263
 
        /* Check that the Uboot passed valid parameters in the TAG */
264
 
        if (!mv_dram_init_valid) {
265
 
                *paramcnt = 0;
266
 
                mvOsPrintf("Warning: DRAM Initialization Parameters Not Found (Check Tags)!");
267
 
                return MV_FAIL;
268
 
        }
269
 
        
270
 
        /* Lookup the appropriate frequency mask */
271
 
        for (i=0; i<MV_DRAM_FREQ_MASK_CNT; i++) {
272
 
                if (ddr_freq_mask[i][0] == ddrFreq) {
273
 
                        mask = ddr_freq_mask[i][1];
274
 
                        break;
275
 
                }
276
 
        }
277
 
 
278
 
        /* Verify that the mask was found in the lookup table */
279
 
        if (i == MV_DRAM_FREQ_MASK_CNT) {
280
 
                *paramcnt = 0;
281
 
                return MV_FAIL;
282
 
        }
283
 
 
284
 
        /* Lookup the configurations entry in the table */
285
 
        for (i=0; i<MV_DRAM_HEADERS_CNT; i++) {
286
 
                if (mv_dram_init_info.dram_init_ctrl[i].freq_mask & mask) {
287
 
                        reg_index = mv_dram_init_info.dram_init_ctrl[i].start_index;
288
 
                        *paramcnt = mv_dram_init_info.dram_init_ctrl[i].size;
289
 
                        break;
290
 
                }
291
 
        }
292
 
 
293
 
        /* Check if frequency is not available OR zero configurations */
294
 
        if ((i == MV_DRAM_HEADERS_CNT) || (*paramcnt == 0))
295
 
                return MV_FAIL;
296
 
 
297
 
        /* Drop the last line with the DDR init trigger - replaced with LMR and LEMR */
298
 
        (*paramcnt)--;
299
 
 
300
 
        /* Firt copy the parameters in 32bit access */
301
 
        for (i=0; i<*paramcnt; i++) {
302
 
                params->addr = (mv_dram_init_info.reg_init[reg_index].reg_addr & 0xFFFFF); /* offset only */
303
 
                params->val = mv_dram_init_info.reg_init[reg_index].reg_value;
304
 
                if (params->addr == 0x80)
305
 
                {
306
 
                        dll_rst = params->val;
307
 
                        params->val |= 0x40;            /* Add DLL reset */
308
 
                }
309
 
                reg_index++;
310
 
                params++;
311
 
        }
312
 
 
313
 
        /* Finally add the DRAM reinit couples */
314
 
        for (i=0; i<MV_DRAM_RECONFIG_CNT; i++) {
315
 
                params->addr = ddr_reconfig[i].addr;
316
 
                params->val = ddr_reconfig[i].val;
317
 
                params++;
318
 
        }
319
 
 
320
 
        /* Add the DLL reset deasser */
321
 
        params->addr = 0x80;
322
 
        params->val = dll_rst;
323
 
 
324
 
        /* Add the count of LMR and LEMR registers count + DLL reset clearing */
325
 
        *paramcnt += (MV_DRAM_RECONFIG_CNT + 1);
326
 
 
327
 
        return MV_OK;   
328
 
}
329
 
 
330
 
 
331
 
/*******************************************************************************
332
 
* mvDramInitPollAmvFill - Fill in the Address/Value couples
333
 
*
334
 
* DESCRIPTION:
335
 
*       This function fills in the addr/val couples needed to init the DDR
336
 
*       controller based on the requesed frequency
337
 
*
338
 
* INPUT:
339
 
*       None.
340
 
*
341
 
* OUTPUT:
342
 
*       amv - address/mask/value for the DDR init done register.
343
 
*               amv->addr: Physical adddress of the init done register
344
 
*               amv->mask: Bit mask to poll for init done
345
 
*               amv->val: Value expected after the mask.
346
 
*
347
 
* RETURN:
348
 
*       STATUS
349
 
*
350
 
*******************************************************************************/
351
 
MV_STATUS mvDramInitPollAmvFill(MV_DDR_INIT_POLL_AMV * amv)
352
 
{
353
 
        amv->addr = (DOVE_SB_REGS_PHYS_BASE|SDRAM_STATUS_REG)/*mvOsIoVirtToPhy(NULL, (void*)(INTER_REGS_BASE|SDRAM_STATUS_REG))*/;
354
 
        amv->mask = SDRAM_STATUS_INIT_DONE_MASK;
355
 
        amv->val = SDRAM_STATUS_INIT_DONE;
356
 
 
357
 
        return MV_OK;
358
 
}
359
 
 
360
 
#endif /* #if defined (CONFIG_PM) && defined (CONFIG_ARCH_DOVE) */