blob: 9718f18c30247703b9067e4a682bc6367c857795 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stefan Roese5ffceb82015-03-26 15:36:56 +01002/*
3 * Copyright (C) Marvell International Ltd. and its affiliates
Stefan Roese5ffceb82015-03-26 15:36:56 +01004 */
5
Stefan Roese5ffceb82015-03-26 15:36:56 +01006#include "ddr3_init.h"
Chris Packham1a07d212018-05-10 13:28:29 +12007#include "mv_ddr_common.h"
Chris Packham4bf81db2018-12-03 14:26:49 +13008#include "mv_ddr_training_db.h"
9#include "mv_ddr_regs.h"
Stefan Roese5ffceb82015-03-26 15:36:56 +010010
11#define GET_CS_FROM_MASK(mask) (cs_mask2_num[mask])
12#define CS_CBE_VALUE(cs_num) (cs_cbe_reg[cs_num])
13
14u32 window_mem_addr = 0;
15u32 phy_reg0_val = 0;
16u32 phy_reg1_val = 8;
17u32 phy_reg2_val = 0;
Chris Packham1a07d212018-05-10 13:28:29 +120018u32 phy_reg3_val = PARAM_UNDEFINED;
Chris Packham4bf81db2018-12-03 14:26:49 +130019enum mv_ddr_freq low_freq = MV_DDR_FREQ_LOW_FREQ;
20enum mv_ddr_freq medium_freq;
Stefan Roese5ffceb82015-03-26 15:36:56 +010021u32 debug_dunit = 0;
22u32 odt_additional = 1;
23u32 *dq_map_table = NULL;
Chris Packham1a07d212018-05-10 13:28:29 +120024
25/* in case of ddr4 do not run ddr3_tip_write_additional_odt_setting function - mc odt always 'on'
26 * in ddr4 case the terminations are rttWR and rttPARK and the odt must be always 'on' 0x1498 = 0xf
27 */
Stefan Roese5ffceb82015-03-26 15:36:56 +010028u32 odt_config = 1;
29
Chris Packham1a07d212018-05-10 13:28:29 +120030u32 nominal_avs;
31u32 extension_avs;
32
Stefan Roese5ffceb82015-03-26 15:36:56 +010033u32 is_pll_before_init = 0, is_adll_calib_before_init = 1, is_dfs_in_init = 0;
Chris Packham1a07d212018-05-10 13:28:29 +120034u32 dfs_low_freq;
35
36u32 g_rtt_nom_cs0, g_rtt_nom_cs1;
Stefan Roese5ffceb82015-03-26 15:36:56 +010037u8 calibration_update_control; /* 2 external only, 1 is internal only */
38
39enum hws_result training_result[MAX_STAGE_LIMIT][MAX_INTERFACE_NUM];
40enum auto_tune_stage training_stage = INIT_CONTROLLER;
41u32 finger_test = 0, p_finger_start = 11, p_finger_end = 64,
42 n_finger_start = 11, n_finger_end = 64,
43 p_finger_step = 3, n_finger_step = 3;
44u32 clamp_tbl[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
45
46/* Initiate to 0xff, this variable is define by user in debug mode */
Chris Packham1a07d212018-05-10 13:28:29 +120047u32 mode_2t = 0xff;
Stefan Roese5ffceb82015-03-26 15:36:56 +010048u32 xsb_validate_type = 0;
49u32 xsb_validation_base_address = 0xf000;
50u32 first_active_if = 0;
51u32 dfs_low_phy1 = 0x1f;
52u32 multicast_id = 0;
53int use_broadcast = 0;
54struct hws_tip_freq_config_info *freq_info_table = NULL;
55u8 is_cbe_required = 0;
56u32 debug_mode = 0;
57u32 delay_enable = 0;
58int rl_mid_freq_wa = 0;
59
60u32 effective_cs = 0;
61
Chris Packham1a07d212018-05-10 13:28:29 +120062u32 vref_init_val = 0x4;
63u32 ck_delay = PARAM_UNDEFINED;
64
65/* Design guidelines parameters */
66u32 g_zpri_data = PARAM_UNDEFINED; /* controller data - P drive strength */
67u32 g_znri_data = PARAM_UNDEFINED; /* controller data - N drive strength */
68u32 g_zpri_ctrl = PARAM_UNDEFINED; /* controller C/A - P drive strength */
69u32 g_znri_ctrl = PARAM_UNDEFINED; /* controller C/A - N drive strength */
70
71u32 g_zpodt_data = PARAM_UNDEFINED; /* controller data - P ODT */
72u32 g_znodt_data = PARAM_UNDEFINED; /* controller data - N ODT */
73u32 g_zpodt_ctrl = PARAM_UNDEFINED; /* controller data - P ODT */
74u32 g_znodt_ctrl = PARAM_UNDEFINED; /* controller data - N ODT */
75
76u32 g_odt_config = PARAM_UNDEFINED;
77u32 g_rtt_nom = PARAM_UNDEFINED;
78u32 g_rtt_wr = PARAM_UNDEFINED;
79u32 g_dic = PARAM_UNDEFINED;
80u32 g_rtt_park = PARAM_UNDEFINED;
81
Stefan Roese5ffceb82015-03-26 15:36:56 +010082u32 mask_tune_func = (SET_MEDIUM_FREQ_MASK_BIT |
83 WRITE_LEVELING_MASK_BIT |
84 LOAD_PATTERN_2_MASK_BIT |
85 READ_LEVELING_MASK_BIT |
Chris Packham1a07d212018-05-10 13:28:29 +120086 SET_TARGET_FREQ_MASK_BIT |
87 WRITE_LEVELING_TF_MASK_BIT |
Stefan Roese5ffceb82015-03-26 15:36:56 +010088 READ_LEVELING_TF_MASK_BIT |
Chris Packham1a07d212018-05-10 13:28:29 +120089 CENTRALIZATION_RX_MASK_BIT |
90 CENTRALIZATION_TX_MASK_BIT);
Stefan Roese5ffceb82015-03-26 15:36:56 +010091
92static int ddr3_tip_ddr3_training_main_flow(u32 dev_num);
93static int ddr3_tip_write_odt(u32 dev_num, enum hws_access_type access_type,
94 u32 if_id, u32 cl_value, u32 cwl_value);
95static int ddr3_tip_ddr3_auto_tune(u32 dev_num);
Chris Packham1a07d212018-05-10 13:28:29 +120096
Stefan Roese5ffceb82015-03-26 15:36:56 +010097#ifdef ODT_TEST_SUPPORT
98static int odt_test(u32 dev_num, enum hws_algo_type algo_type);
99#endif
100
101int adll_calibration(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +1300102 u32 if_id, enum mv_ddr_freq frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100103static int ddr3_tip_set_timing(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +1300104 u32 if_id, enum mv_ddr_freq frequency);
Chris Packham1a07d212018-05-10 13:28:29 +1200105
106static u8 mem_size_config[MV_DDR_DIE_CAP_LAST] = {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100107 0x2, /* 512Mbit */
108 0x3, /* 1Gbit */
109 0x0, /* 2Gbit */
110 0x4, /* 4Gbit */
Chris Packham1a07d212018-05-10 13:28:29 +1200111 0x5, /* 8Gbit */
112 0x0, /* TODO: placeholder for 16-Mbit die capacity */
113 0x0, /* TODO: placeholder for 32-Mbit die capacity */
114 0x0, /* TODO: placeholder for 12-Mbit die capacity */
115 0x0 /* TODO: placeholder for 24-Mbit die capacity */
Stefan Roese5ffceb82015-03-26 15:36:56 +0100116};
117
118static u8 cs_mask2_num[] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 };
119
120static struct reg_data odpg_default_value[] = {
121 {0x1034, 0x38000, MASK_ALL_BITS},
122 {0x1038, 0x0, MASK_ALL_BITS},
123 {0x10b0, 0x0, MASK_ALL_BITS},
124 {0x10b8, 0x0, MASK_ALL_BITS},
125 {0x10c0, 0x0, MASK_ALL_BITS},
126 {0x10f0, 0x0, MASK_ALL_BITS},
127 {0x10f4, 0x0, MASK_ALL_BITS},
128 {0x10f8, 0xff, MASK_ALL_BITS},
129 {0x10fc, 0xffff, MASK_ALL_BITS},
130 {0x1130, 0x0, MASK_ALL_BITS},
131 {0x1830, 0x2000000, MASK_ALL_BITS},
132 {0x14d0, 0x0, MASK_ALL_BITS},
133 {0x14d4, 0x0, MASK_ALL_BITS},
134 {0x14d8, 0x0, MASK_ALL_BITS},
135 {0x14dc, 0x0, MASK_ALL_BITS},
136 {0x1454, 0x0, MASK_ALL_BITS},
137 {0x1594, 0x0, MASK_ALL_BITS},
138 {0x1598, 0x0, MASK_ALL_BITS},
139 {0x159c, 0x0, MASK_ALL_BITS},
140 {0x15a0, 0x0, MASK_ALL_BITS},
141 {0x15a4, 0x0, MASK_ALL_BITS},
142 {0x15a8, 0x0, MASK_ALL_BITS},
143 {0x15ac, 0x0, MASK_ALL_BITS},
144 {0x1604, 0x0, MASK_ALL_BITS},
145 {0x1608, 0x0, MASK_ALL_BITS},
146 {0x160c, 0x0, MASK_ALL_BITS},
147 {0x1610, 0x0, MASK_ALL_BITS},
148 {0x1614, 0x0, MASK_ALL_BITS},
149 {0x1618, 0x0, MASK_ALL_BITS},
150 {0x1624, 0x0, MASK_ALL_BITS},
151 {0x1690, 0x0, MASK_ALL_BITS},
152 {0x1694, 0x0, MASK_ALL_BITS},
153 {0x1698, 0x0, MASK_ALL_BITS},
154 {0x169c, 0x0, MASK_ALL_BITS},
155 {0x14b8, 0x6f67, MASK_ALL_BITS},
156 {0x1630, 0x0, MASK_ALL_BITS},
157 {0x1634, 0x0, MASK_ALL_BITS},
158 {0x1638, 0x0, MASK_ALL_BITS},
159 {0x163c, 0x0, MASK_ALL_BITS},
160 {0x16b0, 0x0, MASK_ALL_BITS},
161 {0x16b4, 0x0, MASK_ALL_BITS},
162 {0x16b8, 0x0, MASK_ALL_BITS},
163 {0x16bc, 0x0, MASK_ALL_BITS},
164 {0x16c0, 0x0, MASK_ALL_BITS},
165 {0x16c4, 0x0, MASK_ALL_BITS},
166 {0x16c8, 0x0, MASK_ALL_BITS},
167 {0x16cc, 0x1, MASK_ALL_BITS},
168 {0x16f0, 0x1, MASK_ALL_BITS},
169 {0x16f4, 0x0, MASK_ALL_BITS},
170 {0x16f8, 0x0, MASK_ALL_BITS},
171 {0x16fc, 0x0, MASK_ALL_BITS}
172};
173
Chris Packham1a07d212018-05-10 13:28:29 +1200174/* MR cmd and addr definitions */
175struct mv_ddr_mr_data mr_data[] = {
176 {MRS0_CMD, MR0_REG},
177 {MRS1_CMD, MR1_REG},
178 {MRS2_CMD, MR2_REG},
179 {MRS3_CMD, MR3_REG}
180};
181
Chris Packham4bf81db2018-12-03 14:26:49 +1300182/* inverse pads */
183static int ddr3_tip_pad_inv(void)
184{
185 u32 sphy, data;
186 u32 sphy_max = ddr3_tip_dev_attr_get(0, MV_ATTR_OCTET_PER_INTERFACE);
187 u32 ck_swap_ctrl_sphy;
188 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
189
190 for (sphy = 0; sphy < sphy_max; sphy++) {
191 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, sphy);
192 if (tm->interface_params[0].
193 as_bus_params[sphy].is_dqs_swap == 1) {
194 data = (INVERT_PAD << INV_PAD4_OFFS |
195 INVERT_PAD << INV_PAD5_OFFS);
196 /* dqs swap */
197 ddr3_tip_bus_read_modify_write(0, ACCESS_TYPE_UNICAST,
198 0, sphy,
199 DDR_PHY_DATA,
200 PHY_CTRL_PHY_REG,
201 data, data);
202 }
203
204 if (tm->interface_params[0].as_bus_params[sphy].
205 is_ck_swap == 1 && sphy == 0) {
206/* TODO: move this code to per platform one */
207#if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_39X)
208 /* clock swap for both cs0 and cs1 */
209 data = (INVERT_PAD << INV_PAD2_OFFS |
210 INVERT_PAD << INV_PAD6_OFFS |
211 INVERT_PAD << INV_PAD4_OFFS |
212 INVERT_PAD << INV_PAD5_OFFS);
213 ck_swap_ctrl_sphy = CK_SWAP_CTRL_PHY_NUM;
214 ddr3_tip_bus_read_modify_write(0, ACCESS_TYPE_UNICAST,
215 0, ck_swap_ctrl_sphy,
216 DDR_PHY_CONTROL,
217 PHY_CTRL_PHY_REG,
218 data, data);
219#else /* !CONFIG_ARMADA_38X && !CONFIG_ARMADA_39X && !A70X0 && !A80X0 && !A3900 */
220#pragma message "unknown platform to configure ddr clock swap"
221#endif
222 }
223 }
224
225 return MV_OK;
226}
227
Stefan Roese5ffceb82015-03-26 15:36:56 +0100228static int ddr3_tip_rank_control(u32 dev_num, u32 if_id);
229
230/*
231 * Update global training parameters by data from user
232 */
233int ddr3_tip_tune_training_params(u32 dev_num,
234 struct tune_train_params *params)
235{
Chris Packham1a07d212018-05-10 13:28:29 +1200236 if (params->ck_delay != PARAM_UNDEFINED)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100237 ck_delay = params->ck_delay;
Chris Packham1a07d212018-05-10 13:28:29 +1200238 if (params->phy_reg3_val != PARAM_UNDEFINED)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100239 phy_reg3_val = params->phy_reg3_val;
Chris Packham1a07d212018-05-10 13:28:29 +1200240 if (params->g_rtt_nom != PARAM_UNDEFINED)
241 g_rtt_nom = params->g_rtt_nom;
242 if (params->g_rtt_wr != PARAM_UNDEFINED)
243 g_rtt_wr = params->g_rtt_wr;
244 if (params->g_dic != PARAM_UNDEFINED)
245 g_dic = params->g_dic;
246 if (params->g_odt_config != PARAM_UNDEFINED)
247 g_odt_config = params->g_odt_config;
248 if (params->g_zpri_data != PARAM_UNDEFINED)
249 g_zpri_data = params->g_zpri_data;
250 if (params->g_znri_data != PARAM_UNDEFINED)
251 g_znri_data = params->g_znri_data;
252 if (params->g_zpri_ctrl != PARAM_UNDEFINED)
253 g_zpri_ctrl = params->g_zpri_ctrl;
254 if (params->g_znri_ctrl != PARAM_UNDEFINED)
255 g_znri_ctrl = params->g_znri_ctrl;
256 if (params->g_zpodt_data != PARAM_UNDEFINED)
257 g_zpodt_data = params->g_zpodt_data;
258 if (params->g_znodt_data != PARAM_UNDEFINED)
259 g_znodt_data = params->g_znodt_data;
260 if (params->g_zpodt_ctrl != PARAM_UNDEFINED)
261 g_zpodt_ctrl = params->g_zpodt_ctrl;
262 if (params->g_znodt_ctrl != PARAM_UNDEFINED)
263 g_znodt_ctrl = params->g_znodt_ctrl;
264 if (params->g_rtt_park != PARAM_UNDEFINED)
265 g_rtt_park = params->g_rtt_park;
266
Chris Packham4bf81db2018-12-03 14:26:49 +1300267
Chris Packham1a07d212018-05-10 13:28:29 +1200268 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
269 ("DGL parameters: 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n",
270 g_zpri_data, g_znri_data, g_zpri_ctrl, g_znri_ctrl, g_zpodt_data, g_znodt_data,
271 g_zpodt_ctrl, g_znodt_ctrl, g_rtt_nom, g_dic, g_odt_config, g_rtt_wr));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100272
273 return MV_OK;
274}
275
276/*
277 * Configure CS
278 */
279int ddr3_tip_configure_cs(u32 dev_num, u32 if_id, u32 cs_num, u32 enable)
280{
281 u32 data, addr_hi, data_high;
282 u32 mem_index;
Baruch Siach24a1d132020-01-20 14:20:06 +0200283 u32 clk_enable;
Chris Packham1a07d212018-05-10 13:28:29 +1200284 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100285
Baruch Siach24a1d132020-01-20 14:20:06 +0200286 if (tm->clk_enable & (1 << cs_num))
287 clk_enable = 1;
288 else
289 clk_enable = enable;
290
Stefan Roese5ffceb82015-03-26 15:36:56 +0100291 if (enable == 1) {
292 data = (tm->interface_params[if_id].bus_width ==
Chris Packham1a07d212018-05-10 13:28:29 +1200293 MV_DDR_DEV_WIDTH_8BIT) ? 0 : 1;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100294 CHECK_STATUS(ddr3_tip_if_write
295 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200296 SDRAM_ADDR_CTRL_REG, (data << (cs_num * 4)),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100297 0x3 << (cs_num * 4)));
298 mem_index = tm->interface_params[if_id].memory_size;
299
300 addr_hi = mem_size_config[mem_index] & 0x3;
301 CHECK_STATUS(ddr3_tip_if_write
302 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200303 SDRAM_ADDR_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100304 (addr_hi << (2 + cs_num * 4)),
305 0x3 << (2 + cs_num * 4)));
306
307 data_high = (mem_size_config[mem_index] & 0x4) >> 2;
308 CHECK_STATUS(ddr3_tip_if_write
309 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200310 SDRAM_ADDR_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100311 data_high << (20 + cs_num), 1 << (20 + cs_num)));
312
313 /* Enable Address Select Mode */
314 CHECK_STATUS(ddr3_tip_if_write
315 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200316 SDRAM_ADDR_CTRL_REG, 1 << (16 + cs_num),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100317 1 << (16 + cs_num)));
318 }
319 switch (cs_num) {
320 case 0:
321 case 1:
322 case 2:
323 CHECK_STATUS(ddr3_tip_if_write
324 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Baruch Siach24a1d132020-01-20 14:20:06 +0200325 DUNIT_CTRL_LOW_REG, (clk_enable << (cs_num + 11)),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100326 1 << (cs_num + 11)));
327 break;
328 case 3:
329 CHECK_STATUS(ddr3_tip_if_write
330 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Baruch Siach24a1d132020-01-20 14:20:06 +0200331 DUNIT_CTRL_LOW_REG, (clk_enable << 15), 1 << 15));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100332 break;
333 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100334
335 return MV_OK;
336}
337
338/*
339 * Init Controller Flow
340 */
341int hws_ddr3_tip_init_controller(u32 dev_num, struct init_cntr_param *init_cntr_prm)
342{
343 u32 if_id;
344 u32 cs_num;
Chris Packham1a07d212018-05-10 13:28:29 +1200345 u32 t_ckclk = 0, t_wr = 0, t2t = 0;
346 u32 data_value = 0, cs_cnt = 0,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100347 mem_mask = 0, bus_index = 0;
Chris Packham4bf81db2018-12-03 14:26:49 +1300348 enum mv_ddr_speed_bin speed_bin_index = SPEED_BIN_DDR_2133N;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100349 u32 cs_mask = 0;
350 u32 cl_value = 0, cwl_val = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200351 u32 bus_cnt = 0, adll_tap = 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100352 enum hws_access_type access_type = ACCESS_TYPE_UNICAST;
353 u32 data_read[MAX_INTERFACE_NUM];
Chris Packham1a07d212018-05-10 13:28:29 +1200354 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
355 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Chris Packham3a09e132018-05-10 13:28:30 +1200356 enum mv_ddr_timing timing;
Chris Packham4bf81db2018-12-03 14:26:49 +1300357 enum mv_ddr_freq freq = tm->interface_params[0].memory_freq;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100358
359 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
360 ("Init_controller, do_mrs_phy=%d, is_ctrl64_bit=%d\n",
361 init_cntr_prm->do_mrs_phy,
362 init_cntr_prm->is_ctrl64_bit));
363
364 if (init_cntr_prm->init_phy == 1) {
365 CHECK_STATUS(ddr3_tip_configure_phy(dev_num));
366 }
367
368 if (generic_init_controller == 1) {
369 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200370 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100371 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
372 ("active IF %d\n", if_id));
373 mem_mask = 0;
374 for (bus_index = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200375 bus_index < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100376 bus_index++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200377 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_index);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100378 mem_mask |=
379 tm->interface_params[if_id].
380 as_bus_params[bus_index].mirror_enable_bitmask;
381 }
382
383 if (mem_mask != 0) {
384 CHECK_STATUS(ddr3_tip_if_write
385 (dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200386 if_id, DUAL_DUNIT_CFG_REG, 0,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100387 0x8));
388 }
389
Stefan Roese5ffceb82015-03-26 15:36:56 +0100390 speed_bin_index =
391 tm->interface_params[if_id].
392 speed_bin_index;
Chris Packham1a07d212018-05-10 13:28:29 +1200393
Stefan Roese5ffceb82015-03-26 15:36:56 +0100394 /* t_ckclk is external clock */
Chris Packham4bf81db2018-12-03 14:26:49 +1300395 t_ckclk = (MEGA / mv_ddr_freq_get(freq));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100396
Chris Packham1a07d212018-05-10 13:28:29 +1200397 if (MV_DDR_IS_HALF_BUS_DRAM_MODE(tm->bus_act_mask, octets_per_if_num))
398 data_value = (0x4000 | 0 | 0x1000000) & ~(1 << 26);
399 else
400 data_value = (0x4000 | 0x8000 | 0x1000000) & ~(1 << 26);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100401
402 /* Interface Bus Width */
403 /* SRMode */
404 CHECK_STATUS(ddr3_tip_if_write
405 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200406 SDRAM_CFG_REG, data_value,
407 0x100c000));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100408
409 /* Interleave first command pre-charge enable (TBD) */
410 CHECK_STATUS(ddr3_tip_if_write
411 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200412 SDRAM_OPEN_PAGES_CTRL_REG, (1 << 10),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100413 (1 << 10)));
414
Chris Packham1a07d212018-05-10 13:28:29 +1200415 /* Reset divider_b assert -> de-assert */
416 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
417 SDRAM_CFG_REG,
418 0x0 << PUP_RST_DIVIDER_OFFS,
419 PUP_RST_DIVIDER_MASK << PUP_RST_DIVIDER_OFFS));
420
421 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
422 SDRAM_CFG_REG,
423 0x1 << PUP_RST_DIVIDER_OFFS,
424 PUP_RST_DIVIDER_MASK << PUP_RST_DIVIDER_OFFS));
425
Stefan Roese5ffceb82015-03-26 15:36:56 +0100426 /* PHY configuration */
427 /*
428 * Postamble Length = 1.5cc, Addresscntl to clk skew
429 * \BD, Preamble length normal, parralal ADLL enable
430 */
431 CHECK_STATUS(ddr3_tip_if_write
432 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200433 DRAM_PHY_CFG_REG, 0x28, 0x3e));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100434 if (init_cntr_prm->is_ctrl64_bit) {
435 /* positive edge */
436 CHECK_STATUS(ddr3_tip_if_write
437 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200438 DRAM_PHY_CFG_REG, 0x0,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100439 0xff80));
440 }
441
442 /* calibration block disable */
443 /* Xbar Read buffer select (for Internal access) */
444 CHECK_STATUS(ddr3_tip_if_write
445 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200446 MAIN_PADS_CAL_MACH_CTRL_REG, 0x1200c,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100447 0x7dffe01c));
448 CHECK_STATUS(ddr3_tip_if_write
449 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200450 MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100451 calibration_update_control << 3, 0x3 << 3));
452
453 /* Pad calibration control - enable */
454 CHECK_STATUS(ddr3_tip_if_write
455 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200456 MAIN_PADS_CAL_MACH_CTRL_REG, 0x1, 0x1));
457 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) < MV_TIP_REV_3) {
458 /* DDR3 rank ctrl \96 part of the generic code */
459 /* CS1 mirroring enable + w/a for JIRA DUNIT-14581 */
460 CHECK_STATUS(ddr3_tip_if_write
461 (dev_num, access_type, if_id,
462 DDR3_RANK_CTRL_REG, 0x27, MASK_ALL_BITS));
463 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100464
465 cs_mask = 0;
466 data_value = 0x7;
467 /*
468 * Address ctrl \96 Part of the Generic code
469 * The next configuration is done:
470 * 1) Memory Size
471 * 2) Bus_width
472 * 3) CS#
473 * 4) Page Number
Stefan Roese5ffceb82015-03-26 15:36:56 +0100474 * Per Dunit get from the Map_topology the parameters:
475 * Bus_width
Stefan Roese5ffceb82015-03-26 15:36:56 +0100476 */
Stefan Roese5ffceb82015-03-26 15:36:56 +0100477
478 data_value =
479 (tm->interface_params[if_id].
Chris Packham1a07d212018-05-10 13:28:29 +1200480 bus_width == MV_DDR_DEV_WIDTH_8BIT) ? 0 : 1;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100481
482 /* create merge cs mask for all cs available in dunit */
483 for (bus_cnt = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200484 bus_cnt < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100485 bus_cnt++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200486 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100487 cs_mask |=
488 tm->interface_params[if_id].
489 as_bus_params[bus_cnt].cs_bitmask;
490 }
491 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
492 ("Init_controller IF %d cs_mask %d\n",
493 if_id, cs_mask));
494 /*
495 * Configure the next upon the Map Topology \96 If the
496 * Dunit is CS0 Configure CS0 if it is multi CS
497 * configure them both: The Bust_width it\92s the
498 * Memory Bus width \96 x8 or x16
499 */
Chris Packham4bf81db2018-12-03 14:26:49 +1300500 for (cs_cnt = 0; cs_cnt < MAX_CS_NUM; cs_cnt++) {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100501 ddr3_tip_configure_cs(dev_num, if_id, cs_cnt,
502 ((cs_mask & (1 << cs_cnt)) ? 1
503 : 0));
504 }
505
506 if (init_cntr_prm->do_mrs_phy) {
507 /*
508 * MR0 \96 Part of the Generic code
509 * The next configuration is done:
510 * 1) Burst Length
511 * 2) CAS Latency
512 * get for each dunit what is it Speed_bin &
513 * Target Frequency. From those both parameters
514 * get the appropriate Cas_l from the CL table
515 */
516 cl_value =
517 tm->interface_params[if_id].
518 cas_l;
519 cwl_val =
520 tm->interface_params[if_id].
521 cas_wl;
522 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
523 ("cl_value 0x%x cwl_val 0x%x\n",
524 cl_value, cwl_val));
Chris Packham1a07d212018-05-10 13:28:29 +1200525
Chris Packham4bf81db2018-12-03 14:26:49 +1300526 t_wr = time_to_nclk(mv_ddr_speed_bin_timing_get
Chris Packham1a07d212018-05-10 13:28:29 +1200527 (speed_bin_index,
528 SPEED_BIN_TWR), t_ckclk);
529
Stefan Roese5ffceb82015-03-26 15:36:56 +0100530 data_value =
531 ((cl_mask_table[cl_value] & 0x1) << 2) |
532 ((cl_mask_table[cl_value] & 0xe) << 3);
533 CHECK_STATUS(ddr3_tip_if_write
534 (dev_num, access_type, if_id,
535 MR0_REG, data_value,
536 (0x7 << 4) | (1 << 2)));
537 CHECK_STATUS(ddr3_tip_if_write
538 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200539 MR0_REG, twr_mask_table[t_wr] << 9,
540 0x7 << 9));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100541
542 /*
543 * MR1: Set RTT and DIC Design GL values
544 * configured by user
545 */
546 CHECK_STATUS(ddr3_tip_if_write
547 (dev_num, ACCESS_TYPE_MULTICAST,
548 PARAM_NOT_CARE, MR1_REG,
549 g_dic | g_rtt_nom, 0x266));
550
551 /* MR2 - Part of the Generic code */
552 /*
553 * The next configuration is done:
554 * 1) SRT
555 * 2) CAS Write Latency
556 */
557 data_value = (cwl_mask_table[cwl_val] << 3);
558 data_value |=
559 ((tm->interface_params[if_id].
560 interface_temp ==
Chris Packham1a07d212018-05-10 13:28:29 +1200561 MV_DDR_TEMP_HIGH) ? (1 << 7) : 0);
562 data_value |= g_rtt_wr;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100563 CHECK_STATUS(ddr3_tip_if_write
564 (dev_num, access_type, if_id,
565 MR2_REG, data_value,
566 (0x7 << 3) | (0x1 << 7) | (0x3 <<
567 9)));
568 }
569
570 ddr3_tip_write_odt(dev_num, access_type, if_id,
571 cl_value, cwl_val);
572 ddr3_tip_set_timing(dev_num, access_type, if_id, freq);
573
Chris Packham1a07d212018-05-10 13:28:29 +1200574 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) < MV_TIP_REV_3) {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100575 CHECK_STATUS(ddr3_tip_if_write
576 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200577 DUNIT_CTRL_HIGH_REG, 0x1000119,
578 0x100017F));
579 } else {
580 CHECK_STATUS(ddr3_tip_if_write
581 (dev_num, access_type, if_id,
582 DUNIT_CTRL_HIGH_REG, 0x600177 |
583 (init_cntr_prm->is_ctrl64_bit ?
584 CPU_INTERJECTION_ENA_SPLIT_ENA << CPU_INTERJECTION_ENA_OFFS :
585 CPU_INTERJECTION_ENA_SPLIT_DIS << CPU_INTERJECTION_ENA_OFFS),
586 0x1600177 | CPU_INTERJECTION_ENA_MASK <<
587 CPU_INTERJECTION_ENA_OFFS));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100588 }
589
590 /* reset bit 7 */
591 CHECK_STATUS(ddr3_tip_if_write
592 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200593 DUNIT_CTRL_HIGH_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100594 (init_cntr_prm->msys_init << 7), (1 << 7)));
595
Chris Packham3a09e132018-05-10 13:28:30 +1200596 timing = tm->interface_params[if_id].timing;
597
Chris Packham1a07d212018-05-10 13:28:29 +1200598 if (mode_2t != 0xff) {
599 t2t = mode_2t;
Chris Packham3a09e132018-05-10 13:28:30 +1200600 } else if (timing != MV_DDR_TIM_DEFAULT) {
601 t2t = (timing == MV_DDR_TIM_2T) ? 1 : 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100602 } else {
Chris Packham1a07d212018-05-10 13:28:29 +1200603 /* calculate number of CS (per interface) */
Chris Packham4bf81db2018-12-03 14:26:49 +1300604 cs_num = mv_ddr_cs_num_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100605 t2t = (cs_num == 1) ? 0 : 1;
606 }
607
608 CHECK_STATUS(ddr3_tip_if_write
609 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200610 DUNIT_CTRL_LOW_REG, t2t << 3,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100611 0x3 << 3));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100612 CHECK_STATUS(ddr3_tip_if_write
613 (dev_num, access_type, if_id,
614 DDR_TIMING_REG, 0x28 << 9, 0x3f << 9));
615 CHECK_STATUS(ddr3_tip_if_write
616 (dev_num, access_type, if_id,
617 DDR_TIMING_REG, 0xa << 21, 0xff << 21));
618
619 /* move the block to ddr3_tip_set_timing - end */
620 /* AUTO_ZQC_TIMING */
621 CHECK_STATUS(ddr3_tip_if_write
622 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200623 ZQC_CFG_REG, (AUTO_ZQC_TIMING | (2 << 20)),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100624 0x3fffff));
625 CHECK_STATUS(ddr3_tip_if_read
626 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200627 DRAM_PHY_CFG_REG, data_read, 0x30));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100628 data_value =
629 (data_read[if_id] == 0) ? (1 << 11) : 0;
630 CHECK_STATUS(ddr3_tip_if_write
631 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200632 DUNIT_CTRL_HIGH_REG, data_value,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100633 (1 << 11)));
634
635 /* Set Active control for ODT write transactions */
636 CHECK_STATUS(ddr3_tip_if_write
637 (dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200638 PARAM_NOT_CARE, 0x1494, g_odt_config,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100639 MASK_ALL_BITS));
Chris Packham1a07d212018-05-10 13:28:29 +1200640
641 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) == MV_TIP_REV_3) {
642 CHECK_STATUS(ddr3_tip_if_write
643 (dev_num, access_type, if_id,
644 0x14a8, 0x900, 0x900));
645 /* wa: controls control sub-phy outputs floating during self-refresh */
646 CHECK_STATUS(ddr3_tip_if_write
647 (dev_num, access_type, if_id,
648 0x16d0, 0, 0x8000));
649 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100650 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100651 }
652
653 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200654 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100655 CHECK_STATUS(ddr3_tip_rank_control(dev_num, if_id));
656
Chris Packham4bf81db2018-12-03 14:26:49 +1300657 if (init_cntr_prm->do_mrs_phy)
658 ddr3_tip_pad_inv();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100659
660 /* Pad calibration control - disable */
661 CHECK_STATUS(ddr3_tip_if_write
662 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200663 MAIN_PADS_CAL_MACH_CTRL_REG, 0x0, 0x1));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100664 CHECK_STATUS(ddr3_tip_if_write
665 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200666 MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100667 calibration_update_control << 3, 0x3 << 3));
668 }
669
Stefan Roese5ffceb82015-03-26 15:36:56 +0100670
671 if (delay_enable != 0) {
Chris Packham4bf81db2018-12-03 14:26:49 +1300672 adll_tap = MEGA / (mv_ddr_freq_get(freq) * 64);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100673 ddr3_tip_cmd_addr_init_delay(dev_num, adll_tap);
674 }
675
676 return MV_OK;
677}
678
679/*
Chris Packham1a07d212018-05-10 13:28:29 +1200680 * Rank Control Flow
Stefan Roese5ffceb82015-03-26 15:36:56 +0100681 */
Chris Packham1a07d212018-05-10 13:28:29 +1200682static int ddr3_tip_rev2_rank_control(u32 dev_num, u32 if_id)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100683{
Chris Packham1a07d212018-05-10 13:28:29 +1200684 u32 data_value = 0, bus_cnt = 0;
685 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
686 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100687
Chris Packham1a07d212018-05-10 13:28:29 +1200688 for (bus_cnt = 0; bus_cnt < octets_per_if_num; bus_cnt++) {
689 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
690 data_value |= tm->interface_params[if_id].as_bus_params[bus_cnt].
691 cs_bitmask;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100692
Chris Packham1a07d212018-05-10 13:28:29 +1200693 if (tm->interface_params[if_id].as_bus_params[bus_cnt].
694 mirror_enable_bitmask == 1) {
695 /*
696 * Check mirror_enable_bitmask
697 * If it is enabled, CS + 4 bit in a word to be '1'
698 */
699 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
700 cs_bitmask & 0x1) != 0) {
701 data_value |= tm->interface_params[if_id].
702 as_bus_params[bus_cnt].
703 mirror_enable_bitmask << 4;
704 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100705
Chris Packham1a07d212018-05-10 13:28:29 +1200706 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
707 cs_bitmask & 0x2) != 0) {
708 data_value |= tm->interface_params[if_id].
709 as_bus_params[bus_cnt].
710 mirror_enable_bitmask << 5;
711 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100712
Chris Packham1a07d212018-05-10 13:28:29 +1200713 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
714 cs_bitmask & 0x4) != 0) {
715 data_value |= tm->interface_params[if_id].
716 as_bus_params[bus_cnt].
717 mirror_enable_bitmask << 6;
718 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100719
Chris Packham1a07d212018-05-10 13:28:29 +1200720 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
721 cs_bitmask & 0x8) != 0) {
722 data_value |= tm->interface_params[if_id].
723 as_bus_params[bus_cnt].
724 mirror_enable_bitmask << 7;
725 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100726 }
727 }
728
Chris Packham1a07d212018-05-10 13:28:29 +1200729 CHECK_STATUS(ddr3_tip_if_write
730 (dev_num, ACCESS_TYPE_UNICAST, if_id, DDR3_RANK_CTRL_REG,
731 data_value, 0xff));
732
Stefan Roese5ffceb82015-03-26 15:36:56 +0100733 return MV_OK;
734}
735
Chris Packham1a07d212018-05-10 13:28:29 +1200736static int ddr3_tip_rev3_rank_control(u32 dev_num, u32 if_id)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100737{
738 u32 data_value = 0, bus_cnt;
Chris Packham1a07d212018-05-10 13:28:29 +1200739 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
740 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100741
Chris Packham1a07d212018-05-10 13:28:29 +1200742 for (bus_cnt = 1; bus_cnt < octets_per_if_num; bus_cnt++) {
743 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100744 if ((tm->interface_params[if_id].
745 as_bus_params[0].cs_bitmask !=
746 tm->interface_params[if_id].
747 as_bus_params[bus_cnt].cs_bitmask) ||
748 (tm->interface_params[if_id].
749 as_bus_params[0].mirror_enable_bitmask !=
750 tm->interface_params[if_id].
751 as_bus_params[bus_cnt].mirror_enable_bitmask))
752 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
753 ("WARNING:Wrong configuration for pup #%d CS mask and CS mirroring for all pups should be the same\n",
754 bus_cnt));
755 }
756
757 data_value |= tm->interface_params[if_id].
758 as_bus_params[0].cs_bitmask;
759 data_value |= tm->interface_params[if_id].
760 as_bus_params[0].mirror_enable_bitmask << 4;
761
762 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +1200763 (dev_num, ACCESS_TYPE_UNICAST, if_id, DDR3_RANK_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100764 data_value, 0xff));
765
766 return MV_OK;
767}
768
Chris Packham1a07d212018-05-10 13:28:29 +1200769static int ddr3_tip_rank_control(u32 dev_num, u32 if_id)
770{
771 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) == MV_TIP_REV_2)
772 return ddr3_tip_rev2_rank_control(dev_num, if_id);
773 else
774 return ddr3_tip_rev3_rank_control(dev_num, if_id);
775}
776
Stefan Roese5ffceb82015-03-26 15:36:56 +0100777/*
Chris Packham1a07d212018-05-10 13:28:29 +1200778 * Algorithm Parameters Validation
779 */
780int ddr3_tip_validate_algo_var(u32 value, u32 fail_value, char *var_name)
781{
782 if (value == fail_value) {
783 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
784 ("Error: %s is not initialized (Algo Components Validation)\n",
785 var_name));
786 return 0;
787 }
788
789 return 1;
790}
791
792int ddr3_tip_validate_algo_ptr(void *ptr, void *fail_value, char *ptr_name)
793{
794 if (ptr == fail_value) {
795 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
796 ("Error: %s is not initialized (Algo Components Validation)\n",
797 ptr_name));
798 return 0;
799 }
800
801 return 1;
802}
803
804int ddr3_tip_validate_algo_components(u8 dev_num)
805{
806 int status = 1;
807
808 /* Check DGL parameters*/
809 status &= ddr3_tip_validate_algo_var(ck_delay, PARAM_UNDEFINED, "ck_delay");
810 status &= ddr3_tip_validate_algo_var(phy_reg3_val, PARAM_UNDEFINED, "phy_reg3_val");
811 status &= ddr3_tip_validate_algo_var(g_rtt_nom, PARAM_UNDEFINED, "g_rtt_nom");
812 status &= ddr3_tip_validate_algo_var(g_dic, PARAM_UNDEFINED, "g_dic");
813 status &= ddr3_tip_validate_algo_var(odt_config, PARAM_UNDEFINED, "odt_config");
814 status &= ddr3_tip_validate_algo_var(g_zpri_data, PARAM_UNDEFINED, "g_zpri_data");
815 status &= ddr3_tip_validate_algo_var(g_znri_data, PARAM_UNDEFINED, "g_znri_data");
816 status &= ddr3_tip_validate_algo_var(g_zpri_ctrl, PARAM_UNDEFINED, "g_zpri_ctrl");
817 status &= ddr3_tip_validate_algo_var(g_znri_ctrl, PARAM_UNDEFINED, "g_znri_ctrl");
818 status &= ddr3_tip_validate_algo_var(g_zpodt_data, PARAM_UNDEFINED, "g_zpodt_data");
819 status &= ddr3_tip_validate_algo_var(g_znodt_data, PARAM_UNDEFINED, "g_znodt_data");
820 status &= ddr3_tip_validate_algo_var(g_zpodt_ctrl, PARAM_UNDEFINED, "g_zpodt_ctrl");
821 status &= ddr3_tip_validate_algo_var(g_znodt_ctrl, PARAM_UNDEFINED, "g_znodt_ctrl");
822
823 /* Check functions pointers */
824 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_dunit_mux_select_func,
825 NULL, "tip_dunit_mux_select_func");
826 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_dunit_write,
827 NULL, "mv_ddr_dunit_write");
828 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_dunit_read,
829 NULL, "mv_ddr_dunit_read");
830 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_phy_write,
831 NULL, "mv_ddr_phy_write");
832 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_phy_read,
833 NULL, "mv_ddr_phy_read");
834 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_get_freq_config_info_func,
835 NULL, "tip_get_freq_config_info_func");
836 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_set_freq_divider_func,
837 NULL, "tip_set_freq_divider_func");
838 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_get_clock_ratio,
839 NULL, "tip_get_clock_ratio");
840
841 status &= ddr3_tip_validate_algo_ptr(dq_map_table, NULL, "dq_map_table");
842 status &= ddr3_tip_validate_algo_var(dfs_low_freq, 0, "dfs_low_freq");
843
844 return (status == 1) ? MV_OK : MV_NOT_INITIALIZED;
845}
846
847
848int ddr3_pre_algo_config(void)
849{
850 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
851
852 /* Set Bus3 ECC training mode */
853 if (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask)) {
854 /* Set Bus3 ECC MUX */
855 CHECK_STATUS(ddr3_tip_if_write
856 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
857 DRAM_PINS_MUX_REG, 0x100, 0x100));
858 }
859
860 /* Set regular ECC training mode (bus4 and bus 3) */
861 if ((DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask)) ||
862 (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask)) ||
863 (DDR3_IS_ECC_PUP8_MODE(tm->bus_act_mask))) {
864 /* Enable ECC Write MUX */
865 CHECK_STATUS(ddr3_tip_if_write
866 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
867 TRAINING_SW_2_REG, 0x100, 0x100));
868 /* General ECC enable */
869 CHECK_STATUS(ddr3_tip_if_write
870 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
871 SDRAM_CFG_REG, 0x40000, 0x40000));
872 /* Disable Read Data ECC MUX */
873 CHECK_STATUS(ddr3_tip_if_write
874 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
875 TRAINING_SW_2_REG, 0x0, 0x2));
876 }
877
878 return MV_OK;
879}
880
881int ddr3_post_algo_config(void)
882{
883 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
884 int status;
885
886 status = ddr3_post_run_alg();
887 if (MV_OK != status) {
888 printf("DDR3 Post Run Alg - FAILED 0x%x\n", status);
889 return status;
890 }
891
892 /* Un_set ECC training mode */
893 if ((DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask)) ||
894 (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask)) ||
895 (DDR3_IS_ECC_PUP8_MODE(tm->bus_act_mask))) {
896 /* Disable ECC Write MUX */
897 CHECK_STATUS(ddr3_tip_if_write
898 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
899 TRAINING_SW_2_REG, 0x0, 0x100));
900 /* General ECC and Bus3 ECC MUX remains enabled */
901 }
902
903 return MV_OK;
904}
905
906/*
Stefan Roese5ffceb82015-03-26 15:36:56 +0100907 * Run Training Flow
908 */
909int hws_ddr3_tip_run_alg(u32 dev_num, enum hws_algo_type algo_type)
910{
Chris Packham1a07d212018-05-10 13:28:29 +1200911 int status = MV_OK;
912
913 status = ddr3_pre_algo_config();
914 if (MV_OK != status) {
915 printf("DDR3 Pre Algo Config - FAILED 0x%x\n", status);
916 return status;
917 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100918
919#ifdef ODT_TEST_SUPPORT
920 if (finger_test == 1)
921 return odt_test(dev_num, algo_type);
922#endif
923
924 if (algo_type == ALGO_TYPE_DYNAMIC) {
Chris Packham1a07d212018-05-10 13:28:29 +1200925 status = ddr3_tip_ddr3_auto_tune(dev_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100926 }
927
Chris Packham1a07d212018-05-10 13:28:29 +1200928 if (status != MV_OK) {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100929 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
Chris Packham1a07d212018-05-10 13:28:29 +1200930 ("******** DRAM initialization Failed (res 0x%x) ********\n",
931 status));
932 return status;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100933 }
934
Chris Packham1a07d212018-05-10 13:28:29 +1200935 status = ddr3_post_algo_config();
936 if (MV_OK != status) {
937 printf("DDR3 Post Algo Config - FAILED 0x%x\n", status);
938 return status;
939 }
940
941 return status;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100942}
943
944#ifdef ODT_TEST_SUPPORT
945/*
946 * ODT Test
947 */
948static int odt_test(u32 dev_num, enum hws_algo_type algo_type)
949{
950 int ret = MV_OK, ret_tune = MV_OK;
951 int pfinger_val = 0, nfinger_val;
952
953 for (pfinger_val = p_finger_start; pfinger_val <= p_finger_end;
954 pfinger_val += p_finger_step) {
955 for (nfinger_val = n_finger_start; nfinger_val <= n_finger_end;
956 nfinger_val += n_finger_step) {
957 if (finger_test != 0) {
958 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
959 ("pfinger_val %d nfinger_val %d\n",
960 pfinger_val, nfinger_val));
Chris Packham1a07d212018-05-10 13:28:29 +1200961 /*
962 * TODO: need to check the correctness
963 * of the following two lines.
964 */
965 g_zpodt_data = pfinger_val;
966 g_znodt_data = nfinger_val;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100967 }
968
969 if (algo_type == ALGO_TYPE_DYNAMIC) {
970 ret = ddr3_tip_ddr3_auto_tune(dev_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100971 }
972 }
973 }
974
975 if (ret_tune != MV_OK) {
976 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
977 ("Run_alg: tuning failed %d\n", ret_tune));
978 ret = (ret == MV_OK) ? ret_tune : ret;
979 }
980
981 return ret;
982}
983#endif
984
985/*
986 * Select Controller
987 */
988int hws_ddr3_tip_select_ddr_controller(u32 dev_num, int enable)
989{
Chris Packham1a07d212018-05-10 13:28:29 +1200990 return config_func_info[dev_num].
991 tip_dunit_mux_select_func((u8)dev_num, enable);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100992}
993
994/*
995 * Dunit Register Write
996 */
997int ddr3_tip_if_write(u32 dev_num, enum hws_access_type interface_access,
998 u32 if_id, u32 reg_addr, u32 data_value, u32 mask)
999{
Chris Packham1a07d212018-05-10 13:28:29 +12001000 config_func_info[dev_num].mv_ddr_dunit_write(reg_addr, mask, data_value);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001001
Chris Packham1a07d212018-05-10 13:28:29 +12001002 return MV_OK;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001003}
1004
1005/*
1006 * Dunit Register Read
1007 */
1008int ddr3_tip_if_read(u32 dev_num, enum hws_access_type interface_access,
1009 u32 if_id, u32 reg_addr, u32 *data, u32 mask)
1010{
Chris Packham1a07d212018-05-10 13:28:29 +12001011 config_func_info[dev_num].mv_ddr_dunit_read(reg_addr, mask, data);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001012
Chris Packham1a07d212018-05-10 13:28:29 +12001013 return MV_OK;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001014}
1015
1016/*
1017 * Dunit Register Polling
1018 */
1019int ddr3_tip_if_polling(u32 dev_num, enum hws_access_type access_type,
1020 u32 if_id, u32 exp_value, u32 mask, u32 offset,
1021 u32 poll_tries)
1022{
1023 u32 poll_cnt = 0, interface_num = 0, start_if, end_if;
1024 u32 read_data[MAX_INTERFACE_NUM];
1025 int ret;
1026 int is_fail = 0, is_if_fail;
Chris Packham1a07d212018-05-10 13:28:29 +12001027 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001028
1029 if (access_type == ACCESS_TYPE_MULTICAST) {
1030 start_if = 0;
1031 end_if = MAX_INTERFACE_NUM - 1;
1032 } else {
1033 start_if = if_id;
1034 end_if = if_id;
1035 }
1036
1037 for (interface_num = start_if; interface_num <= end_if; interface_num++) {
1038 /* polling bit 3 for n times */
Chris Packham1a07d212018-05-10 13:28:29 +12001039 VALIDATE_IF_ACTIVE(tm->if_act_mask, interface_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001040
1041 is_if_fail = 0;
1042 for (poll_cnt = 0; poll_cnt < poll_tries; poll_cnt++) {
1043 ret =
1044 ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST,
1045 interface_num, offset, read_data,
1046 mask);
1047 if (ret != MV_OK)
1048 return ret;
1049
1050 if (read_data[interface_num] == exp_value)
1051 break;
1052 }
1053
1054 if (poll_cnt >= poll_tries) {
1055 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1056 ("max poll IF #%d\n", interface_num));
1057 is_fail = 1;
1058 is_if_fail = 1;
1059 }
1060
1061 training_result[training_stage][interface_num] =
1062 (is_if_fail == 1) ? TEST_FAILED : TEST_SUCCESS;
1063 }
1064
1065 return (is_fail == 0) ? MV_OK : MV_FAIL;
1066}
1067
1068/*
1069 * Bus read access
1070 */
1071int ddr3_tip_bus_read(u32 dev_num, u32 if_id,
1072 enum hws_access_type phy_access, u32 phy_id,
1073 enum hws_ddr_phy phy_type, u32 reg_addr, u32 *data)
1074{
Chris Packham1a07d212018-05-10 13:28:29 +12001075 return config_func_info[dev_num].
1076 mv_ddr_phy_read(phy_access, phy_id, phy_type, reg_addr, data);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001077}
1078
1079/*
1080 * Bus write access
1081 */
1082int ddr3_tip_bus_write(u32 dev_num, enum hws_access_type interface_access,
1083 u32 if_id, enum hws_access_type phy_access,
1084 u32 phy_id, enum hws_ddr_phy phy_type, u32 reg_addr,
1085 u32 data_value)
1086{
Chris Packham1a07d212018-05-10 13:28:29 +12001087 return config_func_info[dev_num].
1088 mv_ddr_phy_write(phy_access, phy_id, phy_type, reg_addr, data_value, OPERATION_WRITE);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001089}
1090
Stefan Roese5ffceb82015-03-26 15:36:56 +01001091
1092/*
Stefan Roese5ffceb82015-03-26 15:36:56 +01001093 * Phy read-modify-write
1094 */
1095int ddr3_tip_bus_read_modify_write(u32 dev_num, enum hws_access_type access_type,
1096 u32 interface_id, u32 phy_id,
1097 enum hws_ddr_phy phy_type, u32 reg_addr,
1098 u32 data_value, u32 reg_mask)
1099{
1100 u32 data_val = 0, if_id, start_if, end_if;
Chris Packham1a07d212018-05-10 13:28:29 +12001101 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001102
1103 if (access_type == ACCESS_TYPE_MULTICAST) {
1104 start_if = 0;
1105 end_if = MAX_INTERFACE_NUM - 1;
1106 } else {
1107 start_if = interface_id;
1108 end_if = interface_id;
1109 }
1110
1111 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001112 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001113 CHECK_STATUS(ddr3_tip_bus_read
1114 (dev_num, if_id, ACCESS_TYPE_UNICAST, phy_id,
1115 phy_type, reg_addr, &data_val));
1116 data_value = (data_val & (~reg_mask)) | (data_value & reg_mask);
1117 CHECK_STATUS(ddr3_tip_bus_write
1118 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1119 ACCESS_TYPE_UNICAST, phy_id, phy_type, reg_addr,
1120 data_value));
1121 }
1122
1123 return MV_OK;
1124}
1125
1126/*
1127 * ADLL Calibration
1128 */
1129int adll_calibration(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +13001130 u32 if_id, enum mv_ddr_freq frequency)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001131{
1132 struct hws_tip_freq_config_info freq_config_info;
1133 u32 bus_cnt = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001134 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1135 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001136
1137 /* Reset Diver_b assert -> de-assert */
1138 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001139 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001140 0, 0x10000000));
1141 mdelay(10);
1142 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001143 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001144 0x10000000, 0x10000000));
1145
Chris Packham1a07d212018-05-10 13:28:29 +12001146 CHECK_STATUS(config_func_info[dev_num].
1147 tip_get_freq_config_info_func((u8)dev_num, frequency,
1148 &freq_config_info));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001149
Chris Packham1a07d212018-05-10 13:28:29 +12001150 for (bus_cnt = 0; bus_cnt < octets_per_if_num; bus_cnt++) {
1151 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001152 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1153 (dev_num, access_type, if_id, bus_cnt,
Chris Packham1a07d212018-05-10 13:28:29 +12001154 DDR_PHY_DATA, ADLL_CFG0_PHY_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001155 freq_config_info.bw_per_freq << 8, 0x700));
1156 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1157 (dev_num, access_type, if_id, bus_cnt,
Chris Packham1a07d212018-05-10 13:28:29 +12001158 DDR_PHY_DATA, ADLL_CFG2_PHY_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001159 freq_config_info.rate_per_freq, 0x7));
1160 }
1161
Chris Packham1a07d212018-05-10 13:28:29 +12001162 for (bus_cnt = 0; bus_cnt < DDR_IF_CTRL_SUBPHYS_NUM; bus_cnt++) {
1163 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1164 (dev_num, ACCESS_TYPE_UNICAST, if_id, bus_cnt,
1165 DDR_PHY_CONTROL, ADLL_CFG0_PHY_REG,
1166 freq_config_info.bw_per_freq << 8, 0x700));
1167 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1168 (dev_num, ACCESS_TYPE_UNICAST, if_id, bus_cnt,
1169 DDR_PHY_CONTROL, ADLL_CFG2_PHY_REG,
1170 freq_config_info.rate_per_freq, 0x7));
1171 }
1172
Stefan Roese5ffceb82015-03-26 15:36:56 +01001173 /* DUnit to Phy drive post edge, ADLL reset assert de-assert */
1174 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001175 (dev_num, access_type, if_id, DRAM_PHY_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001176 0, (0x80000000 | 0x40000000)));
Chris Packham4bf81db2018-12-03 14:26:49 +13001177 mdelay(100 / (mv_ddr_freq_get(frequency)) / mv_ddr_freq_get(MV_DDR_FREQ_LOW_FREQ));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001178 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001179 (dev_num, access_type, if_id, DRAM_PHY_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001180 (0x80000000 | 0x40000000), (0x80000000 | 0x40000000)));
1181
1182 /* polling for ADLL Done */
1183 if (ddr3_tip_if_polling(dev_num, access_type, if_id,
1184 0x3ff03ff, 0x3ff03ff, PHY_LOCK_STATUS_REG,
1185 MAX_POLLING_ITERATIONS) != MV_OK) {
1186 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1187 ("Freq_set: DDR3 poll failed(1)"));
1188 }
1189
1190 /* pup data_pup reset assert-> deassert */
1191 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001192 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001193 0, 0x60000000));
1194 mdelay(10);
1195 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001196 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001197 0x60000000, 0x60000000));
1198
1199 return MV_OK;
1200}
1201
1202int ddr3_tip_freq_set(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +13001203 u32 if_id, enum mv_ddr_freq frequency)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001204{
1205 u32 cl_value = 0, cwl_value = 0, mem_mask = 0, val = 0,
Chris Packham1a07d212018-05-10 13:28:29 +12001206 bus_cnt = 0, t_wr = 0, t_ckclk = 0,
1207 cnt_id;
1208 u32 end_if, start_if;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001209 u32 bus_index = 0;
1210 int is_dll_off = 0;
Chris Packham4bf81db2018-12-03 14:26:49 +13001211 enum mv_ddr_speed_bin speed_bin_index = 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001212 struct hws_tip_freq_config_info freq_config_info;
1213 enum hws_result *flow_result = training_result[training_stage];
1214 u32 adll_tap = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001215 u32 cs_num;
1216 u32 t2t;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001217 u32 cs_mask[MAX_INTERFACE_NUM];
Chris Packham1a07d212018-05-10 13:28:29 +12001218 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1219 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
1220 unsigned int tclk;
Chris Packham3a09e132018-05-10 13:28:30 +12001221 enum mv_ddr_timing timing = tm->interface_params[if_id].timing;
Chris Packham4bf81db2018-12-03 14:26:49 +13001222 u32 freq = mv_ddr_freq_get(frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001223
1224 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
1225 ("dev %d access %d IF %d freq %d\n", dev_num,
1226 access_type, if_id, frequency));
1227
Chris Packham4bf81db2018-12-03 14:26:49 +13001228 if (frequency == MV_DDR_FREQ_LOW_FREQ)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001229 is_dll_off = 1;
1230 if (access_type == ACCESS_TYPE_MULTICAST) {
1231 start_if = 0;
1232 end_if = MAX_INTERFACE_NUM - 1;
1233 } else {
1234 start_if = if_id;
1235 end_if = if_id;
1236 }
1237
1238 /* calculate interface cs mask - Oferb 4/11 */
1239 /* speed bin can be different for each interface */
1240 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
1241 /* cs enable is active low */
Chris Packham1a07d212018-05-10 13:28:29 +12001242 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001243 cs_mask[if_id] = CS_BIT_MASK;
1244 training_result[training_stage][if_id] = TEST_SUCCESS;
1245 ddr3_tip_calc_cs_mask(dev_num, if_id, effective_cs,
1246 &cs_mask[if_id]);
1247 }
1248
1249 /* speed bin can be different for each interface */
1250 /*
1251 * moti b - need to remove the loop for multicas access functions
1252 * and loop the unicast access functions
1253 */
1254 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001255 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001256
1257 flow_result[if_id] = TEST_SUCCESS;
1258 speed_bin_index =
1259 tm->interface_params[if_id].speed_bin_index;
1260 if (tm->interface_params[if_id].memory_freq ==
1261 frequency) {
1262 cl_value =
1263 tm->interface_params[if_id].cas_l;
1264 cwl_value =
1265 tm->interface_params[if_id].cas_wl;
Chris Packham1a07d212018-05-10 13:28:29 +12001266 } else if (tm->cfg_src == MV_DDR_CFG_SPD) {
Chris Packham4bf81db2018-12-03 14:26:49 +13001267 tclk = 1000000 / freq;
Chris Packham1a07d212018-05-10 13:28:29 +12001268 cl_value = mv_ddr_cl_calc(tm->timing_data[MV_DDR_TAA_MIN], tclk);
1269 if (cl_value == 0) {
1270 printf("mv_ddr: unsupported cas latency value found\n");
1271 return MV_FAIL;
1272 }
1273 cwl_value = mv_ddr_cwl_calc(tclk);
1274 if (cwl_value == 0) {
1275 printf("mv_ddr: unsupported cas write latency value found\n");
1276 return MV_FAIL;
1277 }
Stefan Roese5ffceb82015-03-26 15:36:56 +01001278 } else {
Chris Packham4bf81db2018-12-03 14:26:49 +13001279 cl_value = mv_ddr_cl_val_get(speed_bin_index, frequency);
1280 cwl_value = mv_ddr_cwl_val_get(speed_bin_index, frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001281 }
1282
1283 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
1284 ("Freq_set dev 0x%x access 0x%x if 0x%x freq 0x%x speed %d:\n\t",
1285 dev_num, access_type, if_id,
1286 frequency, speed_bin_index));
1287
Chris Packham4bf81db2018-12-03 14:26:49 +13001288 for (cnt_id = 0; cnt_id < MV_DDR_FREQ_LAST; cnt_id++) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01001289 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
Chris Packham4bf81db2018-12-03 14:26:49 +13001290 ("%d ", mv_ddr_cl_val_get(speed_bin_index, cnt_id)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001291 }
1292
1293 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE, ("\n"));
1294 mem_mask = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001295 for (bus_index = 0; bus_index < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001296 bus_index++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001297 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_index);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001298 mem_mask |=
1299 tm->interface_params[if_id].
1300 as_bus_params[bus_index].mirror_enable_bitmask;
1301 }
1302
1303 if (mem_mask != 0) {
Chris Packham1a07d212018-05-10 13:28:29 +12001304 /* motib redundent in KW28 */
Stefan Roese5ffceb82015-03-26 15:36:56 +01001305 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1306 if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001307 DUAL_DUNIT_CFG_REG, 0, 0x8));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001308 }
1309
1310 /* dll state after exiting SR */
1311 if (is_dll_off == 1) {
1312 CHECK_STATUS(ddr3_tip_if_write
1313 (dev_num, access_type, if_id,
1314 DFS_REG, 0x1, 0x1));
1315 } else {
1316 CHECK_STATUS(ddr3_tip_if_write
1317 (dev_num, access_type, if_id,
1318 DFS_REG, 0, 0x1));
1319 }
1320
1321 CHECK_STATUS(ddr3_tip_if_write
1322 (dev_num, access_type, if_id,
1323 DUNIT_MMASK_REG, 0, 0x1));
1324 /* DFS - block transactions */
1325 CHECK_STATUS(ddr3_tip_if_write
1326 (dev_num, access_type, if_id,
1327 DFS_REG, 0x2, 0x2));
1328
1329 /* disable ODT in case of dll off */
1330 if (is_dll_off == 1) {
1331 CHECK_STATUS(ddr3_tip_if_write
1332 (dev_num, access_type, if_id,
1333 0x1874, 0, 0x244));
1334 CHECK_STATUS(ddr3_tip_if_write
1335 (dev_num, access_type, if_id,
1336 0x1884, 0, 0x244));
1337 CHECK_STATUS(ddr3_tip_if_write
1338 (dev_num, access_type, if_id,
1339 0x1894, 0, 0x244));
1340 CHECK_STATUS(ddr3_tip_if_write
1341 (dev_num, access_type, if_id,
1342 0x18a4, 0, 0x244));
1343 }
1344
1345 /* DFS - Enter Self-Refresh */
1346 CHECK_STATUS(ddr3_tip_if_write
1347 (dev_num, access_type, if_id, DFS_REG, 0x4,
1348 0x4));
1349 /* polling on self refresh entry */
1350 if (ddr3_tip_if_polling(dev_num, ACCESS_TYPE_UNICAST,
1351 if_id, 0x8, 0x8, DFS_REG,
1352 MAX_POLLING_ITERATIONS) != MV_OK) {
1353 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1354 ("Freq_set: DDR3 poll failed on SR entry\n"));
1355 }
1356
Chris Packham1a07d212018-05-10 13:28:29 +12001357 /* Calculate 2T mode */
1358 if (mode_2t != 0xff) {
1359 t2t = mode_2t;
Chris Packham3a09e132018-05-10 13:28:30 +12001360 } else if (timing != MV_DDR_TIM_DEFAULT) {
1361 t2t = (timing == MV_DDR_TIM_2T) ? 1 : 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001362 } else {
1363 /* Calculate number of CS per interface */
Chris Packham4bf81db2018-12-03 14:26:49 +13001364 cs_num = mv_ddr_cs_num_get();
Chris Packham1a07d212018-05-10 13:28:29 +12001365 t2t = (cs_num == 1) ? 0 : 1;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001366 }
1367
Stefan Roese5ffceb82015-03-26 15:36:56 +01001368
Chris Packham1a07d212018-05-10 13:28:29 +12001369 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_INTERLEAVE_WA) == 1) {
1370 /* Use 1T mode if 1:1 ratio configured */
1371 if (config_func_info[dev_num].tip_get_clock_ratio(frequency) == 1) {
1372 /* Low freq*/
1373 CHECK_STATUS(ddr3_tip_if_write
1374 (dev_num, access_type, if_id,
1375 SDRAM_OPEN_PAGES_CTRL_REG, 0x0, 0x3C0));
1376 t2t = 0;
1377 } else {
1378 /* Middle or target freq */
1379 CHECK_STATUS(ddr3_tip_if_write
1380 (dev_num, access_type, if_id,
1381 SDRAM_OPEN_PAGES_CTRL_REG, 0x3C0, 0x3C0));
1382 }
1383 }
1384 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
1385 DUNIT_CTRL_LOW_REG, t2t << 3, 0x3 << 3));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001386
Chris Packham1a07d212018-05-10 13:28:29 +12001387 /* PLL configuration */
1388 config_func_info[dev_num].tip_set_freq_divider_func(dev_num, if_id,
1389 frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001390
1391 /* DFS - CL/CWL/WR parameters after exiting SR */
1392 CHECK_STATUS(ddr3_tip_if_write
1393 (dev_num, access_type, if_id, DFS_REG,
1394 (cl_mask_table[cl_value] << 8), 0xf00));
1395 CHECK_STATUS(ddr3_tip_if_write
1396 (dev_num, access_type, if_id, DFS_REG,
1397 (cwl_mask_table[cwl_value] << 12), 0x7000));
Chris Packham5450f0c2018-01-18 17:16:10 +13001398
Chris Packham4bf81db2018-12-03 14:26:49 +13001399 t_ckclk = (MEGA / freq);
1400 t_wr = time_to_nclk(mv_ddr_speed_bin_timing_get
Chris Packham1a07d212018-05-10 13:28:29 +12001401 (speed_bin_index,
1402 SPEED_BIN_TWR), t_ckclk);
Chris Packham5450f0c2018-01-18 17:16:10 +13001403
Stefan Roese5ffceb82015-03-26 15:36:56 +01001404 CHECK_STATUS(ddr3_tip_if_write
1405 (dev_num, access_type, if_id, DFS_REG,
Chris Packham1a07d212018-05-10 13:28:29 +12001406 (twr_mask_table[t_wr] << 16), 0x70000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001407
1408 /* Restore original RTT values if returning from DLL OFF mode */
1409 if (is_dll_off == 1) {
1410 CHECK_STATUS(ddr3_tip_if_write
1411 (dev_num, access_type, if_id, 0x1874,
1412 g_dic | g_rtt_nom, 0x266));
1413 CHECK_STATUS(ddr3_tip_if_write
1414 (dev_num, access_type, if_id, 0x1884,
1415 g_dic | g_rtt_nom, 0x266));
1416 CHECK_STATUS(ddr3_tip_if_write
1417 (dev_num, access_type, if_id, 0x1894,
1418 g_dic | g_rtt_nom, 0x266));
1419 CHECK_STATUS(ddr3_tip_if_write
1420 (dev_num, access_type, if_id, 0x18a4,
1421 g_dic | g_rtt_nom, 0x266));
1422 }
1423
Chris Packham1a07d212018-05-10 13:28:29 +12001424 /* Reset divider_b assert -> de-assert */
Stefan Roese5ffceb82015-03-26 15:36:56 +01001425 CHECK_STATUS(ddr3_tip_if_write
1426 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001427 SDRAM_CFG_REG, 0, 0x10000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001428 mdelay(10);
1429 CHECK_STATUS(ddr3_tip_if_write
1430 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001431 SDRAM_CFG_REG, 0x10000000, 0x10000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001432
Chris Packham1a07d212018-05-10 13:28:29 +12001433 /* ADLL configuration function of process and frequency */
1434 CHECK_STATUS(config_func_info[dev_num].
1435 tip_get_freq_config_info_func(dev_num, frequency,
1436 &freq_config_info));
1437
Stefan Roese5ffceb82015-03-26 15:36:56 +01001438 /* TBD check milo5 using device ID ? */
Chris Packham1a07d212018-05-10 13:28:29 +12001439 for (bus_cnt = 0; bus_cnt < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001440 bus_cnt++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001441 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001442 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1443 (dev_num, ACCESS_TYPE_UNICAST,
1444 if_id, bus_cnt, DDR_PHY_DATA,
1445 0x92,
1446 freq_config_info.
1447 bw_per_freq << 8
1448 /*freq_mask[dev_num][frequency] << 8 */
1449 , 0x700));
1450 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1451 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1452 bus_cnt, DDR_PHY_DATA, 0x94,
1453 freq_config_info.rate_per_freq, 0x7));
1454 }
1455
Chris Packham1a07d212018-05-10 13:28:29 +12001456 /* Dunit to PHY drive post edge, ADLL reset assert -> de-assert */
Stefan Roese5ffceb82015-03-26 15:36:56 +01001457 CHECK_STATUS(ddr3_tip_if_write
1458 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001459 DRAM_PHY_CFG_REG, 0,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001460 (0x80000000 | 0x40000000)));
Chris Packham4bf81db2018-12-03 14:26:49 +13001461 mdelay(100 / (freq / mv_ddr_freq_get(MV_DDR_FREQ_LOW_FREQ)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001462 CHECK_STATUS(ddr3_tip_if_write
1463 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001464 DRAM_PHY_CFG_REG, (0x80000000 | 0x40000000),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001465 (0x80000000 | 0x40000000)));
1466
1467 /* polling for ADLL Done */
1468 if (ddr3_tip_if_polling
1469 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0x3ff03ff,
1470 0x3ff03ff, PHY_LOCK_STATUS_REG,
1471 MAX_POLLING_ITERATIONS) != MV_OK) {
1472 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1473 ("Freq_set: DDR3 poll failed(1)\n"));
1474 }
1475
1476 /* pup data_pup reset assert-> deassert */
1477 CHECK_STATUS(ddr3_tip_if_write
1478 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001479 SDRAM_CFG_REG, 0, 0x60000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001480 mdelay(10);
1481 CHECK_STATUS(ddr3_tip_if_write
1482 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001483 SDRAM_CFG_REG, 0x60000000, 0x60000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001484
1485 /* Set proper timing params before existing Self-Refresh */
1486 ddr3_tip_set_timing(dev_num, access_type, if_id, frequency);
1487 if (delay_enable != 0) {
Chris Packham4bf81db2018-12-03 14:26:49 +13001488 adll_tap = (is_dll_off == 1) ? 1000 : (MEGA / (freq * 64));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001489 ddr3_tip_cmd_addr_init_delay(dev_num, adll_tap);
1490 }
1491
1492 /* Exit SR */
1493 CHECK_STATUS(ddr3_tip_if_write
1494 (dev_num, access_type, if_id, DFS_REG, 0,
1495 0x4));
1496 if (ddr3_tip_if_polling
1497 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0, 0x8, DFS_REG,
1498 MAX_POLLING_ITERATIONS) != MV_OK) {
1499 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1500 ("Freq_set: DDR3 poll failed(2)"));
1501 }
1502
1503 /* Refresh Command */
1504 CHECK_STATUS(ddr3_tip_if_write
1505 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001506 SDRAM_OP_REG, 0x2, 0xf1f));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001507 if (ddr3_tip_if_polling
1508 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0, 0x1f,
Chris Packham1a07d212018-05-10 13:28:29 +12001509 SDRAM_OP_REG, MAX_POLLING_ITERATIONS) != MV_OK) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01001510 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1511 ("Freq_set: DDR3 poll failed(3)"));
1512 }
1513
1514 /* Release DFS Block */
1515 CHECK_STATUS(ddr3_tip_if_write
1516 (dev_num, access_type, if_id, DFS_REG, 0,
1517 0x2));
1518 /* Controller to MBUS Retry - normal */
1519 CHECK_STATUS(ddr3_tip_if_write
1520 (dev_num, access_type, if_id, DUNIT_MMASK_REG,
1521 0x1, 0x1));
1522
1523 /* MRO: Burst Length 8, CL , Auto_precharge 0x16cc */
1524 val =
1525 ((cl_mask_table[cl_value] & 0x1) << 2) |
1526 ((cl_mask_table[cl_value] & 0xe) << 3);
1527 CHECK_STATUS(ddr3_tip_if_write
1528 (dev_num, access_type, if_id, MR0_REG,
1529 val, (0x7 << 4) | (1 << 2)));
1530 /* MR2: CWL = 10 , Auto Self-Refresh - disable */
Chris Packham1a07d212018-05-10 13:28:29 +12001531 val = (cwl_mask_table[cwl_value] << 3) | g_rtt_wr;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001532 /*
1533 * nklein 24.10.13 - should not be here - leave value as set in
1534 * the init configuration val |= (1 << 9);
1535 * val |= ((tm->interface_params[if_id].
Chris Packham1a07d212018-05-10 13:28:29 +12001536 * interface_temp == MV_DDR_TEMP_HIGH) ? (1 << 7) : 0);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001537 */
1538 /* nklein 24.10.13 - see above comment */
1539 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1540 if_id, MR2_REG,
Chris Packham1a07d212018-05-10 13:28:29 +12001541 val, (0x7 << 3) | (0x3 << 9)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001542
1543 /* ODT TIMING */
1544 val = ((cl_value - cwl_value + 1) << 4) |
1545 ((cl_value - cwl_value + 6) << 8) |
1546 ((cl_value - 1) << 12) | ((cl_value + 6) << 16);
1547 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
Chris Packham1a07d212018-05-10 13:28:29 +12001548 if_id, DDR_ODT_TIMING_LOW_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001549 val, 0xffff0));
Chris Packhamae806142018-01-18 17:16:07 +13001550 val = 0x91 | ((cwl_value - 1) << 8) | ((cwl_value + 5) << 12);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001551 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
Chris Packham1a07d212018-05-10 13:28:29 +12001552 if_id, DDR_ODT_TIMING_HIGH_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001553 val, 0xffff));
1554
Chris Packham1a07d212018-05-10 13:28:29 +12001555 /* in case of ddr4 need to set the receiver to odt always 'on' (odt_config = '0')
1556 * in case of ddr3 configure the odt through the timing
1557 */
1558 if (odt_config != 0) {
1559 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id, DUNIT_ODT_CTRL_REG, 0xf, 0xf));
1560 }
1561 else {
1562 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id, DUNIT_ODT_CTRL_REG,
1563 0x30f, 0x30f));
1564 }
Stefan Roese5ffceb82015-03-26 15:36:56 +01001565
1566 /* re-write CL */
1567 val = ((cl_mask_table[cl_value] & 0x1) << 2) |
1568 ((cl_mask_table[cl_value] & 0xe) << 3);
Chris Packham1a07d212018-05-10 13:28:29 +12001569
1570 CHECK_STATUS(ddr3_tip_write_mrs_cmd(dev_num, cs_mask, MR_CMD0,
1571 val, (0x7 << 4) | (0x1 << 2)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001572
1573 /* re-write CWL */
Chris Packham1a07d212018-05-10 13:28:29 +12001574 val = (cwl_mask_table[cwl_value] << 3) | g_rtt_wr;
1575 CHECK_STATUS(ddr3_tip_write_mrs_cmd(dev_num, cs_mask, MR_CMD2,
1576 val, (0x7 << 3) | (0x3 << 9)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001577
1578 if (mem_mask != 0) {
1579 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1580 if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001581 DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001582 1 << 3, 0x8));
1583 }
1584 }
1585
1586 return MV_OK;
1587}
1588
1589/*
1590 * Set ODT values
1591 */
1592static int ddr3_tip_write_odt(u32 dev_num, enum hws_access_type access_type,
1593 u32 if_id, u32 cl_value, u32 cwl_value)
1594{
1595 /* ODT TIMING */
1596 u32 val = (cl_value - cwl_value + 6);
1597
1598 val = ((cl_value - cwl_value + 1) << 4) | ((val & 0xf) << 8) |
1599 (((cl_value - 1) & 0xf) << 12) |
1600 (((cl_value + 6) & 0xf) << 16) | (((val & 0x10) >> 4) << 21);
1601 val |= (((cl_value - 1) >> 4) << 22) | (((cl_value + 6) >> 4) << 23);
1602
1603 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001604 DDR_ODT_TIMING_LOW_REG, val, 0xffff0));
Chris Packhamae806142018-01-18 17:16:07 +13001605 val = 0x91 | ((cwl_value - 1) << 8) | ((cwl_value + 5) << 12);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001606 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001607 DDR_ODT_TIMING_HIGH_REG, val, 0xffff));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001608 if (odt_additional == 1) {
1609 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1610 if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001611 SDRAM_ODT_CTRL_HIGH_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001612 0xf, 0xf));
1613 }
1614
1615 /* ODT Active */
1616 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001617 DUNIT_ODT_CTRL_REG, 0xf, 0xf));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001618
1619 return MV_OK;
1620}
1621
1622/*
1623 * Set Timing values for training
1624 */
1625static int ddr3_tip_set_timing(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +13001626 u32 if_id, enum mv_ddr_freq frequency)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001627{
1628 u32 t_ckclk = 0, t_ras = 0;
1629 u32 t_rcd = 0, t_rp = 0, t_wr = 0, t_wtr = 0, t_rrd = 0, t_rtp = 0,
Chris Packham1a07d212018-05-10 13:28:29 +12001630 t_rfc = 0, t_mod = 0, t_r2r = 0x3, t_r2r_high = 0,
1631 t_r2w_w2r = 0x3, t_r2w_w2r_high = 0x1, t_w2w = 0x3;
1632 u32 refresh_interval_cnt, t_hclk, t_refi, t_faw, t_pd, t_xpdll;
1633 u32 val = 0, page_size = 0, mask = 0;
Chris Packham4bf81db2018-12-03 14:26:49 +13001634 enum mv_ddr_speed_bin speed_bin_index;
Chris Packham1a07d212018-05-10 13:28:29 +12001635 enum mv_ddr_die_capacity memory_size = MV_DDR_DIE_CAP_2GBIT;
1636 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Chris Packham4bf81db2018-12-03 14:26:49 +13001637 u32 freq = mv_ddr_freq_get(frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001638
1639 speed_bin_index = tm->interface_params[if_id].speed_bin_index;
1640 memory_size = tm->interface_params[if_id].memory_size;
Chris Packham4bf81db2018-12-03 14:26:49 +13001641 page_size = mv_ddr_page_size_get(tm->interface_params[if_id].bus_width, memory_size);
1642 t_ckclk = (MEGA / freq);
Chris Packham1a07d212018-05-10 13:28:29 +12001643 /* HCLK in[ps] */
Chris Packham4bf81db2018-12-03 14:26:49 +13001644 t_hclk = MEGA / (freq / config_func_info[dev_num].tip_get_clock_ratio(frequency));
Chris Packham1a07d212018-05-10 13:28:29 +12001645
1646 t_refi = (tm->interface_params[if_id].interface_temp == MV_DDR_TEMP_HIGH) ? TREFI_HIGH : TREFI_LOW;
1647 t_refi *= 1000; /* psec */
1648 refresh_interval_cnt = t_refi / t_hclk; /* no units */
1649
1650 if (page_size == 1) {
Chris Packham4bf81db2018-12-03 14:26:49 +13001651 t_faw = mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TFAW1K);
Chris Packham1a07d212018-05-10 13:28:29 +12001652 t_faw = time_to_nclk(t_faw, t_ckclk);
1653 t_faw = GET_MAX_VALUE(20, t_faw);
1654 } else { /* page size =2, we do not support page size 0.5k */
Chris Packham4bf81db2018-12-03 14:26:49 +13001655 t_faw = mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TFAW2K);
Chris Packham1a07d212018-05-10 13:28:29 +12001656 t_faw = time_to_nclk(t_faw, t_ckclk);
1657 t_faw = GET_MAX_VALUE(28, t_faw);
1658 }
1659
Chris Packham4bf81db2018-12-03 14:26:49 +13001660 t_pd = GET_MAX_VALUE(t_ckclk * 3, mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TPD));
Chris Packham1a07d212018-05-10 13:28:29 +12001661 t_pd = time_to_nclk(t_pd, t_ckclk);
1662
Chris Packham4bf81db2018-12-03 14:26:49 +13001663 t_xpdll = GET_MAX_VALUE(t_ckclk * 10, mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TXPDLL));
Chris Packham1a07d212018-05-10 13:28:29 +12001664 t_xpdll = time_to_nclk(t_xpdll, t_ckclk);
1665
Chris Packham4bf81db2018-12-03 14:26:49 +13001666 t_rrd = (page_size == 1) ? mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001667 SPEED_BIN_TRRD1K) :
Chris Packham4bf81db2018-12-03 14:26:49 +13001668 mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TRRD2K);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001669 t_rrd = GET_MAX_VALUE(t_ckclk * 4, t_rrd);
Chris Packham4bf81db2018-12-03 14:26:49 +13001670 t_rtp = GET_MAX_VALUE(t_ckclk * 4, mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001671 SPEED_BIN_TRTP));
Chris Packham1a07d212018-05-10 13:28:29 +12001672 t_mod = GET_MAX_VALUE(t_ckclk * 12, 15000);
Chris Packham4bf81db2018-12-03 14:26:49 +13001673 t_wtr = GET_MAX_VALUE(t_ckclk * 4, mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001674 SPEED_BIN_TWTR));
Chris Packham4bf81db2018-12-03 14:26:49 +13001675 t_ras = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001676 SPEED_BIN_TRAS),
1677 t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001678 t_rcd = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001679 SPEED_BIN_TRCD),
1680 t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001681 t_rp = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001682 SPEED_BIN_TRP),
1683 t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001684 t_wr = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001685 SPEED_BIN_TWR),
1686 t_ckclk);
Chris Packham1a07d212018-05-10 13:28:29 +12001687 t_wtr = time_to_nclk(t_wtr, t_ckclk);
1688 t_rrd = time_to_nclk(t_rrd, t_ckclk);
1689 t_rtp = time_to_nclk(t_rtp, t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001690 t_rfc = time_to_nclk(mv_ddr_rfc_get(memory_size) * 1000, t_ckclk);
Chris Packham1a07d212018-05-10 13:28:29 +12001691 t_mod = time_to_nclk(t_mod, t_ckclk);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001692
1693 /* SDRAM Timing Low */
Chris Packham1a07d212018-05-10 13:28:29 +12001694 val = (((t_ras - 1) & SDRAM_TIMING_LOW_TRAS_MASK) << SDRAM_TIMING_LOW_TRAS_OFFS) |
1695 (((t_rcd - 1) & SDRAM_TIMING_LOW_TRCD_MASK) << SDRAM_TIMING_LOW_TRCD_OFFS) |
1696 (((t_rcd - 1) >> SDRAM_TIMING_LOW_TRCD_OFFS & SDRAM_TIMING_HIGH_TRCD_MASK)
1697 << SDRAM_TIMING_HIGH_TRCD_OFFS) |
1698 (((t_rp - 1) & SDRAM_TIMING_LOW_TRP_MASK) << SDRAM_TIMING_LOW_TRP_OFFS) |
1699 (((t_rp - 1) >> SDRAM_TIMING_LOW_TRP_MASK & SDRAM_TIMING_HIGH_TRP_MASK)
1700 << SDRAM_TIMING_HIGH_TRP_OFFS) |
1701 (((t_wr - 1) & SDRAM_TIMING_LOW_TWR_MASK) << SDRAM_TIMING_LOW_TWR_OFFS) |
1702 (((t_wtr - 1) & SDRAM_TIMING_LOW_TWTR_MASK) << SDRAM_TIMING_LOW_TWTR_OFFS) |
1703 ((((t_ras - 1) >> 4) & SDRAM_TIMING_LOW_TRAS_HIGH_MASK) << SDRAM_TIMING_LOW_TRAS_HIGH_OFFS) |
1704 (((t_rrd - 1) & SDRAM_TIMING_LOW_TRRD_MASK) << SDRAM_TIMING_LOW_TRRD_OFFS) |
1705 (((t_rtp - 1) & SDRAM_TIMING_LOW_TRTP_MASK) << SDRAM_TIMING_LOW_TRTP_OFFS);
1706
1707 mask = (SDRAM_TIMING_LOW_TRAS_MASK << SDRAM_TIMING_LOW_TRAS_OFFS) |
1708 (SDRAM_TIMING_LOW_TRCD_MASK << SDRAM_TIMING_LOW_TRCD_OFFS) |
1709 (SDRAM_TIMING_HIGH_TRCD_MASK << SDRAM_TIMING_HIGH_TRCD_OFFS) |
1710 (SDRAM_TIMING_LOW_TRP_MASK << SDRAM_TIMING_LOW_TRP_OFFS) |
1711 (SDRAM_TIMING_HIGH_TRP_MASK << SDRAM_TIMING_HIGH_TRP_OFFS) |
1712 (SDRAM_TIMING_LOW_TWR_MASK << SDRAM_TIMING_LOW_TWR_OFFS) |
1713 (SDRAM_TIMING_LOW_TWTR_MASK << SDRAM_TIMING_LOW_TWTR_OFFS) |
1714 (SDRAM_TIMING_LOW_TRAS_HIGH_MASK << SDRAM_TIMING_LOW_TRAS_HIGH_OFFS) |
1715 (SDRAM_TIMING_LOW_TRRD_MASK << SDRAM_TIMING_LOW_TRRD_OFFS) |
1716 (SDRAM_TIMING_LOW_TRTP_MASK << SDRAM_TIMING_LOW_TRTP_OFFS);
1717
Stefan Roese5ffceb82015-03-26 15:36:56 +01001718 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001719 SDRAM_TIMING_LOW_REG, val, mask));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001720
1721 /* SDRAM Timing High */
Chris Packham1a07d212018-05-10 13:28:29 +12001722 val = 0;
1723 mask = 0;
1724
1725 val = (((t_rfc - 1) & SDRAM_TIMING_HIGH_TRFC_MASK) << SDRAM_TIMING_HIGH_TRFC_OFFS) |
1726 ((t_r2r & SDRAM_TIMING_HIGH_TR2R_MASK) << SDRAM_TIMING_HIGH_TR2R_OFFS) |
1727 ((t_r2w_w2r & SDRAM_TIMING_HIGH_TR2W_W2R_MASK) << SDRAM_TIMING_HIGH_TR2W_W2R_OFFS) |
1728 ((t_w2w & SDRAM_TIMING_HIGH_TW2W_MASK) << SDRAM_TIMING_HIGH_TW2W_OFFS) |
1729 ((((t_rfc - 1) >> 7) & SDRAM_TIMING_HIGH_TRFC_HIGH_MASK) << SDRAM_TIMING_HIGH_TRFC_HIGH_OFFS) |
1730 ((t_r2r_high & SDRAM_TIMING_HIGH_TR2R_HIGH_MASK) << SDRAM_TIMING_HIGH_TR2R_HIGH_OFFS) |
1731 ((t_r2w_w2r_high & SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_MASK) << SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_OFFS) |
1732 (((t_mod - 1) & SDRAM_TIMING_HIGH_TMOD_MASK) << SDRAM_TIMING_HIGH_TMOD_OFFS) |
1733 ((((t_mod - 1) >> 4) & SDRAM_TIMING_HIGH_TMOD_HIGH_MASK) << SDRAM_TIMING_HIGH_TMOD_HIGH_OFFS);
1734
1735 mask = (SDRAM_TIMING_HIGH_TRFC_MASK << SDRAM_TIMING_HIGH_TRFC_OFFS) |
1736 (SDRAM_TIMING_HIGH_TR2R_MASK << SDRAM_TIMING_HIGH_TR2R_OFFS) |
1737 (SDRAM_TIMING_HIGH_TR2W_W2R_MASK << SDRAM_TIMING_HIGH_TR2W_W2R_OFFS) |
1738 (SDRAM_TIMING_HIGH_TW2W_MASK << SDRAM_TIMING_HIGH_TW2W_OFFS) |
1739 (SDRAM_TIMING_HIGH_TRFC_HIGH_MASK << SDRAM_TIMING_HIGH_TRFC_HIGH_OFFS) |
1740 (SDRAM_TIMING_HIGH_TR2R_HIGH_MASK << SDRAM_TIMING_HIGH_TR2R_HIGH_OFFS) |
1741 (SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_MASK << SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_OFFS) |
1742 (SDRAM_TIMING_HIGH_TMOD_MASK << SDRAM_TIMING_HIGH_TMOD_OFFS) |
1743 (SDRAM_TIMING_HIGH_TMOD_HIGH_MASK << SDRAM_TIMING_HIGH_TMOD_HIGH_OFFS);
1744
Stefan Roese5ffceb82015-03-26 15:36:56 +01001745 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001746 SDRAM_TIMING_HIGH_REG, val, mask));
1747
Stefan Roese5ffceb82015-03-26 15:36:56 +01001748 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001749 SDRAM_CFG_REG,
1750 refresh_interval_cnt << REFRESH_OFFS,
1751 REFRESH_MASK << REFRESH_OFFS));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001752 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001753 SDRAM_ADDR_CTRL_REG, (t_faw - 1) << T_FAW_OFFS,
1754 T_FAW_MASK << T_FAW_OFFS));
1755
1756 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id, DDR_TIMING_REG,
1757 (t_pd - 1) << DDR_TIMING_TPD_OFFS |
1758 (t_xpdll - 1) << DDR_TIMING_TXPDLL_OFFS,
1759 DDR_TIMING_TPD_MASK << DDR_TIMING_TPD_OFFS |
1760 DDR_TIMING_TXPDLL_MASK << DDR_TIMING_TXPDLL_OFFS));
1761
Stefan Roese5ffceb82015-03-26 15:36:56 +01001762
1763 return MV_OK;
1764}
1765
Chris Packham1a07d212018-05-10 13:28:29 +12001766
Stefan Roese5ffceb82015-03-26 15:36:56 +01001767/*
Stefan Roese5ffceb82015-03-26 15:36:56 +01001768 * Write CS Result
1769 */
1770int ddr3_tip_write_cs_result(u32 dev_num, u32 offset)
1771{
1772 u32 if_id, bus_num, cs_bitmask, data_val, cs_num;
Chris Packham1a07d212018-05-10 13:28:29 +12001773 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1774 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001775
1776 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001777 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
1778 for (bus_num = 0; bus_num < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001779 bus_num++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001780 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001781 cs_bitmask =
1782 tm->interface_params[if_id].
1783 as_bus_params[bus_num].cs_bitmask;
1784 if (cs_bitmask != effective_cs) {
1785 cs_num = GET_CS_FROM_MASK(cs_bitmask);
1786 ddr3_tip_bus_read(dev_num, if_id,
1787 ACCESS_TYPE_UNICAST, bus_num,
1788 DDR_PHY_DATA,
1789 offset +
Chris Packham1a07d212018-05-10 13:28:29 +12001790 (effective_cs * 0x4),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001791 &data_val);
1792 ddr3_tip_bus_write(dev_num,
1793 ACCESS_TYPE_UNICAST,
1794 if_id,
1795 ACCESS_TYPE_UNICAST,
1796 bus_num, DDR_PHY_DATA,
1797 offset +
Chris Packham1a07d212018-05-10 13:28:29 +12001798 (cs_num * 0x4),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001799 data_val);
1800 }
1801 }
1802 }
1803
1804 return MV_OK;
1805}
1806
1807/*
1808 * Write MRS
1809 */
Chris Packham1a07d212018-05-10 13:28:29 +12001810int ddr3_tip_write_mrs_cmd(u32 dev_num, u32 *cs_mask_arr, enum mr_number mr_num, u32 data, u32 mask)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001811{
Chris Packham1a07d212018-05-10 13:28:29 +12001812 u32 if_id;
1813 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001814
Stefan Roese5ffceb82015-03-26 15:36:56 +01001815 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12001816 PARAM_NOT_CARE, mr_data[mr_num].reg_addr, data, mask));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001817 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001818 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001819 CHECK_STATUS(ddr3_tip_if_write
1820 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001821 SDRAM_OP_REG,
1822 (cs_mask_arr[if_id] << 8) | mr_data[mr_num].cmd, 0xf1f));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001823 }
1824
1825 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001826 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001827 if (ddr3_tip_if_polling(dev_num, ACCESS_TYPE_UNICAST, if_id, 0,
Chris Packham1a07d212018-05-10 13:28:29 +12001828 0x1f, SDRAM_OP_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001829 MAX_POLLING_ITERATIONS) != MV_OK) {
1830 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1831 ("write_mrs_cmd: Poll cmd fail"));
1832 }
1833 }
1834
1835 return MV_OK;
1836}
1837
1838/*
1839 * Reset XSB Read FIFO
1840 */
1841int ddr3_tip_reset_fifo_ptr(u32 dev_num)
1842{
1843 u32 if_id = 0;
1844
1845 /* Configure PHY reset value to 0 in order to "clean" the FIFO */
1846 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1847 if_id, 0x15c8, 0, 0xff000000));
1848 /*
1849 * Move PHY to RL mode (only in RL mode the PHY overrides FIFO values
1850 * during FIFO reset)
1851 */
1852 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1853 if_id, TRAINING_SW_2_REG,
1854 0x1, 0x9));
1855 /* In order that above configuration will influence the PHY */
1856 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1857 if_id, 0x15b0,
1858 0x80000000, 0x80000000));
1859 /* Reset read fifo assertion */
1860 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1861 if_id, 0x1400, 0, 0x40000000));
1862 /* Reset read fifo deassertion */
1863 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1864 if_id, 0x1400,
1865 0x40000000, 0x40000000));
1866 /* Move PHY back to functional mode */
1867 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1868 if_id, TRAINING_SW_2_REG,
1869 0x8, 0x9));
1870 /* Stop training machine */
1871 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1872 if_id, 0x15b4, 0x10000, 0x10000));
1873
1874 return MV_OK;
1875}
1876
1877/*
1878 * Reset Phy registers
1879 */
1880int ddr3_tip_ddr3_reset_phy_regs(u32 dev_num)
1881{
1882 u32 if_id, phy_id, cs;
Chris Packham1a07d212018-05-10 13:28:29 +12001883 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1884 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001885
1886 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001887 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
1888 for (phy_id = 0; phy_id < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001889 phy_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001890 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, phy_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001891 CHECK_STATUS(ddr3_tip_bus_write
1892 (dev_num, ACCESS_TYPE_UNICAST,
1893 if_id, ACCESS_TYPE_UNICAST,
1894 phy_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +12001895 WL_PHY_REG(effective_cs),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001896 phy_reg0_val));
1897 CHECK_STATUS(ddr3_tip_bus_write
1898 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1899 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +12001900 RL_PHY_REG(effective_cs),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001901 phy_reg2_val));
1902 CHECK_STATUS(ddr3_tip_bus_write
1903 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1904 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +12001905 CRX_PHY_REG(effective_cs), phy_reg3_val));
1906 CHECK_STATUS(ddr3_tip_bus_write
1907 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1908 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1909 CTX_PHY_REG(effective_cs), phy_reg1_val));
1910 CHECK_STATUS(ddr3_tip_bus_write
1911 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1912 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1913 PBS_TX_BCAST_PHY_REG(effective_cs), 0x0));
1914 CHECK_STATUS(ddr3_tip_bus_write
1915 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1916 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1917 PBS_RX_BCAST_PHY_REG(effective_cs), 0));
1918 CHECK_STATUS(ddr3_tip_bus_write
1919 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1920 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1921 PBS_TX_PHY_REG(effective_cs, DQSP_PAD), 0));
1922 CHECK_STATUS(ddr3_tip_bus_write
1923 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1924 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1925 PBS_RX_PHY_REG(effective_cs, DQSP_PAD), 0));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001926 CHECK_STATUS(ddr3_tip_bus_write
1927 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1928 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +12001929 PBS_TX_PHY_REG(effective_cs, DQSN_PAD), 0));
1930 CHECK_STATUS(ddr3_tip_bus_write
1931 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1932 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1933 PBS_RX_PHY_REG(effective_cs, DQSN_PAD), 0));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001934 }
1935 }
1936
1937 /* Set Receiver Calibration value */
1938 for (cs = 0; cs < MAX_CS_NUM; cs++) {
1939 /* PHY register 0xdb bits[5:0] - configure to 63 */
1940 CHECK_STATUS(ddr3_tip_bus_write
1941 (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE,
1942 ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE,
Chris Packham1a07d212018-05-10 13:28:29 +12001943 DDR_PHY_DATA, VREF_BCAST_PHY_REG(cs), 63));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001944 }
1945
1946 return MV_OK;
1947}
1948
1949/*
1950 * Restore Dunit registers
1951 */
1952int ddr3_tip_restore_dunit_regs(u32 dev_num)
1953{
1954 u32 index_cnt;
1955
Chris Packham1a07d212018-05-10 13:28:29 +12001956 mv_ddr_set_calib_controller();
1957
Stefan Roese5ffceb82015-03-26 15:36:56 +01001958 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12001959 PARAM_NOT_CARE, MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001960 0x1, 0x1));
1961 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12001962 PARAM_NOT_CARE, MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001963 calibration_update_control << 3,
1964 0x3 << 3));
1965 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1966 PARAM_NOT_CARE,
Chris Packham1a07d212018-05-10 13:28:29 +12001967 ODPG_WR_RD_MODE_ENA_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001968 0xffff, MASK_ALL_BITS));
1969
1970 for (index_cnt = 0; index_cnt < ARRAY_SIZE(odpg_default_value);
1971 index_cnt++) {
1972 CHECK_STATUS(ddr3_tip_if_write
1973 (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE,
1974 odpg_default_value[index_cnt].reg_addr,
1975 odpg_default_value[index_cnt].reg_data,
1976 odpg_default_value[index_cnt].reg_mask));
1977 }
1978
1979 return MV_OK;
1980}
1981
Chris Packham1a07d212018-05-10 13:28:29 +12001982int ddr3_tip_adll_regs_bypass(u32 dev_num, u32 reg_val1, u32 reg_val2)
1983{
1984 u32 if_id, phy_id;
1985 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1986 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
1987
1988 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
1989 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
1990 for (phy_id = 0; phy_id < octets_per_if_num; phy_id++) {
1991 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, phy_id);
1992 CHECK_STATUS(ddr3_tip_bus_write
1993 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1994 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1995 CTX_PHY_REG(effective_cs), reg_val1));
1996 CHECK_STATUS(ddr3_tip_bus_write
1997 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1998 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1999 PBS_TX_BCAST_PHY_REG(effective_cs), reg_val2));
2000 }
2001 }
2002
2003 return MV_OK;
2004}
2005
Stefan Roese5ffceb82015-03-26 15:36:56 +01002006/*
2007 * Auto tune main flow
2008 */
2009static int ddr3_tip_ddr3_training_main_flow(u32 dev_num)
2010{
Chris Packham1a07d212018-05-10 13:28:29 +12002011/* TODO: enable this functionality for other platforms */
2012#if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_39X)
Stefan Roese5ffceb82015-03-26 15:36:56 +01002013 struct init_cntr_param init_cntr_prm;
Chris Packham1a07d212018-05-10 13:28:29 +12002014#endif
Stefan Roese5ffceb82015-03-26 15:36:56 +01002015 int ret = MV_OK;
Chris Packham1a07d212018-05-10 13:28:29 +12002016 int adll_bypass_flag = 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002017 u32 if_id;
Chris Packham4bf81db2018-12-03 14:26:49 +13002018 unsigned int max_cs = mv_ddr_cs_num_get();
Chris Packham1a07d212018-05-10 13:28:29 +12002019 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Chris Packham4bf81db2018-12-03 14:26:49 +13002020 enum mv_ddr_freq freq = tm->interface_params[0].memory_freq;
2021 unsigned int *freq_tbl = mv_ddr_freq_tbl_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002022
Chris Packham1a07d212018-05-10 13:28:29 +12002023#ifdef DDR_VIEWER_TOOL
Stefan Roese5ffceb82015-03-26 15:36:56 +01002024 if (debug_training == DEBUG_LEVEL_TRACE) {
2025 CHECK_STATUS(print_device_info((u8)dev_num));
2026 }
2027#endif
2028
Chris Packham1a07d212018-05-10 13:28:29 +12002029 ddr3_tip_validate_algo_components(dev_num);
2030
Stefan Roese5ffceb82015-03-26 15:36:56 +01002031 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2032 CHECK_STATUS(ddr3_tip_ddr3_reset_phy_regs(dev_num));
2033 }
2034 /* Set to 0 after each loop to avoid illegal value may be used */
2035 effective_cs = 0;
2036
Chris Packham4bf81db2018-12-03 14:26:49 +13002037 freq_tbl[MV_DDR_FREQ_LOW_FREQ] = dfs_low_freq;
Chris Packham1a07d212018-05-10 13:28:29 +12002038
Stefan Roese5ffceb82015-03-26 15:36:56 +01002039 if (is_pll_before_init != 0) {
2040 for (if_id = 0; if_id < MAX_INTERFACE_NUM; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12002041 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002042 config_func_info[dev_num].tip_set_freq_divider_func(
2043 (u8)dev_num, if_id, freq);
2044 }
2045 }
2046
Chris Packham1a07d212018-05-10 13:28:29 +12002047/* TODO: enable this functionality for other platforms */
2048#if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_39X)
Stefan Roese5ffceb82015-03-26 15:36:56 +01002049 if (is_adll_calib_before_init != 0) {
2050 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2051 ("with adll calib before init\n"));
2052 adll_calibration(dev_num, ACCESS_TYPE_MULTICAST, 0, freq);
2053 }
2054
2055 if (is_reg_dump != 0) {
2056 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2057 ("Dump before init controller\n"));
2058 ddr3_tip_reg_dump(dev_num);
2059 }
2060
2061 if (mask_tune_func & INIT_CONTROLLER_MASK_BIT) {
2062 training_stage = INIT_CONTROLLER;
2063 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2064 ("INIT_CONTROLLER_MASK_BIT\n"));
2065 init_cntr_prm.do_mrs_phy = 1;
2066 init_cntr_prm.is_ctrl64_bit = 0;
2067 init_cntr_prm.init_phy = 1;
2068 init_cntr_prm.msys_init = 0;
2069 ret = hws_ddr3_tip_init_controller(dev_num, &init_cntr_prm);
2070 if (is_reg_dump != 0)
2071 ddr3_tip_reg_dump(dev_num);
2072 if (ret != MV_OK) {
2073 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2074 ("hws_ddr3_tip_init_controller failure\n"));
2075 if (debug_mode == 0)
2076 return MV_FAIL;
2077 }
2078 }
Chris Packham1a07d212018-05-10 13:28:29 +12002079#endif
Stefan Roese5ffceb82015-03-26 15:36:56 +01002080
Chris Packham1a07d212018-05-10 13:28:29 +12002081 ret = adll_calibration(dev_num, ACCESS_TYPE_MULTICAST, 0, freq);
2082 if (ret != MV_OK) {
2083 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2084 ("adll_calibration failure\n"));
2085 if (debug_mode == 0)
2086 return MV_FAIL;
2087 }
Stefan Roese5ffceb82015-03-26 15:36:56 +01002088
2089 if (mask_tune_func & SET_LOW_FREQ_MASK_BIT) {
2090 training_stage = SET_LOW_FREQ;
Chris Packham1a07d212018-05-10 13:28:29 +12002091
2092 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2093 ddr3_tip_adll_regs_bypass(dev_num, 0, 0x1f);
2094 adll_bypass_flag = 1;
2095 }
2096 effective_cs = 0;
2097
Stefan Roese5ffceb82015-03-26 15:36:56 +01002098 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2099 ("SET_LOW_FREQ_MASK_BIT %d\n",
Chris Packham4bf81db2018-12-03 14:26:49 +13002100 freq_tbl[low_freq]));
Stefan Roese5ffceb82015-03-26 15:36:56 +01002101 ret = ddr3_tip_freq_set(dev_num, ACCESS_TYPE_MULTICAST,
2102 PARAM_NOT_CARE, low_freq);
2103 if (is_reg_dump != 0)
2104 ddr3_tip_reg_dump(dev_num);
2105 if (ret != MV_OK) {
2106 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2107 ("ddr3_tip_freq_set failure\n"));
2108 if (debug_mode == 0)
2109 return MV_FAIL;
2110 }
2111 }
2112
Chris Packham1a07d212018-05-10 13:28:29 +12002113 if (mask_tune_func & WRITE_LEVELING_LF_MASK_BIT) {
2114 training_stage = WRITE_LEVELING_LF;
2115 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2116 ("WRITE_LEVELING_LF_MASK_BIT\n"));
2117 ret = ddr3_tip_dynamic_write_leveling(dev_num, 1);
2118 if (is_reg_dump != 0)
2119 ddr3_tip_reg_dump(dev_num);
2120 if (ret != MV_OK) {
2121 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2122 ("ddr3_tip_dynamic_write_leveling LF failure\n"));
2123 if (debug_mode == 0)
2124 return MV_FAIL;
2125 }
2126 }
2127
Stefan Roese5ffceb82015-03-26 15:36:56 +01002128 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2129 if (mask_tune_func & LOAD_PATTERN_MASK_BIT) {
2130 training_stage = LOAD_PATTERN;
2131 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2132 ("LOAD_PATTERN_MASK_BIT #%d\n",
2133 effective_cs));
2134 ret = ddr3_tip_load_all_pattern_to_mem(dev_num);
2135 if (is_reg_dump != 0)
2136 ddr3_tip_reg_dump(dev_num);
2137 if (ret != MV_OK) {
2138 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2139 ("ddr3_tip_load_all_pattern_to_mem failure CS #%d\n",
2140 effective_cs));
2141 if (debug_mode == 0)
2142 return MV_FAIL;
2143 }
2144 }
2145 }
Chris Packham1a07d212018-05-10 13:28:29 +12002146
2147 if (adll_bypass_flag == 1) {
2148 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2149 ddr3_tip_adll_regs_bypass(dev_num, phy_reg1_val, 0);
2150 adll_bypass_flag = 0;
2151 }
2152 }
2153
Stefan Roese5ffceb82015-03-26 15:36:56 +01002154 /* Set to 0 after each loop to avoid illegal value may be used */
2155 effective_cs = 0;
2156
2157 if (mask_tune_func & SET_MEDIUM_FREQ_MASK_BIT) {
2158 training_stage = SET_MEDIUM_FREQ;
2159 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2160 ("SET_MEDIUM_FREQ_MASK_BIT %d\n",
Chris Packham4bf81db2018-12-03 14:26:49 +13002161 freq_tbl[medium_freq]));
Stefan Roese5ffceb82015-03-26 15:36:56 +01002162 ret =
2163 ddr3_tip_freq_set(dev_num, ACCESS_TYPE_MULTICAST,
2164 PARAM_NOT_CARE, medium_freq);
2165 if (is_reg_dump != 0)
2166 ddr3_tip_reg_dump(dev_num);
2167 if (ret != MV_OK) {
2168 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2169 ("ddr3_tip_freq_set failure\n"));
2170 if (debug_mode == 0)
2171 return MV_FAIL;
2172 }
2173 }
2174
2175 if (mask_tune_func & WRITE_LEVELING_MASK_BIT) {
2176 training_stage = WRITE_LEVELING;
2177 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2178 ("WRITE_LEVELING_MASK_BIT\n"));
Chris Packham4bf81db2018-12-03 14:26:49 +13002179 if ((rl_mid_freq_wa == 0) || (freq_tbl[medium_freq] == 533)) {
Chris Packham1a07d212018-05-10 13:28:29 +12002180 ret = ddr3_tip_dynamic_write_leveling(dev_num, 0);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002181 } else {
2182 /* Use old WL */
2183 ret = ddr3_tip_legacy_dynamic_write_leveling(dev_num);
2184 }
2185
2186 if (is_reg_dump != 0)
2187 ddr3_tip_reg_dump(dev_num);
2188 if (ret != MV_OK) {
2189 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2190 ("ddr3_tip_dynamic_write_leveling failure\n"));
2191 if (debug_mode == 0)
2192 return MV_FAIL;
2193 }
2194 }
2195
2196 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2197 if (mask_tune_func & LOAD_PATTERN_2_MASK_BIT) {
2198 training_stage = LOAD_PATTERN_2;
2199 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2200 ("LOAD_PATTERN_2_MASK_BIT CS #%d\n",
2201 effective_cs));
2202 ret = ddr3_tip_load_all_pattern_to_mem(dev_num);
2203 if (is_reg_dump != 0)
2204 ddr3_tip_reg_dump(dev_num);
2205 if (ret != MV_OK) {
2206 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2207 ("ddr3_tip_load_all_pattern_to_mem failure CS #%d\n",
2208 effective_cs));
2209 if (debug_mode == 0)
2210 return MV_FAIL;
2211 }
2212 }
2213 }
2214 /* Set to 0 after each loop to avoid illegal value may be used */
2215 effective_cs = 0;
2216
2217 if (mask_tune_func & READ_LEVELING_MASK_BIT) {
2218 training_stage = READ_LEVELING;
2219 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2220 ("READ_LEVELING_MASK_BIT\n"));
Chris Packham4bf81db2018-12-03 14:26:49 +13002221 if ((rl_mid_freq_wa == 0) || (freq_tbl[medium_freq] == 533)) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01002222 ret = ddr3_tip_dynamic_read_leveling(dev_num, medium_freq);
2223 } else {
2224 /* Use old RL */
2225 ret = ddr3_tip_legacy_dynamic_read_leveling(dev_num);
2226 }
2227
2228 if (is_reg_dump != 0)
2229 ddr3_tip_reg_dump(dev_num);
2230 if (ret != MV_OK) {
2231 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2232 ("ddr3_tip_dynamic_read_leveling failure\n"));
2233 if (debug_mode == 0)
2234 return MV_FAIL;
2235 }
2236 }
2237
2238 if (mask_tune_func & WRITE_LEVELING_SUPP_MASK_BIT) {
2239 training_stage = WRITE_LEVELING_SUPP;
2240 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2241 ("WRITE_LEVELING_SUPP_MASK_BIT\n"));
2242 ret = ddr3_tip_dynamic_write_leveling_supp(dev_num);
2243 if (is_reg_dump != 0)
2244 ddr3_tip_reg_dump(dev_num);
2245 if (ret != MV_OK) {
2246 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2247 ("ddr3_tip_dynamic_write_leveling_supp failure\n"));
2248 if (debug_mode == 0)
2249 return MV_FAIL;
2250 }
2251 }
2252
2253 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2254 if (mask_tune_func & PBS_RX_MASK_BIT) {
2255 training_stage = PBS_RX;
2256 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2257 ("PBS_RX_MASK_BIT CS #%d\n",
2258 effective_cs));
2259 ret = ddr3_tip_pbs_rx(dev_num);
2260 if (is_reg_dump != 0)
2261 ddr3_tip_reg_dump(dev_num);
2262 if (ret != MV_OK) {
2263 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2264 ("ddr3_tip_pbs_rx failure CS #%d\n",
2265 effective_cs));
2266 if (debug_mode == 0)
2267 return MV_FAIL;
2268 }
2269 }
2270 }
2271
2272 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2273 if (mask_tune_func & PBS_TX_MASK_BIT) {
2274 training_stage = PBS_TX;
2275 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2276 ("PBS_TX_MASK_BIT CS #%d\n",
2277 effective_cs));
2278 ret = ddr3_tip_pbs_tx(dev_num);
2279 if (is_reg_dump != 0)
2280 ddr3_tip_reg_dump(dev_num);
2281 if (ret != MV_OK) {
2282 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2283 ("ddr3_tip_pbs_tx failure CS #%d\n",
2284 effective_cs));
2285 if (debug_mode == 0)
2286 return MV_FAIL;
2287 }
2288 }
2289 }
2290 /* Set to 0 after each loop to avoid illegal value may be used */
2291 effective_cs = 0;
2292
2293 if (mask_tune_func & SET_TARGET_FREQ_MASK_BIT) {
2294 training_stage = SET_TARGET_FREQ;
2295 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2296 ("SET_TARGET_FREQ_MASK_BIT %d\n",
Chris Packham4bf81db2018-12-03 14:26:49 +13002297 freq_tbl[tm->
Stefan Roese5ffceb82015-03-26 15:36:56 +01002298 interface_params[first_active_if].
2299 memory_freq]));
2300 ret = ddr3_tip_freq_set(dev_num, ACCESS_TYPE_MULTICAST,
2301 PARAM_NOT_CARE,
2302 tm->interface_params[first_active_if].
2303 memory_freq);
2304 if (is_reg_dump != 0)
2305 ddr3_tip_reg_dump(dev_num);
2306 if (ret != MV_OK) {
2307 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2308 ("ddr3_tip_freq_set failure\n"));
2309 if (debug_mode == 0)
2310 return MV_FAIL;
2311 }
2312 }
2313
2314 if (mask_tune_func & WRITE_LEVELING_TF_MASK_BIT) {
2315 training_stage = WRITE_LEVELING_TF;
2316 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2317 ("WRITE_LEVELING_TF_MASK_BIT\n"));
Chris Packham1a07d212018-05-10 13:28:29 +12002318 ret = ddr3_tip_dynamic_write_leveling(dev_num, 0);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002319 if (is_reg_dump != 0)
2320 ddr3_tip_reg_dump(dev_num);
2321 if (ret != MV_OK) {
2322 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2323 ("ddr3_tip_dynamic_write_leveling TF failure\n"));
2324 if (debug_mode == 0)
2325 return MV_FAIL;
2326 }
2327 }
2328
2329 if (mask_tune_func & LOAD_PATTERN_HIGH_MASK_BIT) {
2330 training_stage = LOAD_PATTERN_HIGH;
2331 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("LOAD_PATTERN_HIGH\n"));
2332 ret = ddr3_tip_load_all_pattern_to_mem(dev_num);
2333 if (is_reg_dump != 0)
2334 ddr3_tip_reg_dump(dev_num);
2335 if (ret != MV_OK) {
2336 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2337 ("ddr3_tip_load_all_pattern_to_mem failure\n"));
2338 if (debug_mode == 0)
2339 return MV_FAIL;
2340 }
2341 }
2342
2343 if (mask_tune_func & READ_LEVELING_TF_MASK_BIT) {
2344 training_stage = READ_LEVELING_TF;
2345 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2346 ("READ_LEVELING_TF_MASK_BIT\n"));
2347 ret = ddr3_tip_dynamic_read_leveling(dev_num, tm->
2348 interface_params[first_active_if].
2349 memory_freq);
2350 if (is_reg_dump != 0)
2351 ddr3_tip_reg_dump(dev_num);
2352 if (ret != MV_OK) {
2353 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2354 ("ddr3_tip_dynamic_read_leveling TF failure\n"));
2355 if (debug_mode == 0)
2356 return MV_FAIL;
2357 }
2358 }
2359
Chris Packham1a07d212018-05-10 13:28:29 +12002360 if (mask_tune_func & RL_DQS_BURST_MASK_BIT) {
2361 training_stage = READ_LEVELING_TF;
2362 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2363 ("RL_DQS_BURST_MASK_BIT\n"));
2364 ret = mv_ddr_rl_dqs_burst(0, 0, tm->interface_params[0].memory_freq);
2365 if (is_reg_dump != 0)
2366 ddr3_tip_reg_dump(dev_num);
2367 if (ret != MV_OK) {
2368 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2369 ("mv_ddr_rl_dqs_burst TF failure\n"));
2370 if (debug_mode == 0)
2371 return MV_FAIL;
2372 }
2373 }
2374
Stefan Roese5ffceb82015-03-26 15:36:56 +01002375 if (mask_tune_func & DM_PBS_TX_MASK_BIT) {
2376 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("DM_PBS_TX_MASK_BIT\n"));
2377 }
2378
2379 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2380 if (mask_tune_func & VREF_CALIBRATION_MASK_BIT) {
2381 training_stage = VREF_CALIBRATION;
2382 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("VREF\n"));
2383 ret = ddr3_tip_vref(dev_num);
2384 if (is_reg_dump != 0) {
2385 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2386 ("VREF Dump\n"));
2387 ddr3_tip_reg_dump(dev_num);
2388 }
2389 if (ret != MV_OK) {
2390 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2391 ("ddr3_tip_vref failure\n"));
2392 if (debug_mode == 0)
2393 return MV_FAIL;
2394 }
2395 }
2396 }
2397 /* Set to 0 after each loop to avoid illegal value may be used */
2398 effective_cs = 0;
2399
2400 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2401 if (mask_tune_func & CENTRALIZATION_RX_MASK_BIT) {
2402 training_stage = CENTRALIZATION_RX;
2403 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2404 ("CENTRALIZATION_RX_MASK_BIT CS #%d\n",
2405 effective_cs));
2406 ret = ddr3_tip_centralization_rx(dev_num);
2407 if (is_reg_dump != 0)
2408 ddr3_tip_reg_dump(dev_num);
2409 if (ret != MV_OK) {
2410 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2411 ("ddr3_tip_centralization_rx failure CS #%d\n",
2412 effective_cs));
2413 if (debug_mode == 0)
2414 return MV_FAIL;
2415 }
2416 }
2417 }
2418 /* Set to 0 after each loop to avoid illegal value may be used */
2419 effective_cs = 0;
2420
2421 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2422 if (mask_tune_func & WRITE_LEVELING_SUPP_TF_MASK_BIT) {
2423 training_stage = WRITE_LEVELING_SUPP_TF;
2424 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2425 ("WRITE_LEVELING_SUPP_TF_MASK_BIT CS #%d\n",
2426 effective_cs));
2427 ret = ddr3_tip_dynamic_write_leveling_supp(dev_num);
2428 if (is_reg_dump != 0)
2429 ddr3_tip_reg_dump(dev_num);
2430 if (ret != MV_OK) {
2431 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2432 ("ddr3_tip_dynamic_write_leveling_supp TF failure CS #%d\n",
2433 effective_cs));
2434 if (debug_mode == 0)
2435 return MV_FAIL;
2436 }
2437 }
2438 }
2439 /* Set to 0 after each loop to avoid illegal value may be used */
2440 effective_cs = 0;
2441
Chris Packham1a07d212018-05-10 13:28:29 +12002442
Stefan Roese5ffceb82015-03-26 15:36:56 +01002443 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2444 if (mask_tune_func & CENTRALIZATION_TX_MASK_BIT) {
2445 training_stage = CENTRALIZATION_TX;
2446 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2447 ("CENTRALIZATION_TX_MASK_BIT CS #%d\n",
2448 effective_cs));
2449 ret = ddr3_tip_centralization_tx(dev_num);
2450 if (is_reg_dump != 0)
2451 ddr3_tip_reg_dump(dev_num);
2452 if (ret != MV_OK) {
2453 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2454 ("ddr3_tip_centralization_tx failure CS #%d\n",
2455 effective_cs));
2456 if (debug_mode == 0)
2457 return MV_FAIL;
2458 }
2459 }
2460 }
2461 /* Set to 0 after each loop to avoid illegal value may be used */
2462 effective_cs = 0;
2463
2464 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("restore registers to default\n"));
2465 /* restore register values */
2466 CHECK_STATUS(ddr3_tip_restore_dunit_regs(dev_num));
2467
2468 if (is_reg_dump != 0)
2469 ddr3_tip_reg_dump(dev_num);
2470
2471 return MV_OK;
2472}
2473
2474/*
2475 * DDR3 Dynamic training flow
2476 */
2477static int ddr3_tip_ddr3_auto_tune(u32 dev_num)
2478{
Chris Packham1a07d212018-05-10 13:28:29 +12002479 int status;
2480 u32 if_id, stage;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002481 int is_if_fail = 0, is_auto_tune_fail = 0;
2482
2483 training_stage = INIT_CONTROLLER;
2484
2485 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
2486 for (stage = 0; stage < MAX_STAGE_LIMIT; stage++)
2487 training_result[stage][if_id] = NO_TEST_DONE;
2488 }
2489
Chris Packham1a07d212018-05-10 13:28:29 +12002490 status = ddr3_tip_ddr3_training_main_flow(dev_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002491
2492 /* activate XSB test */
2493 if (xsb_validate_type != 0) {
2494 run_xsb_test(dev_num, xsb_validation_base_address, 1, 1,
2495 0x1024);
2496 }
2497
2498 if (is_reg_dump != 0)
2499 ddr3_tip_reg_dump(dev_num);
2500
2501 /* print log */
2502 CHECK_STATUS(ddr3_tip_print_log(dev_num, window_mem_addr));
2503
Chris Packham1a07d212018-05-10 13:28:29 +12002504#ifndef EXCLUDE_DEBUG_PRINTS
2505 if (status != MV_OK) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01002506 CHECK_STATUS(ddr3_tip_print_stability_log(dev_num));
2507 }
Chris Packham1a07d212018-05-10 13:28:29 +12002508#endif /* EXCLUDE_DEBUG_PRINTS */
Stefan Roese5ffceb82015-03-26 15:36:56 +01002509
2510 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
2511 is_if_fail = 0;
2512 for (stage = 0; stage < MAX_STAGE_LIMIT; stage++) {
2513 if (training_result[stage][if_id] == TEST_FAILED)
2514 is_if_fail = 1;
2515 }
2516 if (is_if_fail == 1) {
2517 is_auto_tune_fail = 1;
2518 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2519 ("Auto Tune failed for IF %d\n",
2520 if_id));
2521 }
2522 }
2523
Chris Packham1a07d212018-05-10 13:28:29 +12002524 if (((status == MV_FAIL) && (is_auto_tune_fail == 0)) ||
2525 ((status == MV_OK) && (is_auto_tune_fail == 1))) {
2526 /*
2527 * If MainFlow result and trainingResult DB not in sync,
2528 * issue warning (caused by no update of trainingResult DB
2529 * when failed)
2530 */
2531 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2532 ("Warning: Algorithm return value and Result DB"
2533 "are not synced (status 0x%x result DB %d)\n",
2534 status, is_auto_tune_fail));
2535 }
2536
2537 if ((status != MV_OK) || (is_auto_tune_fail == 1))
Stefan Roese5ffceb82015-03-26 15:36:56 +01002538 return MV_FAIL;
2539 else
2540 return MV_OK;
2541}
2542
2543/*
2544 * Enable init sequence
2545 */
2546int ddr3_tip_enable_init_sequence(u32 dev_num)
2547{
2548 int is_fail = 0;
2549 u32 if_id = 0, mem_mask = 0, bus_index = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12002550 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
2551 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002552
2553 /* Enable init sequence */
2554 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST, 0,
Chris Packham1a07d212018-05-10 13:28:29 +12002555 SDRAM_INIT_CTRL_REG, 0x1, 0x1));
Stefan Roese5ffceb82015-03-26 15:36:56 +01002556
2557 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12002558 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002559
2560 if (ddr3_tip_if_polling
2561 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0, 0x1,
Chris Packham1a07d212018-05-10 13:28:29 +12002562 SDRAM_INIT_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01002563 MAX_POLLING_ITERATIONS) != MV_OK) {
2564 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2565 ("polling failed IF %d\n",
2566 if_id));
2567 is_fail = 1;
2568 continue;
2569 }
2570
2571 mem_mask = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12002572 for (bus_index = 0; bus_index < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002573 bus_index++) {
Chris Packham1a07d212018-05-10 13:28:29 +12002574 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_index);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002575 mem_mask |=
2576 tm->interface_params[if_id].
2577 as_bus_params[bus_index].mirror_enable_bitmask;
2578 }
2579
2580 if (mem_mask != 0) {
2581 /* Disable Multi CS */
2582 CHECK_STATUS(ddr3_tip_if_write
2583 (dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12002584 if_id, DUAL_DUNIT_CFG_REG, 1 << 3,
Stefan Roese5ffceb82015-03-26 15:36:56 +01002585 1 << 3));
2586 }
2587 }
2588
2589 return (is_fail == 0) ? MV_OK : MV_FAIL;
2590}
2591
2592int ddr3_tip_register_dq_table(u32 dev_num, u32 *table)
2593{
2594 dq_map_table = table;
2595
2596 return MV_OK;
2597}
2598
2599/*
2600 * Check if pup search is locked
2601 */
2602int ddr3_tip_is_pup_lock(u32 *pup_buf, enum hws_training_result read_mode)
2603{
2604 u32 bit_start = 0, bit_end = 0, bit_id;
2605
2606 if (read_mode == RESULT_PER_BIT) {
2607 bit_start = 0;
2608 bit_end = BUS_WIDTH_IN_BITS - 1;
2609 } else {
2610 bit_start = 0;
2611 bit_end = 0;
2612 }
2613
2614 for (bit_id = bit_start; bit_id <= bit_end; bit_id++) {
2615 if (GET_LOCK_RESULT(pup_buf[bit_id]) == 0)
2616 return 0;
2617 }
2618
2619 return 1;
2620}
2621
2622/*
2623 * Get minimum buffer value
2624 */
2625u8 ddr3_tip_get_buf_min(u8 *buf_ptr)
2626{
2627 u8 min_val = 0xff;
2628 u8 cnt = 0;
2629
2630 for (cnt = 0; cnt < BUS_WIDTH_IN_BITS; cnt++) {
2631 if (buf_ptr[cnt] < min_val)
2632 min_val = buf_ptr[cnt];
2633 }
2634
2635 return min_val;
2636}
2637
2638/*
2639 * Get maximum buffer value
2640 */
2641u8 ddr3_tip_get_buf_max(u8 *buf_ptr)
2642{
2643 u8 max_val = 0;
2644 u8 cnt = 0;
2645
2646 for (cnt = 0; cnt < BUS_WIDTH_IN_BITS; cnt++) {
2647 if (buf_ptr[cnt] > max_val)
2648 max_val = buf_ptr[cnt];
2649 }
2650
2651 return max_val;
2652}
2653
2654/*
2655 * The following functions return memory parameters:
2656 * bus and device width, device size
2657 */
2658
2659u32 hws_ddr3_get_bus_width(void)
2660{
Chris Packham1a07d212018-05-10 13:28:29 +12002661 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002662
2663 return (DDR3_IS_16BIT_DRAM_MODE(tm->bus_act_mask) ==
2664 1) ? 16 : 32;
2665}
2666
2667u32 hws_ddr3_get_device_width(u32 if_id)
2668{
Chris Packham1a07d212018-05-10 13:28:29 +12002669 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002670
2671 return (tm->interface_params[if_id].bus_width ==
Chris Packham1a07d212018-05-10 13:28:29 +12002672 MV_DDR_DEV_WIDTH_8BIT) ? 8 : 16;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002673}
2674
2675u32 hws_ddr3_get_device_size(u32 if_id)
2676{
Chris Packham1a07d212018-05-10 13:28:29 +12002677 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002678
2679 if (tm->interface_params[if_id].memory_size >=
Chris Packham1a07d212018-05-10 13:28:29 +12002680 MV_DDR_DIE_CAP_LAST) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01002681 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2682 ("Error: Wrong device size of Cs: %d",
2683 tm->interface_params[if_id].memory_size));
2684 return 0;
2685 } else {
2686 return 1 << tm->interface_params[if_id].memory_size;
2687 }
2688}
2689
2690int hws_ddr3_calc_mem_cs_size(u32 if_id, u32 cs, u32 *cs_size)
2691{
2692 u32 cs_mem_size, dev_size;
2693
2694 dev_size = hws_ddr3_get_device_size(if_id);
2695 if (dev_size != 0) {
2696 cs_mem_size = ((hws_ddr3_get_bus_width() /
2697 hws_ddr3_get_device_width(if_id)) * dev_size);
2698
2699 /* the calculated result in Gbytex16 to avoid float using */
2700
2701 if (cs_mem_size == 2) {
2702 *cs_size = _128M;
2703 } else if (cs_mem_size == 4) {
2704 *cs_size = _256M;
2705 } else if (cs_mem_size == 8) {
2706 *cs_size = _512M;
2707 } else if (cs_mem_size == 16) {
2708 *cs_size = _1G;
2709 } else if (cs_mem_size == 32) {
2710 *cs_size = _2G;
2711 } else {
2712 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2713 ("Error: Wrong Memory size of Cs: %d", cs));
2714 return MV_FAIL;
2715 }
2716 return MV_OK;
2717 } else {
2718 return MV_FAIL;
2719 }
2720}
2721
2722int hws_ddr3_cs_base_adr_calc(u32 if_id, u32 cs, u32 *cs_base_addr)
2723{
2724 u32 cs_mem_size = 0;
2725#ifdef DEVICE_MAX_DRAM_ADDRESS_SIZE
2726 u32 physical_mem_size;
2727 u32 max_mem_size = DEVICE_MAX_DRAM_ADDRESS_SIZE;
2728#endif
2729
2730 if (hws_ddr3_calc_mem_cs_size(if_id, cs, &cs_mem_size) != MV_OK)
2731 return MV_FAIL;
2732
2733#ifdef DEVICE_MAX_DRAM_ADDRESS_SIZE
Chris Packham1a07d212018-05-10 13:28:29 +12002734 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002735 /*
2736 * if number of address pins doesn't allow to use max mem size that
2737 * is defined in topology mem size is defined by
2738 * DEVICE_MAX_DRAM_ADDRESS_SIZE
2739 */
Chris Packham1a07d212018-05-10 13:28:29 +12002740 physical_mem_size = mem_size[tm->interface_params[0].memory_size];
Stefan Roese5ffceb82015-03-26 15:36:56 +01002741
2742 if (hws_ddr3_get_device_width(cs) == 16) {
2743 /*
2744 * 16bit mem device can be twice more - no need in less
2745 * significant pin
2746 */
2747 max_mem_size = DEVICE_MAX_DRAM_ADDRESS_SIZE * 2;
2748 }
2749
2750 if (physical_mem_size > max_mem_size) {
2751 cs_mem_size = max_mem_size *
2752 (hws_ddr3_get_bus_width() /
2753 hws_ddr3_get_device_width(if_id));
2754 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2755 ("Updated Physical Mem size is from 0x%x to %x\n",
2756 physical_mem_size,
2757 DEVICE_MAX_DRAM_ADDRESS_SIZE));
2758 }
2759#endif
2760
2761 /* calculate CS base addr */
2762 *cs_base_addr = ((cs_mem_size) * cs) & 0xffff0000;
2763
2764 return MV_OK;
2765}
Chris Packham4bf81db2018-12-03 14:26:49 +13002766
2767/* TODO: consider to move to misl phy driver */
2768enum {
2769 MISL_PHY_DRV_OHM_30 = 0xf,
2770 MISL_PHY_DRV_OHM_48 = 0xa,
2771 MISL_PHY_DRV_OHM_80 = 0x6,
2772 MISL_PHY_DRV_OHM_120 = 0x4
2773};
2774
2775enum {
2776 MISL_PHY_ODT_OHM_60 = 0x8,
2777 MISL_PHY_ODT_OHM_80 = 0x6,
2778 MISL_PHY_ODT_OHM_120 = 0x4,
2779 MISL_PHY_ODT_OHM_240 = 0x2
2780};
2781
2782static unsigned int mv_ddr_misl_phy_drv_calc(unsigned int cfg)
2783{
2784 unsigned int val;
2785
2786 switch (cfg) {
2787 case MV_DDR_OHM_30:
2788 val = MISL_PHY_DRV_OHM_30;
2789 break;
2790 case MV_DDR_OHM_48:
2791 val = MISL_PHY_DRV_OHM_48;
2792 break;
2793 case MV_DDR_OHM_80:
2794 val = MISL_PHY_DRV_OHM_80;
2795 break;
2796 case MV_DDR_OHM_120:
2797 val = MISL_PHY_DRV_OHM_120;
2798 break;
2799 default:
2800 val = PARAM_UNDEFINED;
2801 }
2802
2803 return val;
2804}
2805
2806static unsigned int mv_ddr_misl_phy_odt_calc(unsigned int cfg)
2807{
2808 unsigned int val;
2809
2810 switch (cfg) {
2811 case MV_DDR_OHM_60:
2812 val = MISL_PHY_ODT_OHM_60;
2813 break;
2814 case MV_DDR_OHM_80:
2815 val = MISL_PHY_ODT_OHM_80;
2816 break;
2817 case MV_DDR_OHM_120:
2818 val = MISL_PHY_ODT_OHM_120;
2819 break;
2820 case MV_DDR_OHM_240:
2821 val = MISL_PHY_ODT_OHM_240;
2822 break;
2823 default:
2824 val = PARAM_UNDEFINED;
2825 }
2826
2827 return val;
2828}
2829
2830unsigned int mv_ddr_misl_phy_drv_data_p_get(void)
2831{
2832 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2833 unsigned int drv_data_p = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_data_p);
2834
2835 if (drv_data_p == PARAM_UNDEFINED)
2836 printf("error: %s: unsupported drv_data_p parameter found\n", __func__);
2837
2838 return drv_data_p;
2839}
2840
2841unsigned int mv_ddr_misl_phy_drv_data_n_get(void)
2842{
2843 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2844 unsigned int drv_data_n = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_data_n);
2845
2846 if (drv_data_n == PARAM_UNDEFINED)
2847 printf("error: %s: unsupported drv_data_n parameter found\n", __func__);
2848
2849 return drv_data_n;
2850}
2851
2852unsigned int mv_ddr_misl_phy_drv_ctrl_p_get(void)
2853{
2854 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2855 unsigned int drv_ctrl_p = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_ctrl_p);
2856
2857 if (drv_ctrl_p == PARAM_UNDEFINED)
2858 printf("error: %s: unsupported drv_ctrl_p parameter found\n", __func__);
2859
2860 return drv_ctrl_p;
2861}
2862
2863unsigned int mv_ddr_misl_phy_drv_ctrl_n_get(void)
2864{
2865 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2866 unsigned int drv_ctrl_n = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_ctrl_n);
2867
2868 if (drv_ctrl_n == PARAM_UNDEFINED)
2869 printf("error: %s: unsupported drv_ctrl_n parameter found\n", __func__);
2870
2871 return drv_ctrl_n;
2872}
2873
2874unsigned int mv_ddr_misl_phy_odt_p_get(void)
2875{
2876 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2877 unsigned int cs_num = mv_ddr_cs_num_get();
2878 unsigned int odt_p = PARAM_UNDEFINED;
2879
2880 if (cs_num > 0 && cs_num <= MAX_CS_NUM)
2881 odt_p = mv_ddr_misl_phy_odt_calc(tm->edata.phy_edata.odt_p[cs_num - 1]);
2882
2883 if (odt_p == PARAM_UNDEFINED)
2884 printf("error: %s: unsupported odt_p parameter found\n", __func__);
2885
2886 return odt_p;
2887}
2888
2889unsigned int mv_ddr_misl_phy_odt_n_get(void)
2890{
2891 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2892 unsigned int cs_num = mv_ddr_cs_num_get();
2893 unsigned int odt_n = PARAM_UNDEFINED;
2894
2895 if (cs_num > 0 && cs_num <= MAX_CS_NUM)
2896 odt_n = mv_ddr_misl_phy_odt_calc(tm->edata.phy_edata.odt_n[cs_num - 1]);
2897
2898 if (odt_n == PARAM_UNDEFINED)
2899 printf("error: %s: unsupported odt_n parameter found\n", __func__);
2900
2901 return odt_n;
2902}