Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 <i2c.h> |
| 11 | #include <hwconfig.h> |
| 12 | #include <asm/mmu.h> |
| 13 | #include <asm/fsl_ddr_sdram.h> |
| 14 | #include <asm/fsl_ddr_dimm_params.h> |
| 15 | #include <asm/fsl_law.h> |
| 16 | |
| 17 | typedef struct { |
| 18 | u32 datarate_mhz_low; |
| 19 | u32 datarate_mhz_high; |
| 20 | u32 n_ranks; |
| 21 | u32 clk_adjust; |
| 22 | u32 wrlvl_start; |
| 23 | u32 cpo; |
| 24 | u32 write_data_delay; |
| 25 | u32 force_2T; |
| 26 | } board_specific_parameters_t; |
| 27 | |
| 28 | /* |
| 29 | * ranges for parameters: |
| 30 | * wr_data_delay = 0-6 |
| 31 | * clk adjust = 0-8 |
| 32 | * cpo 2-0x1E (30) |
| 33 | */ |
| 34 | const board_specific_parameters_t board_specific_parameters[] = { |
| 35 | /* |
| 36 | * memory controller 0 |
| 37 | * lo| hi| num| clk| wrlvl | cpo |wrdata|2T |
| 38 | * mhz| mhz|ranks|adjst| start | delay| |
| 39 | */ |
Shaohui Xie | 1cf509e | 2011-09-22 11:46:12 +0800 | [diff] [blame] | 40 | { 0, 750, 2, 3, 5, 0xff, 2, 0}, |
| 41 | { 751, 1250, 2, 4, 6, 0xff, 2, 0}, |
| 42 | { 1251, 1350, 2, 5, 7, 0xff, 2, 0}, |
| 43 | { 1351, 1666, 2, 5, 8, 0xff, 2, 0}, |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | void fsl_ddr_board_options(memctl_options_t *popts, |
| 47 | dimm_params_t *pdimm, |
| 48 | unsigned int ctrl_num) |
| 49 | { |
| 50 | const board_specific_parameters_t *pbsp = |
| 51 | &board_specific_parameters[0]; |
| 52 | u32 num_params = ARRAY_SIZE(board_specific_parameters); |
| 53 | u32 i; |
| 54 | ulong ddr_freq; |
| 55 | |
| 56 | /* |
| 57 | * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr |
| 58 | * freqency and n_banks specified in board_specific_parameters table. |
| 59 | */ |
| 60 | ddr_freq = get_ddr_freq(0) / 1000000; |
| 61 | for (i = 0; i < num_params; i++) { |
| 62 | if (ddr_freq >= pbsp->datarate_mhz_low && |
| 63 | ddr_freq <= pbsp->datarate_mhz_high && |
| 64 | pdimm[0].n_ranks == pbsp->n_ranks) { |
| 65 | popts->cpo_override = pbsp->cpo; |
| 66 | popts->write_data_delay = pbsp->write_data_delay; |
| 67 | popts->clk_adjust = pbsp->clk_adjust; |
| 68 | popts->wrlvl_start = pbsp->wrlvl_start; |
| 69 | popts->twoT_en = pbsp->force_2T; |
| 70 | break; |
| 71 | } |
| 72 | pbsp++; |
| 73 | } |
| 74 | |
| 75 | if (i == num_params) { |
| 76 | printf("Warning: board specific timing not found " |
| 77 | "for data rate %lu MT/s!\n", ddr_freq); |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Factors to consider for half-strength driver enable: |
| 82 | * - number of DIMMs installed |
| 83 | */ |
| 84 | popts->half_strength_driver_enable = 0; |
| 85 | /* Write leveling override */ |
| 86 | popts->wrlvl_override = 1; |
| 87 | popts->wrlvl_sample = 0xf; |
| 88 | |
| 89 | /* Rtt and Rtt_WR override */ |
| 90 | popts->rtt_override = 0; |
| 91 | |
| 92 | /* Enable ZQ calibration */ |
| 93 | popts->zq_en = 1; |
| 94 | |
| 95 | /* DHC_EN =1, ODT = 60 Ohm */ |
| 96 | popts->ddr_cdr1 = DDR_CDR1_DHC_EN; |
| 97 | } |
| 98 | |
| 99 | phys_size_t initdram(int board_type) |
| 100 | { |
| 101 | phys_size_t dram_size = 0; |
| 102 | |
| 103 | puts("Initializing...."); |
| 104 | |
| 105 | if (fsl_use_spd()) { |
| 106 | puts("using SPD\n"); |
| 107 | dram_size = fsl_ddr_sdram(); |
| 108 | } else { |
| 109 | puts("no SPD and fixed parameters\n"); |
| 110 | return dram_size; |
| 111 | } |
| 112 | |
| 113 | dram_size = setup_ddr_tlbs(dram_size / 0x100000); |
| 114 | dram_size *= 0x100000; |
| 115 | |
Wolfgang Denk | f2bbb53 | 2011-07-25 10:13:53 +0200 | [diff] [blame] | 116 | debug(" DDR: "); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 117 | return dram_size; |
| 118 | } |