Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
York Sun | c0c32af | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 2 | * Copyright 2008-2016 Freescale Semiconductor, Inc. |
| 3 | * Copyright 2017-2018 NXP Semiconductor |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 4 | * |
Tom Rini | 5b8031c | 2016-01-14 22:05:13 -0500 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0 |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef DDR2_DIMM_PARAMS_H |
| 9 | #define DDR2_DIMM_PARAMS_H |
| 10 | |
York Sun | 08b3f75 | 2011-03-17 11:18:10 -0700 | [diff] [blame] | 11 | #define EDC_DATA_PARITY 1 |
| 12 | #define EDC_ECC 2 |
| 13 | #define EDC_AC_PARITY 4 |
| 14 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 15 | /* Parameters for a DDR dimm computed from the SPD */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 16 | typedef struct dimm_params_s { |
| 17 | |
| 18 | /* DIMM organization parameters */ |
| 19 | char mpart[19]; /* guaranteed null terminated */ |
| 20 | |
| 21 | unsigned int n_ranks; |
York Sun | c0c32af | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 22 | unsigned int die_density; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 23 | unsigned long long rank_density; |
| 24 | unsigned long long capacity; |
| 25 | unsigned int data_width; |
| 26 | unsigned int primary_sdram_width; |
| 27 | unsigned int ec_sdram_width; |
| 28 | unsigned int registered_dimm; |
York Sun | c0c32af | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 29 | unsigned int package_3ds; /* number of dies in 3DS DIMM */ |
York Sun | b61e061 | 2013-06-25 11:37:47 -0700 | [diff] [blame] | 30 | unsigned int device_width; /* x4, x8, x16 components */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 31 | |
| 32 | /* SDRAM device parameters */ |
| 33 | unsigned int n_row_addr; |
| 34 | unsigned int n_col_addr; |
| 35 | unsigned int edc_config; /* 0 = none, 1 = parity, 2 = ECC */ |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 36 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 37 | unsigned int bank_addr_bits; |
| 38 | unsigned int bank_group_bits; |
| 39 | #else |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 40 | unsigned int n_banks_per_sdram_device; |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 41 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 42 | unsigned int burst_lengths_bitmask; /* BL=4 bit 2, BL=8 = bit 3 */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 43 | |
| 44 | /* used in computing base address of DIMMs */ |
| 45 | unsigned long long base_address; |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 46 | /* mirrored DIMMs */ |
| 47 | unsigned int mirrored_dimm; /* only for ddr3 */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 48 | |
| 49 | /* DIMM timing parameters */ |
| 50 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 51 | int mtb_ps; /* medium timebase ps */ |
| 52 | int ftb_10th_ps; /* fine timebase, in 1/10 ps */ |
| 53 | int taa_ps; /* minimum CAS latency time */ |
| 54 | int tfaw_ps; /* four active window delay */ |
Dave Liu | c360cea | 2009-03-14 12:48:30 +0800 | [diff] [blame] | 55 | |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 56 | /* |
| 57 | * SDRAM clock periods |
| 58 | * The range for these are 1000-10000 so a short should be sufficient |
| 59 | */ |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 60 | int tckmin_x_ps; |
| 61 | int tckmin_x_minus_1_ps; |
| 62 | int tckmin_x_minus_2_ps; |
| 63 | int tckmax_ps; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 64 | |
| 65 | /* SPD-defined CAS latencies */ |
Priyanka Jain | 0dd38a3 | 2013-09-25 10:41:19 +0530 | [diff] [blame] | 66 | unsigned int caslat_x; |
| 67 | unsigned int caslat_x_minus_1; |
| 68 | unsigned int caslat_x_minus_2; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 69 | |
| 70 | unsigned int caslat_lowest_derated; /* Derated CAS latency */ |
| 71 | |
| 72 | /* basic timing parameters */ |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 73 | int trcd_ps; |
| 74 | int trp_ps; |
| 75 | int tras_ps; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 76 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 77 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 78 | int trfc1_ps; |
| 79 | int trfc2_ps; |
| 80 | int trfc4_ps; |
| 81 | int trrds_ps; |
| 82 | int trrdl_ps; |
| 83 | int tccdl_ps; |
York Sun | c0c32af | 2018-01-29 09:44:35 -0800 | [diff] [blame] | 84 | int trfc_slr_ps; |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 85 | #else |
| 86 | int twr_ps; /* maximum = 63750 ps */ |
| 87 | int trfc_ps; /* max = 255 ns + 256 ns + .75 ns |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 88 | = 511750 ps */ |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 89 | int trrd_ps; /* maximum = 63750 ps */ |
| 90 | int twtr_ps; /* maximum = 63750 ps */ |
| 91 | int trtp_ps; /* byte 38, spd->trtp */ |
| 92 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 93 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 94 | int trc_ps; /* maximum = 254 ns + .75 ns = 254750 ps */ |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 95 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 96 | int refresh_rate_ps; |
| 97 | int extended_op_srt; |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 98 | |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 99 | #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2) |
| 100 | int tis_ps; /* byte 32, spd->ca_setup */ |
| 101 | int tih_ps; /* byte 33, spd->ca_hold */ |
| 102 | int tds_ps; /* byte 34, spd->data_setup */ |
| 103 | int tdh_ps; /* byte 35, spd->data_hold */ |
| 104 | int tdqsq_max_ps; /* byte 44, spd->tdqsq */ |
| 105 | int tqhs_ps; /* byte 45, spd->tqhs */ |
| 106 | #endif |
york | 9490ff4 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 107 | |
York Sun | 564e938 | 2018-01-29 10:24:08 -0800 | [diff] [blame] | 108 | /* DDR3 & DDR4 RDIMM */ |
york | 9490ff4 | 2010-07-02 22:25:55 +0000 | [diff] [blame] | 109 | unsigned char rcw[16]; /* Register Control Word 0-15 */ |
York Sun | 34e026f | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 110 | #ifdef CONFIG_SYS_FSL_DDR4 |
| 111 | unsigned int dq_mapping[18]; |
| 112 | unsigned int dq_mapping_ors; |
| 113 | #endif |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 114 | } dimm_params_t; |
| 115 | |
York Sun | 03e664d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 116 | unsigned int ddr_compute_dimm_parameters(const unsigned int ctrl_num, |
Kumar Gala | 58e5e9a | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 117 | const generic_spd_eeprom_t *spd, |
| 118 | dimm_params_t *pdimm, |
| 119 | unsigned int dimm_number); |
| 120 | |
| 121 | #endif |