summaryrefslogtreecommitdiff
path: root/board/scalys/simc-t10xx/ddr_QT1040-4GB.c
blob: 27f2f469d02597419970d4edf5436e98f7114d81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * Copyright 2017 Scalys B.V.
 * opensource@scalys.com
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <i2c.h>
#include <hwconfig.h>
#include <asm/mmu.h>
#include <fsl_ddr_sdram.h>
#include <fsl_ddr_dimm_params.h>
#include <asm/fsl_law.h>
 
DECLARE_GLOBAL_DATA_PTR;

#ifndef CONFIG_SYS_FSL_DDR4
#error  CONFIG_SYS_FSL_DDR4 not defined
#endif

/* Values for QT1040 4GB DDR4 */
/* ST9D4512M72SBG0 */
dimm_params_t ddr_raw_timing = {
	.n_ranks 		= 1,
	.rank_density 		= 0x100000000ULL,
	.capacity 		= 0x100000000ULL,
	.device_width 		= 64,
	.primary_sdram_width 	= 64,
	.ec_sdram_width 	= 8,
	.registered_dimm 	= 0,
	.mirrored_dimm 		= 0,
	.n_row_addr 		= 16,
	.n_col_addr 		= 10,

	.bank_addr_bits		= 0,
	.bank_group_bits	= 1,
	.edc_config 		= EDC_ECC,
	.burst_lengths_bitmask 	= 0x0c,
	/* 1600 MT/s*/
	.tckmin_x_ps		= 1250,
	.tckmax_ps		= 1499,
	.caslat_x		= 0x1400,
	.taa_ps 		= 15000,
	.trcd_ps 		= 15000,
	.trp_ps			= 15000,
	.tras_ps		= 35000,
	.trc_ps 		= 50000,
	.trfc1_ps		= 350000,
	.trfc2_ps		= 260000,
	.trfc4_ps		= 160000,
	.trrds_ps		= 6000,
	.trrdl_ps		= 7500,
	.tccdl_ps		= 6250,
	.refresh_rate_ps 	= 3900000,
	.tfaw_ps 		= 50000,
	
	/* DQ mapping for Qormino V2 S3/4 (rev-C/D) */
	.dq_mapping[ 0] = 0x15,
	.dq_mapping[ 1] = 0x2B,
	.dq_mapping[ 2] = 0x0C,
	.dq_mapping[ 3] = 0x27,
	.dq_mapping[ 4] = 0x0F,
	.dq_mapping[ 5] = 0x37,
	.dq_mapping[ 6] = 0x18,
	.dq_mapping[ 7] = 0x25,
	.dq_mapping[ 8] = 0x2A,
	.dq_mapping[ 9] = 0x16,
	.dq_mapping[10] = 0x2E,
	.dq_mapping[11] = 0x06,
	.dq_mapping[12] = 0x2A,
	.dq_mapping[13] = 0x0D,
	.dq_mapping[14] = 0x05,
	.dq_mapping[15] = 0x27,
	.dq_mapping[16] = 0x2B,
	.dq_mapping[17] = 0x18,
	.dq_mapping_ors = 0,
};

void fsl_ddr_board_options(memctl_options_t *popts,
			   dimm_params_t *pdimm,
			   unsigned int ctrl_num)
{
	int i;

	if (ctrl_num != 0) {
		printf("Only 1 memory controller supported, but %i requested\n",
		       ctrl_num);
		return; 
	}

	if (pdimm == NULL ) {
		printf("Error, no valid dimm parameter supplied\n");
		return;
	}

	if (!pdimm->n_ranks) {
		printf("No ranks in dimm parameters. Configuration error?\n");
		return;
	}

	/* DDR speed is fixed in the RCW */

	/* set odt_rd_cfg and odt_wr_cfg. */
	for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
		popts->cs_local_opts[i].odt_wr_cfg = 4;
	}

	for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
		popts->cs_local_opts[i].odt_rd_cfg = 4;
	}
	
	/* half strength */
	popts->half_strength_driver_enable = 1;

	popts->wrlvl_override	= 1;
	popts->wrlvl_en		= 1;
	popts->wrlvl_sample	= 0xf;
	popts->wrlvl_start	= 5;
	popts->wrlvl_ctl_2	= 0x05050505;
	popts->wrlvl_ctl_3	= 0x05050505;
	
	popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_40ohm);
	popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_40ohm) |
	DDR_CDR2_VREF_OVRD(70);       /* Vref = 70% */

	/* rtt and rtt_wr override */
	popts->rtt_override = 0;
	
	/* Enable ZQ calibration */
	popts->zq_en = 1;

	/* Clock is launched xxx applied cycle after address/command */
	popts->clk_adjust = 9; 
	
	/* Optimized cpo */
	popts->cpo_sample = 0x3d;
}

int fsl_ddr_get_dimm_params(dimm_params_t *pdimm,
			    unsigned int controller_number,
			    unsigned int dimm_number)
{
	const char dimm_model[] = "Soldered-down DDR4";
	
	if (((controller_number == 0) && (dimm_number == 0)) ||
		((controller_number == 1) && (dimm_number == 0))) {
		memcpy(pdimm, &ddr_raw_timing, sizeof(dimm_params_t));
		memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
		memcpy(pdimm->mpart, dimm_model, sizeof(pdimm->mpart) - 1);
	}
	
	return 0;
}

int dram_init(void)
{
	phys_size_t dram_size;

#if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_RAMBOOT_PBL)
	debug ("\n**** SPL_BUILD - DDR %i bits - %i MHz - (stack @ %p - fct @ %p) ****\n\n", 
			ddr_raw_timing.primary_sdram_width, (unsigned int) get_ddr_freq(0)/1000000u, &dram_size, (void*) dram_init);

	dram_size = fsl_ddr_sdram();
	debug("dram_size 0 = 0x%llx\n", dram_size);
	dram_size = setup_ddr_tlbs(dram_size / 0x100000);
	debug("dram_size 1 = 0x%llx\n", dram_size);
	dram_size *= 0x100000;
	debug("dram_size = 0x%llx (%llu MB)\n\nEnd of SPL DDR init...", dram_size, dram_size/(1024U*1024U));

#else
	debug ("\n**** NOT SPL_BUILD - DDR %i bits - %i MHz - (stack @ %p - fct @ %p)  ****\n\n", 
			ddr_raw_timing.primary_sdram_width, (unsigned int) get_ddr_freq(0)/1000000u, &dram_size, dram_init);

	/* DDR has been initialised by SPL loader */
	dram_size =  fsl_ddr_sdram_size();
	debug("dram_size 0 = 0x%llx\n", dram_size);
	dram_size = setup_ddr_tlbs(dram_size / 0x100000);
	debug("dram_size 1 = 0x%llx\n", dram_size);
	dram_size *= 0x100000;

#endif
	
	gd->ram_size = dram_size;
	
	return 0;
}