1d4b91066SYork Sun /* 2d4b91066SYork Sun * Copyright 2011 Freescale Semiconductor, Inc. 3d4b91066SYork Sun * 4*1a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 5d4b91066SYork Sun */ 6d4b91066SYork Sun 7d4b91066SYork Sun #include <common.h> 8d4b91066SYork Sun 9d4b91066SYork Sun #include <asm/fsl_ddr_sdram.h> 10d4b91066SYork Sun #include <asm/fsl_ddr_dimm_params.h> 11d4b91066SYork Sun 12d4b91066SYork Sun struct board_specific_parameters { 13d4b91066SYork Sun u32 n_ranks; 14712cf7abSYork Sun u32 datarate_mhz_high; 15d4b91066SYork Sun u32 clk_adjust; 16d4b91066SYork Sun u32 cpo; 17d4b91066SYork Sun u32 write_data_delay; 18d4b91066SYork Sun u32 force_2T; 19d4b91066SYork Sun }; 20d4b91066SYork Sun 21712cf7abSYork Sun /* 22712cf7abSYork Sun * This table contains all valid speeds we want to override with board 23712cf7abSYork Sun * specific parameters. datarate_mhz_high values need to be in ascending order 24712cf7abSYork Sun * for each n_ranks group. 25712cf7abSYork Sun */ 26712cf7abSYork Sun static const struct board_specific_parameters udimm0[] = { 27d4b91066SYork Sun /* 28d4b91066SYork Sun * memory controller 0 29712cf7abSYork Sun * num| hi| clk| cpo|wrdata|2T 30712cf7abSYork Sun * ranks| mhz|adjst| | delay| 31d4b91066SYork Sun */ 32712cf7abSYork Sun {2, 300, 4, 4, 2, 0}, 33712cf7abSYork Sun {2, 365, 4, 6, 2, 0}, 34712cf7abSYork Sun {2, 450, 4, 7, 2, 0}, 35712cf7abSYork Sun {2, 850, 4, 31, 2, 0}, 36712cf7abSYork Sun {1, 300, 4, 4, 2, 0}, 37712cf7abSYork Sun {1, 365, 4, 6, 2, 0}, 38712cf7abSYork Sun {1, 450, 4, 7, 2, 0}, 39712cf7abSYork Sun {1, 850, 4, 31, 2, 0}, 40712cf7abSYork Sun {} 41d4b91066SYork Sun }; 42d4b91066SYork Sun 43d4b91066SYork Sun void fsl_ddr_board_options(memctl_options_t *popts, 44d4b91066SYork Sun dimm_params_t *pdimm, 45d4b91066SYork Sun unsigned int ctrl_num) 46d4b91066SYork Sun { 47712cf7abSYork Sun const struct board_specific_parameters *pbsp, *pbsp_highest = NULL; 48712cf7abSYork Sun unsigned int i; 49d4b91066SYork Sun ulong ddr_freq; 50d4b91066SYork Sun 51d4b91066SYork Sun if (ctrl_num != 0) /* we have only one controller */ 52d4b91066SYork Sun return; 53d4b91066SYork Sun for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) { 54d4b91066SYork Sun if (pdimm[i].n_ranks) 55d4b91066SYork Sun break; 56d4b91066SYork Sun } 57d4b91066SYork Sun if (i >= CONFIG_DIMM_SLOTS_PER_CTLR) /* no DIMM */ 58d4b91066SYork Sun return; 59d4b91066SYork Sun 60712cf7abSYork Sun pbsp = udimm0; 61d4b91066SYork Sun 62d4b91066SYork Sun /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr 63d4b91066SYork Sun * freqency and n_banks specified in board_specific_parameters table. 64d4b91066SYork Sun */ 65d4b91066SYork Sun ddr_freq = get_ddr_freq(0) / 1000000; 66712cf7abSYork Sun while (pbsp->datarate_mhz_high) { 67712cf7abSYork Sun if (pbsp->n_ranks == pdimm[i].n_ranks) { 68712cf7abSYork Sun if (ddr_freq <= pbsp->datarate_mhz_high) { 69d4b91066SYork Sun popts->clk_adjust = pbsp->clk_adjust; 70d4b91066SYork Sun popts->cpo_override = pbsp->cpo; 71712cf7abSYork Sun popts->write_data_delay = 72712cf7abSYork Sun pbsp->write_data_delay; 73d4b91066SYork Sun popts->twoT_en = pbsp->force_2T; 74712cf7abSYork Sun goto found; 75712cf7abSYork Sun } 76712cf7abSYork Sun pbsp_highest = pbsp; 77d4b91066SYork Sun } 78d4b91066SYork Sun pbsp++; 79d4b91066SYork Sun } 80d4b91066SYork Sun 81712cf7abSYork Sun if (pbsp_highest) { 82712cf7abSYork Sun printf("Error: board specific timing not found " 83712cf7abSYork Sun "for data rate %lu MT/s!\n" 84712cf7abSYork Sun "Trying to use the highest speed (%u) parameters\n", 85712cf7abSYork Sun ddr_freq, pbsp_highest->datarate_mhz_high); 86712cf7abSYork Sun popts->clk_adjust = pbsp_highest->clk_adjust; 87712cf7abSYork Sun popts->cpo_override = pbsp_highest->cpo; 88712cf7abSYork Sun popts->write_data_delay = pbsp_highest->write_data_delay; 89712cf7abSYork Sun popts->twoT_en = pbsp_highest->force_2T; 90712cf7abSYork Sun } else { 91712cf7abSYork Sun panic("DIMM is not supported by this board"); 92d4b91066SYork Sun } 93d4b91066SYork Sun 94712cf7abSYork Sun found: 95d4b91066SYork Sun /* 96d4b91066SYork Sun * Factors to consider for half-strength driver enable: 97d4b91066SYork Sun * - number of DIMMs installed 98d4b91066SYork Sun */ 99d4b91066SYork Sun popts->half_strength_driver_enable = 0; 100d4b91066SYork Sun popts->DQS_config = 0; /* only true DQS signal is used on board */ 101d4b91066SYork Sun } 102