blob: 0358f6287a8097d25f0621426a67c6e35c0862c9 [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"
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Stefan Roese5ffceb82015-03-26 15:36:56 +010012
13#define GET_CS_FROM_MASK(mask) (cs_mask2_num[mask])
14#define CS_CBE_VALUE(cs_num) (cs_cbe_reg[cs_num])
15
16u32 window_mem_addr = 0;
17u32 phy_reg0_val = 0;
18u32 phy_reg1_val = 8;
19u32 phy_reg2_val = 0;
Chris Packham1a07d212018-05-10 13:28:29 +120020u32 phy_reg3_val = PARAM_UNDEFINED;
Chris Packham4bf81db2018-12-03 14:26:49 +130021enum mv_ddr_freq low_freq = MV_DDR_FREQ_LOW_FREQ;
22enum mv_ddr_freq medium_freq;
Stefan Roese5ffceb82015-03-26 15:36:56 +010023u32 debug_dunit = 0;
24u32 odt_additional = 1;
25u32 *dq_map_table = NULL;
Chris Packham1a07d212018-05-10 13:28:29 +120026
27/* in case of ddr4 do not run ddr3_tip_write_additional_odt_setting function - mc odt always 'on'
28 * in ddr4 case the terminations are rttWR and rttPARK and the odt must be always 'on' 0x1498 = 0xf
29 */
Stefan Roese5ffceb82015-03-26 15:36:56 +010030u32 odt_config = 1;
31
Chris Packham1a07d212018-05-10 13:28:29 +120032u32 nominal_avs;
33u32 extension_avs;
34
Stefan Roese5ffceb82015-03-26 15:36:56 +010035u32 is_pll_before_init = 0, is_adll_calib_before_init = 1, is_dfs_in_init = 0;
Chris Packham1a07d212018-05-10 13:28:29 +120036u32 dfs_low_freq;
37
38u32 g_rtt_nom_cs0, g_rtt_nom_cs1;
Stefan Roese5ffceb82015-03-26 15:36:56 +010039u8 calibration_update_control; /* 2 external only, 1 is internal only */
40
41enum hws_result training_result[MAX_STAGE_LIMIT][MAX_INTERFACE_NUM];
42enum auto_tune_stage training_stage = INIT_CONTROLLER;
43u32 finger_test = 0, p_finger_start = 11, p_finger_end = 64,
44 n_finger_start = 11, n_finger_end = 64,
45 p_finger_step = 3, n_finger_step = 3;
46u32 clamp_tbl[] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
47
48/* Initiate to 0xff, this variable is define by user in debug mode */
Chris Packham1a07d212018-05-10 13:28:29 +120049u32 mode_2t = 0xff;
Stefan Roese5ffceb82015-03-26 15:36:56 +010050u32 xsb_validate_type = 0;
51u32 xsb_validation_base_address = 0xf000;
52u32 first_active_if = 0;
53u32 dfs_low_phy1 = 0x1f;
54u32 multicast_id = 0;
55int use_broadcast = 0;
56struct hws_tip_freq_config_info *freq_info_table = NULL;
57u8 is_cbe_required = 0;
58u32 debug_mode = 0;
59u32 delay_enable = 0;
60int rl_mid_freq_wa = 0;
61
62u32 effective_cs = 0;
63
Chris Packham1a07d212018-05-10 13:28:29 +120064u32 vref_init_val = 0x4;
65u32 ck_delay = PARAM_UNDEFINED;
66
67/* Design guidelines parameters */
68u32 g_zpri_data = PARAM_UNDEFINED; /* controller data - P drive strength */
69u32 g_znri_data = PARAM_UNDEFINED; /* controller data - N drive strength */
70u32 g_zpri_ctrl = PARAM_UNDEFINED; /* controller C/A - P drive strength */
71u32 g_znri_ctrl = PARAM_UNDEFINED; /* controller C/A - N drive strength */
72
73u32 g_zpodt_data = PARAM_UNDEFINED; /* controller data - P ODT */
74u32 g_znodt_data = PARAM_UNDEFINED; /* controller data - N ODT */
75u32 g_zpodt_ctrl = PARAM_UNDEFINED; /* controller data - P ODT */
76u32 g_znodt_ctrl = PARAM_UNDEFINED; /* controller data - N ODT */
77
78u32 g_odt_config = PARAM_UNDEFINED;
79u32 g_rtt_nom = PARAM_UNDEFINED;
80u32 g_rtt_wr = PARAM_UNDEFINED;
81u32 g_dic = PARAM_UNDEFINED;
82u32 g_rtt_park = PARAM_UNDEFINED;
83
Stefan Roese5ffceb82015-03-26 15:36:56 +010084u32 mask_tune_func = (SET_MEDIUM_FREQ_MASK_BIT |
85 WRITE_LEVELING_MASK_BIT |
86 LOAD_PATTERN_2_MASK_BIT |
87 READ_LEVELING_MASK_BIT |
Chris Packham1a07d212018-05-10 13:28:29 +120088 SET_TARGET_FREQ_MASK_BIT |
89 WRITE_LEVELING_TF_MASK_BIT |
Stefan Roese5ffceb82015-03-26 15:36:56 +010090 READ_LEVELING_TF_MASK_BIT |
Chris Packham1a07d212018-05-10 13:28:29 +120091 CENTRALIZATION_RX_MASK_BIT |
92 CENTRALIZATION_TX_MASK_BIT);
Stefan Roese5ffceb82015-03-26 15:36:56 +010093
94static int ddr3_tip_ddr3_training_main_flow(u32 dev_num);
95static int ddr3_tip_write_odt(u32 dev_num, enum hws_access_type access_type,
96 u32 if_id, u32 cl_value, u32 cwl_value);
97static int ddr3_tip_ddr3_auto_tune(u32 dev_num);
Chris Packham1a07d212018-05-10 13:28:29 +120098
Stefan Roese5ffceb82015-03-26 15:36:56 +010099#ifdef ODT_TEST_SUPPORT
100static int odt_test(u32 dev_num, enum hws_algo_type algo_type);
101#endif
102
103int adll_calibration(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);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100105static int ddr3_tip_set_timing(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +1300106 u32 if_id, enum mv_ddr_freq frequency);
Chris Packham1a07d212018-05-10 13:28:29 +1200107
108static u8 mem_size_config[MV_DDR_DIE_CAP_LAST] = {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100109 0x2, /* 512Mbit */
110 0x3, /* 1Gbit */
111 0x0, /* 2Gbit */
112 0x4, /* 4Gbit */
Chris Packham1a07d212018-05-10 13:28:29 +1200113 0x5, /* 8Gbit */
114 0x0, /* TODO: placeholder for 16-Mbit die capacity */
115 0x0, /* TODO: placeholder for 32-Mbit die capacity */
116 0x0, /* TODO: placeholder for 12-Mbit die capacity */
117 0x0 /* TODO: placeholder for 24-Mbit die capacity */
Stefan Roese5ffceb82015-03-26 15:36:56 +0100118};
119
120static u8 cs_mask2_num[] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 };
121
122static struct reg_data odpg_default_value[] = {
123 {0x1034, 0x38000, MASK_ALL_BITS},
124 {0x1038, 0x0, MASK_ALL_BITS},
125 {0x10b0, 0x0, MASK_ALL_BITS},
126 {0x10b8, 0x0, MASK_ALL_BITS},
127 {0x10c0, 0x0, MASK_ALL_BITS},
128 {0x10f0, 0x0, MASK_ALL_BITS},
129 {0x10f4, 0x0, MASK_ALL_BITS},
130 {0x10f8, 0xff, MASK_ALL_BITS},
131 {0x10fc, 0xffff, MASK_ALL_BITS},
132 {0x1130, 0x0, MASK_ALL_BITS},
133 {0x1830, 0x2000000, MASK_ALL_BITS},
134 {0x14d0, 0x0, MASK_ALL_BITS},
135 {0x14d4, 0x0, MASK_ALL_BITS},
136 {0x14d8, 0x0, MASK_ALL_BITS},
137 {0x14dc, 0x0, MASK_ALL_BITS},
138 {0x1454, 0x0, MASK_ALL_BITS},
139 {0x1594, 0x0, MASK_ALL_BITS},
140 {0x1598, 0x0, MASK_ALL_BITS},
141 {0x159c, 0x0, MASK_ALL_BITS},
142 {0x15a0, 0x0, MASK_ALL_BITS},
143 {0x15a4, 0x0, MASK_ALL_BITS},
144 {0x15a8, 0x0, MASK_ALL_BITS},
145 {0x15ac, 0x0, MASK_ALL_BITS},
Marek Behúnb9eaf112021-02-19 17:11:23 +0100146 {0x1600, 0x0, MASK_ALL_BITS},
Stefan Roese5ffceb82015-03-26 15:36:56 +0100147 {0x1604, 0x0, MASK_ALL_BITS},
148 {0x1608, 0x0, MASK_ALL_BITS},
149 {0x160c, 0x0, MASK_ALL_BITS},
150 {0x1610, 0x0, MASK_ALL_BITS},
151 {0x1614, 0x0, MASK_ALL_BITS},
152 {0x1618, 0x0, MASK_ALL_BITS},
153 {0x1624, 0x0, MASK_ALL_BITS},
154 {0x1690, 0x0, MASK_ALL_BITS},
155 {0x1694, 0x0, MASK_ALL_BITS},
156 {0x1698, 0x0, MASK_ALL_BITS},
157 {0x169c, 0x0, MASK_ALL_BITS},
158 {0x14b8, 0x6f67, MASK_ALL_BITS},
159 {0x1630, 0x0, MASK_ALL_BITS},
160 {0x1634, 0x0, MASK_ALL_BITS},
161 {0x1638, 0x0, MASK_ALL_BITS},
162 {0x163c, 0x0, MASK_ALL_BITS},
163 {0x16b0, 0x0, MASK_ALL_BITS},
164 {0x16b4, 0x0, MASK_ALL_BITS},
165 {0x16b8, 0x0, MASK_ALL_BITS},
166 {0x16bc, 0x0, MASK_ALL_BITS},
167 {0x16c0, 0x0, MASK_ALL_BITS},
168 {0x16c4, 0x0, MASK_ALL_BITS},
169 {0x16c8, 0x0, MASK_ALL_BITS},
170 {0x16cc, 0x1, MASK_ALL_BITS},
171 {0x16f0, 0x1, MASK_ALL_BITS},
172 {0x16f4, 0x0, MASK_ALL_BITS},
173 {0x16f8, 0x0, MASK_ALL_BITS},
174 {0x16fc, 0x0, MASK_ALL_BITS}
175};
176
Chris Packham1a07d212018-05-10 13:28:29 +1200177/* MR cmd and addr definitions */
178struct mv_ddr_mr_data mr_data[] = {
179 {MRS0_CMD, MR0_REG},
180 {MRS1_CMD, MR1_REG},
181 {MRS2_CMD, MR2_REG},
182 {MRS3_CMD, MR3_REG}
183};
184
Chris Packham4bf81db2018-12-03 14:26:49 +1300185/* inverse pads */
186static int ddr3_tip_pad_inv(void)
187{
188 u32 sphy, data;
189 u32 sphy_max = ddr3_tip_dev_attr_get(0, MV_ATTR_OCTET_PER_INTERFACE);
190 u32 ck_swap_ctrl_sphy;
191 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
192
193 for (sphy = 0; sphy < sphy_max; sphy++) {
194 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, sphy);
195 if (tm->interface_params[0].
196 as_bus_params[sphy].is_dqs_swap == 1) {
197 data = (INVERT_PAD << INV_PAD4_OFFS |
198 INVERT_PAD << INV_PAD5_OFFS);
199 /* dqs swap */
200 ddr3_tip_bus_read_modify_write(0, ACCESS_TYPE_UNICAST,
201 0, sphy,
202 DDR_PHY_DATA,
203 PHY_CTRL_PHY_REG,
204 data, data);
205 }
206
207 if (tm->interface_params[0].as_bus_params[sphy].
208 is_ck_swap == 1 && sphy == 0) {
209/* TODO: move this code to per platform one */
210#if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_39X)
211 /* clock swap for both cs0 and cs1 */
212 data = (INVERT_PAD << INV_PAD2_OFFS |
213 INVERT_PAD << INV_PAD6_OFFS |
214 INVERT_PAD << INV_PAD4_OFFS |
215 INVERT_PAD << INV_PAD5_OFFS);
216 ck_swap_ctrl_sphy = CK_SWAP_CTRL_PHY_NUM;
217 ddr3_tip_bus_read_modify_write(0, ACCESS_TYPE_UNICAST,
218 0, ck_swap_ctrl_sphy,
219 DDR_PHY_CONTROL,
220 PHY_CTRL_PHY_REG,
221 data, data);
222#else /* !CONFIG_ARMADA_38X && !CONFIG_ARMADA_39X && !A70X0 && !A80X0 && !A3900 */
223#pragma message "unknown platform to configure ddr clock swap"
224#endif
225 }
226 }
227
228 return MV_OK;
229}
230
Stefan Roese5ffceb82015-03-26 15:36:56 +0100231static int ddr3_tip_rank_control(u32 dev_num, u32 if_id);
232
233/*
234 * Update global training parameters by data from user
235 */
236int ddr3_tip_tune_training_params(u32 dev_num,
237 struct tune_train_params *params)
238{
Chris Packham1a07d212018-05-10 13:28:29 +1200239 if (params->ck_delay != PARAM_UNDEFINED)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100240 ck_delay = params->ck_delay;
Chris Packham1a07d212018-05-10 13:28:29 +1200241 if (params->phy_reg3_val != PARAM_UNDEFINED)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100242 phy_reg3_val = params->phy_reg3_val;
Chris Packham1a07d212018-05-10 13:28:29 +1200243 if (params->g_rtt_nom != PARAM_UNDEFINED)
244 g_rtt_nom = params->g_rtt_nom;
245 if (params->g_rtt_wr != PARAM_UNDEFINED)
246 g_rtt_wr = params->g_rtt_wr;
247 if (params->g_dic != PARAM_UNDEFINED)
248 g_dic = params->g_dic;
249 if (params->g_odt_config != PARAM_UNDEFINED)
250 g_odt_config = params->g_odt_config;
251 if (params->g_zpri_data != PARAM_UNDEFINED)
252 g_zpri_data = params->g_zpri_data;
253 if (params->g_znri_data != PARAM_UNDEFINED)
254 g_znri_data = params->g_znri_data;
255 if (params->g_zpri_ctrl != PARAM_UNDEFINED)
256 g_zpri_ctrl = params->g_zpri_ctrl;
257 if (params->g_znri_ctrl != PARAM_UNDEFINED)
258 g_znri_ctrl = params->g_znri_ctrl;
259 if (params->g_zpodt_data != PARAM_UNDEFINED)
260 g_zpodt_data = params->g_zpodt_data;
261 if (params->g_znodt_data != PARAM_UNDEFINED)
262 g_znodt_data = params->g_znodt_data;
263 if (params->g_zpodt_ctrl != PARAM_UNDEFINED)
264 g_zpodt_ctrl = params->g_zpodt_ctrl;
265 if (params->g_znodt_ctrl != PARAM_UNDEFINED)
266 g_znodt_ctrl = params->g_znodt_ctrl;
267 if (params->g_rtt_park != PARAM_UNDEFINED)
268 g_rtt_park = params->g_rtt_park;
269
Chris Packham4bf81db2018-12-03 14:26:49 +1300270
Chris Packham1a07d212018-05-10 13:28:29 +1200271 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
272 ("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",
273 g_zpri_data, g_znri_data, g_zpri_ctrl, g_znri_ctrl, g_zpodt_data, g_znodt_data,
274 g_zpodt_ctrl, g_znodt_ctrl, g_rtt_nom, g_dic, g_odt_config, g_rtt_wr));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100275
276 return MV_OK;
277}
278
279/*
280 * Configure CS
281 */
282int ddr3_tip_configure_cs(u32 dev_num, u32 if_id, u32 cs_num, u32 enable)
283{
284 u32 data, addr_hi, data_high;
285 u32 mem_index;
Baruch Siach24a1d132020-01-20 14:20:06 +0200286 u32 clk_enable;
Chris Packham1a07d212018-05-10 13:28:29 +1200287 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100288
Baruch Siach24a1d132020-01-20 14:20:06 +0200289 if (tm->clk_enable & (1 << cs_num))
290 clk_enable = 1;
291 else
292 clk_enable = enable;
293
Stefan Roese5ffceb82015-03-26 15:36:56 +0100294 if (enable == 1) {
295 data = (tm->interface_params[if_id].bus_width ==
Chris Packham1a07d212018-05-10 13:28:29 +1200296 MV_DDR_DEV_WIDTH_8BIT) ? 0 : 1;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100297 CHECK_STATUS(ddr3_tip_if_write
298 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200299 SDRAM_ADDR_CTRL_REG, (data << (cs_num * 4)),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100300 0x3 << (cs_num * 4)));
301 mem_index = tm->interface_params[if_id].memory_size;
302
303 addr_hi = mem_size_config[mem_index] & 0x3;
304 CHECK_STATUS(ddr3_tip_if_write
305 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200306 SDRAM_ADDR_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100307 (addr_hi << (2 + cs_num * 4)),
308 0x3 << (2 + cs_num * 4)));
309
310 data_high = (mem_size_config[mem_index] & 0x4) >> 2;
311 CHECK_STATUS(ddr3_tip_if_write
312 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200313 SDRAM_ADDR_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100314 data_high << (20 + cs_num), 1 << (20 + cs_num)));
315
316 /* Enable Address Select Mode */
317 CHECK_STATUS(ddr3_tip_if_write
318 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200319 SDRAM_ADDR_CTRL_REG, 1 << (16 + cs_num),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100320 1 << (16 + cs_num)));
321 }
322 switch (cs_num) {
323 case 0:
324 case 1:
325 case 2:
326 CHECK_STATUS(ddr3_tip_if_write
327 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Baruch Siach24a1d132020-01-20 14:20:06 +0200328 DUNIT_CTRL_LOW_REG, (clk_enable << (cs_num + 11)),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100329 1 << (cs_num + 11)));
330 break;
331 case 3:
332 CHECK_STATUS(ddr3_tip_if_write
333 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Baruch Siach24a1d132020-01-20 14:20:06 +0200334 DUNIT_CTRL_LOW_REG, (clk_enable << 15), 1 << 15));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100335 break;
336 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100337
338 return MV_OK;
339}
340
341/*
342 * Init Controller Flow
343 */
344int hws_ddr3_tip_init_controller(u32 dev_num, struct init_cntr_param *init_cntr_prm)
345{
346 u32 if_id;
347 u32 cs_num;
Chris Packham1a07d212018-05-10 13:28:29 +1200348 u32 t_ckclk = 0, t_wr = 0, t2t = 0;
349 u32 data_value = 0, cs_cnt = 0,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100350 mem_mask = 0, bus_index = 0;
Chris Packham4bf81db2018-12-03 14:26:49 +1300351 enum mv_ddr_speed_bin speed_bin_index = SPEED_BIN_DDR_2133N;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100352 u32 cs_mask = 0;
353 u32 cl_value = 0, cwl_val = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200354 u32 bus_cnt = 0, adll_tap = 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100355 enum hws_access_type access_type = ACCESS_TYPE_UNICAST;
356 u32 data_read[MAX_INTERFACE_NUM];
Chris Packham1a07d212018-05-10 13:28:29 +1200357 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
358 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Chris Packham3a09e132018-05-10 13:28:30 +1200359 enum mv_ddr_timing timing;
Chris Packham4bf81db2018-12-03 14:26:49 +1300360 enum mv_ddr_freq freq = tm->interface_params[0].memory_freq;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100361
362 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
363 ("Init_controller, do_mrs_phy=%d, is_ctrl64_bit=%d\n",
364 init_cntr_prm->do_mrs_phy,
365 init_cntr_prm->is_ctrl64_bit));
366
367 if (init_cntr_prm->init_phy == 1) {
368 CHECK_STATUS(ddr3_tip_configure_phy(dev_num));
369 }
370
371 if (generic_init_controller == 1) {
372 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200373 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100374 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
375 ("active IF %d\n", if_id));
376 mem_mask = 0;
377 for (bus_index = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200378 bus_index < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100379 bus_index++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200380 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_index);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100381 mem_mask |=
382 tm->interface_params[if_id].
383 as_bus_params[bus_index].mirror_enable_bitmask;
384 }
385
386 if (mem_mask != 0) {
387 CHECK_STATUS(ddr3_tip_if_write
388 (dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200389 if_id, DUAL_DUNIT_CFG_REG, 0,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100390 0x8));
391 }
392
Stefan Roese5ffceb82015-03-26 15:36:56 +0100393 speed_bin_index =
394 tm->interface_params[if_id].
395 speed_bin_index;
Chris Packham1a07d212018-05-10 13:28:29 +1200396
Stefan Roese5ffceb82015-03-26 15:36:56 +0100397 /* t_ckclk is external clock */
Chris Packham4bf81db2018-12-03 14:26:49 +1300398 t_ckclk = (MEGA / mv_ddr_freq_get(freq));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100399
Chris Packham1a07d212018-05-10 13:28:29 +1200400 if (MV_DDR_IS_HALF_BUS_DRAM_MODE(tm->bus_act_mask, octets_per_if_num))
401 data_value = (0x4000 | 0 | 0x1000000) & ~(1 << 26);
402 else
403 data_value = (0x4000 | 0x8000 | 0x1000000) & ~(1 << 26);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100404
405 /* Interface Bus Width */
406 /* SRMode */
407 CHECK_STATUS(ddr3_tip_if_write
408 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200409 SDRAM_CFG_REG, data_value,
410 0x100c000));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100411
412 /* Interleave first command pre-charge enable (TBD) */
413 CHECK_STATUS(ddr3_tip_if_write
414 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200415 SDRAM_OPEN_PAGES_CTRL_REG, (1 << 10),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100416 (1 << 10)));
417
Chris Packham1a07d212018-05-10 13:28:29 +1200418 /* Reset divider_b assert -> de-assert */
419 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
420 SDRAM_CFG_REG,
421 0x0 << PUP_RST_DIVIDER_OFFS,
422 PUP_RST_DIVIDER_MASK << PUP_RST_DIVIDER_OFFS));
423
424 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
425 SDRAM_CFG_REG,
426 0x1 << PUP_RST_DIVIDER_OFFS,
427 PUP_RST_DIVIDER_MASK << PUP_RST_DIVIDER_OFFS));
428
Stefan Roese5ffceb82015-03-26 15:36:56 +0100429 /* PHY configuration */
430 /*
431 * Postamble Length = 1.5cc, Addresscntl to clk skew
432 * \BD, Preamble length normal, parralal ADLL enable
433 */
434 CHECK_STATUS(ddr3_tip_if_write
435 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200436 DRAM_PHY_CFG_REG, 0x28, 0x3e));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100437 if (init_cntr_prm->is_ctrl64_bit) {
438 /* positive edge */
439 CHECK_STATUS(ddr3_tip_if_write
440 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200441 DRAM_PHY_CFG_REG, 0x0,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100442 0xff80));
443 }
444
445 /* calibration block disable */
446 /* Xbar Read buffer select (for Internal access) */
447 CHECK_STATUS(ddr3_tip_if_write
448 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200449 MAIN_PADS_CAL_MACH_CTRL_REG, 0x1200c,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100450 0x7dffe01c));
451 CHECK_STATUS(ddr3_tip_if_write
452 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200453 MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100454 calibration_update_control << 3, 0x3 << 3));
455
456 /* Pad calibration control - enable */
457 CHECK_STATUS(ddr3_tip_if_write
458 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200459 MAIN_PADS_CAL_MACH_CTRL_REG, 0x1, 0x1));
460 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) < MV_TIP_REV_3) {
461 /* DDR3 rank ctrl \96 part of the generic code */
462 /* CS1 mirroring enable + w/a for JIRA DUNIT-14581 */
463 CHECK_STATUS(ddr3_tip_if_write
464 (dev_num, access_type, if_id,
465 DDR3_RANK_CTRL_REG, 0x27, MASK_ALL_BITS));
466 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100467
468 cs_mask = 0;
469 data_value = 0x7;
470 /*
471 * Address ctrl \96 Part of the Generic code
472 * The next configuration is done:
473 * 1) Memory Size
474 * 2) Bus_width
475 * 3) CS#
476 * 4) Page Number
Stefan Roese5ffceb82015-03-26 15:36:56 +0100477 * Per Dunit get from the Map_topology the parameters:
478 * Bus_width
Stefan Roese5ffceb82015-03-26 15:36:56 +0100479 */
Stefan Roese5ffceb82015-03-26 15:36:56 +0100480
481 data_value =
482 (tm->interface_params[if_id].
Chris Packham1a07d212018-05-10 13:28:29 +1200483 bus_width == MV_DDR_DEV_WIDTH_8BIT) ? 0 : 1;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100484
485 /* create merge cs mask for all cs available in dunit */
486 for (bus_cnt = 0;
Chris Packham1a07d212018-05-10 13:28:29 +1200487 bus_cnt < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100488 bus_cnt++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200489 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100490 cs_mask |=
491 tm->interface_params[if_id].
492 as_bus_params[bus_cnt].cs_bitmask;
493 }
494 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
495 ("Init_controller IF %d cs_mask %d\n",
496 if_id, cs_mask));
497 /*
498 * Configure the next upon the Map Topology \96 If the
499 * Dunit is CS0 Configure CS0 if it is multi CS
500 * configure them both: The Bust_width it\92s the
501 * Memory Bus width \96 x8 or x16
502 */
Chris Packham4bf81db2018-12-03 14:26:49 +1300503 for (cs_cnt = 0; cs_cnt < MAX_CS_NUM; cs_cnt++) {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100504 ddr3_tip_configure_cs(dev_num, if_id, cs_cnt,
505 ((cs_mask & (1 << cs_cnt)) ? 1
506 : 0));
507 }
508
509 if (init_cntr_prm->do_mrs_phy) {
510 /*
511 * MR0 \96 Part of the Generic code
512 * The next configuration is done:
513 * 1) Burst Length
514 * 2) CAS Latency
515 * get for each dunit what is it Speed_bin &
516 * Target Frequency. From those both parameters
517 * get the appropriate Cas_l from the CL table
518 */
519 cl_value =
520 tm->interface_params[if_id].
521 cas_l;
522 cwl_val =
523 tm->interface_params[if_id].
524 cas_wl;
525 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
526 ("cl_value 0x%x cwl_val 0x%x\n",
527 cl_value, cwl_val));
Chris Packham1a07d212018-05-10 13:28:29 +1200528
Chris Packham4bf81db2018-12-03 14:26:49 +1300529 t_wr = time_to_nclk(mv_ddr_speed_bin_timing_get
Chris Packham1a07d212018-05-10 13:28:29 +1200530 (speed_bin_index,
531 SPEED_BIN_TWR), t_ckclk);
532
Stefan Roese5ffceb82015-03-26 15:36:56 +0100533 data_value =
534 ((cl_mask_table[cl_value] & 0x1) << 2) |
535 ((cl_mask_table[cl_value] & 0xe) << 3);
536 CHECK_STATUS(ddr3_tip_if_write
537 (dev_num, access_type, if_id,
538 MR0_REG, data_value,
539 (0x7 << 4) | (1 << 2)));
540 CHECK_STATUS(ddr3_tip_if_write
541 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200542 MR0_REG, twr_mask_table[t_wr] << 9,
543 0x7 << 9));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100544
545 /*
546 * MR1: Set RTT and DIC Design GL values
547 * configured by user
548 */
549 CHECK_STATUS(ddr3_tip_if_write
550 (dev_num, ACCESS_TYPE_MULTICAST,
551 PARAM_NOT_CARE, MR1_REG,
552 g_dic | g_rtt_nom, 0x266));
553
554 /* MR2 - Part of the Generic code */
555 /*
556 * The next configuration is done:
557 * 1) SRT
558 * 2) CAS Write Latency
559 */
560 data_value = (cwl_mask_table[cwl_val] << 3);
561 data_value |=
562 ((tm->interface_params[if_id].
563 interface_temp ==
Chris Packham1a07d212018-05-10 13:28:29 +1200564 MV_DDR_TEMP_HIGH) ? (1 << 7) : 0);
565 data_value |= g_rtt_wr;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100566 CHECK_STATUS(ddr3_tip_if_write
567 (dev_num, access_type, if_id,
568 MR2_REG, data_value,
569 (0x7 << 3) | (0x1 << 7) | (0x3 <<
570 9)));
571 }
572
573 ddr3_tip_write_odt(dev_num, access_type, if_id,
574 cl_value, cwl_val);
575 ddr3_tip_set_timing(dev_num, access_type, if_id, freq);
576
Chris Packham1a07d212018-05-10 13:28:29 +1200577 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) < MV_TIP_REV_3) {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100578 CHECK_STATUS(ddr3_tip_if_write
579 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200580 DUNIT_CTRL_HIGH_REG, 0x1000119,
581 0x100017F));
582 } else {
583 CHECK_STATUS(ddr3_tip_if_write
584 (dev_num, access_type, if_id,
585 DUNIT_CTRL_HIGH_REG, 0x600177 |
586 (init_cntr_prm->is_ctrl64_bit ?
587 CPU_INTERJECTION_ENA_SPLIT_ENA << CPU_INTERJECTION_ENA_OFFS :
588 CPU_INTERJECTION_ENA_SPLIT_DIS << CPU_INTERJECTION_ENA_OFFS),
589 0x1600177 | CPU_INTERJECTION_ENA_MASK <<
590 CPU_INTERJECTION_ENA_OFFS));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100591 }
592
593 /* reset bit 7 */
594 CHECK_STATUS(ddr3_tip_if_write
595 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200596 DUNIT_CTRL_HIGH_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100597 (init_cntr_prm->msys_init << 7), (1 << 7)));
598
Chris Packham3a09e132018-05-10 13:28:30 +1200599 timing = tm->interface_params[if_id].timing;
600
Chris Packham1a07d212018-05-10 13:28:29 +1200601 if (mode_2t != 0xff) {
602 t2t = mode_2t;
Chris Packham3a09e132018-05-10 13:28:30 +1200603 } else if (timing != MV_DDR_TIM_DEFAULT) {
604 t2t = (timing == MV_DDR_TIM_2T) ? 1 : 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100605 } else {
Chris Packham1a07d212018-05-10 13:28:29 +1200606 /* calculate number of CS (per interface) */
Chris Packham4bf81db2018-12-03 14:26:49 +1300607 cs_num = mv_ddr_cs_num_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100608 t2t = (cs_num == 1) ? 0 : 1;
609 }
610
611 CHECK_STATUS(ddr3_tip_if_write
612 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200613 DUNIT_CTRL_LOW_REG, t2t << 3,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100614 0x3 << 3));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100615 CHECK_STATUS(ddr3_tip_if_write
616 (dev_num, access_type, if_id,
617 DDR_TIMING_REG, 0x28 << 9, 0x3f << 9));
618 CHECK_STATUS(ddr3_tip_if_write
619 (dev_num, access_type, if_id,
620 DDR_TIMING_REG, 0xa << 21, 0xff << 21));
621
622 /* move the block to ddr3_tip_set_timing - end */
623 /* AUTO_ZQC_TIMING */
624 CHECK_STATUS(ddr3_tip_if_write
625 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200626 ZQC_CFG_REG, (AUTO_ZQC_TIMING | (2 << 20)),
Stefan Roese5ffceb82015-03-26 15:36:56 +0100627 0x3fffff));
628 CHECK_STATUS(ddr3_tip_if_read
629 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200630 DRAM_PHY_CFG_REG, data_read, 0x30));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100631 data_value =
632 (data_read[if_id] == 0) ? (1 << 11) : 0;
633 CHECK_STATUS(ddr3_tip_if_write
634 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200635 DUNIT_CTRL_HIGH_REG, data_value,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100636 (1 << 11)));
637
638 /* Set Active control for ODT write transactions */
639 CHECK_STATUS(ddr3_tip_if_write
640 (dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +1200641 PARAM_NOT_CARE, 0x1494, g_odt_config,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100642 MASK_ALL_BITS));
Chris Packham1a07d212018-05-10 13:28:29 +1200643
644 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) == MV_TIP_REV_3) {
645 CHECK_STATUS(ddr3_tip_if_write
646 (dev_num, access_type, if_id,
647 0x14a8, 0x900, 0x900));
648 /* wa: controls control sub-phy outputs floating during self-refresh */
649 CHECK_STATUS(ddr3_tip_if_write
650 (dev_num, access_type, if_id,
651 0x16d0, 0, 0x8000));
652 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100653 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100654 }
655
656 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +1200657 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100658 CHECK_STATUS(ddr3_tip_rank_control(dev_num, if_id));
659
Chris Packham4bf81db2018-12-03 14:26:49 +1300660 if (init_cntr_prm->do_mrs_phy)
661 ddr3_tip_pad_inv();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100662
663 /* Pad calibration control - disable */
664 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, 0x0, 0x1));
Stefan Roese5ffceb82015-03-26 15:36:56 +0100667 CHECK_STATUS(ddr3_tip_if_write
668 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +1200669 MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100670 calibration_update_control << 3, 0x3 << 3));
671 }
672
Stefan Roese5ffceb82015-03-26 15:36:56 +0100673
674 if (delay_enable != 0) {
Chris Packham4bf81db2018-12-03 14:26:49 +1300675 adll_tap = MEGA / (mv_ddr_freq_get(freq) * 64);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100676 ddr3_tip_cmd_addr_init_delay(dev_num, adll_tap);
677 }
678
679 return MV_OK;
680}
681
682/*
Chris Packham1a07d212018-05-10 13:28:29 +1200683 * Rank Control Flow
Stefan Roese5ffceb82015-03-26 15:36:56 +0100684 */
Chris Packham1a07d212018-05-10 13:28:29 +1200685static int ddr3_tip_rev2_rank_control(u32 dev_num, u32 if_id)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100686{
Chris Packham1a07d212018-05-10 13:28:29 +1200687 u32 data_value = 0, bus_cnt = 0;
688 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
689 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100690
Chris Packham1a07d212018-05-10 13:28:29 +1200691 for (bus_cnt = 0; bus_cnt < octets_per_if_num; bus_cnt++) {
692 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
693 data_value |= tm->interface_params[if_id].as_bus_params[bus_cnt].
694 cs_bitmask;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100695
Chris Packham1a07d212018-05-10 13:28:29 +1200696 if (tm->interface_params[if_id].as_bus_params[bus_cnt].
697 mirror_enable_bitmask == 1) {
698 /*
699 * Check mirror_enable_bitmask
700 * If it is enabled, CS + 4 bit in a word to be '1'
701 */
702 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
703 cs_bitmask & 0x1) != 0) {
704 data_value |= tm->interface_params[if_id].
705 as_bus_params[bus_cnt].
706 mirror_enable_bitmask << 4;
707 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100708
Chris Packham1a07d212018-05-10 13:28:29 +1200709 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
710 cs_bitmask & 0x2) != 0) {
711 data_value |= tm->interface_params[if_id].
712 as_bus_params[bus_cnt].
713 mirror_enable_bitmask << 5;
714 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100715
Chris Packham1a07d212018-05-10 13:28:29 +1200716 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
717 cs_bitmask & 0x4) != 0) {
718 data_value |= tm->interface_params[if_id].
719 as_bus_params[bus_cnt].
720 mirror_enable_bitmask << 6;
721 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100722
Chris Packham1a07d212018-05-10 13:28:29 +1200723 if ((tm->interface_params[if_id].as_bus_params[bus_cnt].
724 cs_bitmask & 0x8) != 0) {
725 data_value |= tm->interface_params[if_id].
726 as_bus_params[bus_cnt].
727 mirror_enable_bitmask << 7;
728 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100729 }
730 }
731
Chris Packham1a07d212018-05-10 13:28:29 +1200732 CHECK_STATUS(ddr3_tip_if_write
733 (dev_num, ACCESS_TYPE_UNICAST, if_id, DDR3_RANK_CTRL_REG,
734 data_value, 0xff));
735
Stefan Roese5ffceb82015-03-26 15:36:56 +0100736 return MV_OK;
737}
738
Chris Packham1a07d212018-05-10 13:28:29 +1200739static int ddr3_tip_rev3_rank_control(u32 dev_num, u32 if_id)
Stefan Roese5ffceb82015-03-26 15:36:56 +0100740{
741 u32 data_value = 0, bus_cnt;
Chris Packham1a07d212018-05-10 13:28:29 +1200742 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
743 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +0100744
Chris Packham1a07d212018-05-10 13:28:29 +1200745 for (bus_cnt = 1; bus_cnt < octets_per_if_num; bus_cnt++) {
746 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100747 if ((tm->interface_params[if_id].
748 as_bus_params[0].cs_bitmask !=
749 tm->interface_params[if_id].
750 as_bus_params[bus_cnt].cs_bitmask) ||
751 (tm->interface_params[if_id].
752 as_bus_params[0].mirror_enable_bitmask !=
753 tm->interface_params[if_id].
754 as_bus_params[bus_cnt].mirror_enable_bitmask))
755 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
756 ("WARNING:Wrong configuration for pup #%d CS mask and CS mirroring for all pups should be the same\n",
757 bus_cnt));
758 }
759
760 data_value |= tm->interface_params[if_id].
761 as_bus_params[0].cs_bitmask;
762 data_value |= tm->interface_params[if_id].
763 as_bus_params[0].mirror_enable_bitmask << 4;
764
765 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +1200766 (dev_num, ACCESS_TYPE_UNICAST, if_id, DDR3_RANK_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +0100767 data_value, 0xff));
768
769 return MV_OK;
770}
771
Chris Packham1a07d212018-05-10 13:28:29 +1200772static int ddr3_tip_rank_control(u32 dev_num, u32 if_id)
773{
774 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_TIP_REV) == MV_TIP_REV_2)
775 return ddr3_tip_rev2_rank_control(dev_num, if_id);
776 else
777 return ddr3_tip_rev3_rank_control(dev_num, if_id);
778}
779
Stefan Roese5ffceb82015-03-26 15:36:56 +0100780/*
Chris Packham1a07d212018-05-10 13:28:29 +1200781 * Algorithm Parameters Validation
782 */
783int ddr3_tip_validate_algo_var(u32 value, u32 fail_value, char *var_name)
784{
785 if (value == fail_value) {
786 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
787 ("Error: %s is not initialized (Algo Components Validation)\n",
788 var_name));
789 return 0;
790 }
791
792 return 1;
793}
794
795int ddr3_tip_validate_algo_ptr(void *ptr, void *fail_value, char *ptr_name)
796{
797 if (ptr == fail_value) {
798 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
799 ("Error: %s is not initialized (Algo Components Validation)\n",
800 ptr_name));
801 return 0;
802 }
803
804 return 1;
805}
806
807int ddr3_tip_validate_algo_components(u8 dev_num)
808{
809 int status = 1;
810
811 /* Check DGL parameters*/
812 status &= ddr3_tip_validate_algo_var(ck_delay, PARAM_UNDEFINED, "ck_delay");
813 status &= ddr3_tip_validate_algo_var(phy_reg3_val, PARAM_UNDEFINED, "phy_reg3_val");
814 status &= ddr3_tip_validate_algo_var(g_rtt_nom, PARAM_UNDEFINED, "g_rtt_nom");
815 status &= ddr3_tip_validate_algo_var(g_dic, PARAM_UNDEFINED, "g_dic");
816 status &= ddr3_tip_validate_algo_var(odt_config, PARAM_UNDEFINED, "odt_config");
817 status &= ddr3_tip_validate_algo_var(g_zpri_data, PARAM_UNDEFINED, "g_zpri_data");
818 status &= ddr3_tip_validate_algo_var(g_znri_data, PARAM_UNDEFINED, "g_znri_data");
819 status &= ddr3_tip_validate_algo_var(g_zpri_ctrl, PARAM_UNDEFINED, "g_zpri_ctrl");
820 status &= ddr3_tip_validate_algo_var(g_znri_ctrl, PARAM_UNDEFINED, "g_znri_ctrl");
821 status &= ddr3_tip_validate_algo_var(g_zpodt_data, PARAM_UNDEFINED, "g_zpodt_data");
822 status &= ddr3_tip_validate_algo_var(g_znodt_data, PARAM_UNDEFINED, "g_znodt_data");
823 status &= ddr3_tip_validate_algo_var(g_zpodt_ctrl, PARAM_UNDEFINED, "g_zpodt_ctrl");
824 status &= ddr3_tip_validate_algo_var(g_znodt_ctrl, PARAM_UNDEFINED, "g_znodt_ctrl");
825
826 /* Check functions pointers */
827 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_dunit_mux_select_func,
828 NULL, "tip_dunit_mux_select_func");
829 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_dunit_write,
830 NULL, "mv_ddr_dunit_write");
831 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_dunit_read,
832 NULL, "mv_ddr_dunit_read");
833 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_phy_write,
834 NULL, "mv_ddr_phy_write");
835 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].mv_ddr_phy_read,
836 NULL, "mv_ddr_phy_read");
837 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_get_freq_config_info_func,
838 NULL, "tip_get_freq_config_info_func");
839 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_set_freq_divider_func,
840 NULL, "tip_set_freq_divider_func");
841 status &= ddr3_tip_validate_algo_ptr(config_func_info[dev_num].tip_get_clock_ratio,
842 NULL, "tip_get_clock_ratio");
843
844 status &= ddr3_tip_validate_algo_ptr(dq_map_table, NULL, "dq_map_table");
845 status &= ddr3_tip_validate_algo_var(dfs_low_freq, 0, "dfs_low_freq");
846
847 return (status == 1) ? MV_OK : MV_NOT_INITIALIZED;
848}
849
850
851int ddr3_pre_algo_config(void)
852{
853 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
854
855 /* Set Bus3 ECC training mode */
856 if (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask)) {
857 /* Set Bus3 ECC MUX */
858 CHECK_STATUS(ddr3_tip_if_write
859 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
860 DRAM_PINS_MUX_REG, 0x100, 0x100));
861 }
862
863 /* Set regular ECC training mode (bus4 and bus 3) */
864 if ((DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask)) ||
865 (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask)) ||
866 (DDR3_IS_ECC_PUP8_MODE(tm->bus_act_mask))) {
867 /* Enable ECC Write MUX */
868 CHECK_STATUS(ddr3_tip_if_write
869 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
870 TRAINING_SW_2_REG, 0x100, 0x100));
871 /* General ECC enable */
872 CHECK_STATUS(ddr3_tip_if_write
873 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
874 SDRAM_CFG_REG, 0x40000, 0x40000));
875 /* Disable Read Data ECC MUX */
876 CHECK_STATUS(ddr3_tip_if_write
877 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
878 TRAINING_SW_2_REG, 0x0, 0x2));
879 }
880
881 return MV_OK;
882}
883
884int ddr3_post_algo_config(void)
885{
886 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
887 int status;
888
889 status = ddr3_post_run_alg();
890 if (MV_OK != status) {
891 printf("DDR3 Post Run Alg - FAILED 0x%x\n", status);
892 return status;
893 }
894
895 /* Un_set ECC training mode */
896 if ((DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask)) ||
897 (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask)) ||
898 (DDR3_IS_ECC_PUP8_MODE(tm->bus_act_mask))) {
899 /* Disable ECC Write MUX */
900 CHECK_STATUS(ddr3_tip_if_write
901 (0, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
902 TRAINING_SW_2_REG, 0x0, 0x100));
903 /* General ECC and Bus3 ECC MUX remains enabled */
904 }
905
906 return MV_OK;
907}
908
909/*
Stefan Roese5ffceb82015-03-26 15:36:56 +0100910 * Run Training Flow
911 */
912int hws_ddr3_tip_run_alg(u32 dev_num, enum hws_algo_type algo_type)
913{
Chris Packham1a07d212018-05-10 13:28:29 +1200914 int status = MV_OK;
915
916 status = ddr3_pre_algo_config();
917 if (MV_OK != status) {
918 printf("DDR3 Pre Algo Config - FAILED 0x%x\n", status);
919 return status;
920 }
Stefan Roese5ffceb82015-03-26 15:36:56 +0100921
922#ifdef ODT_TEST_SUPPORT
923 if (finger_test == 1)
924 return odt_test(dev_num, algo_type);
925#endif
926
927 if (algo_type == ALGO_TYPE_DYNAMIC) {
Chris Packham1a07d212018-05-10 13:28:29 +1200928 status = ddr3_tip_ddr3_auto_tune(dev_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100929 }
930
Chris Packham1a07d212018-05-10 13:28:29 +1200931 if (status != MV_OK) {
Stefan Roese5ffceb82015-03-26 15:36:56 +0100932 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
Chris Packham1a07d212018-05-10 13:28:29 +1200933 ("******** DRAM initialization Failed (res 0x%x) ********\n",
934 status));
935 return status;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100936 }
937
Chris Packham1a07d212018-05-10 13:28:29 +1200938 status = ddr3_post_algo_config();
939 if (MV_OK != status) {
940 printf("DDR3 Post Algo Config - FAILED 0x%x\n", status);
941 return status;
942 }
943
944 return status;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100945}
946
947#ifdef ODT_TEST_SUPPORT
948/*
949 * ODT Test
950 */
951static int odt_test(u32 dev_num, enum hws_algo_type algo_type)
952{
953 int ret = MV_OK, ret_tune = MV_OK;
954 int pfinger_val = 0, nfinger_val;
955
956 for (pfinger_val = p_finger_start; pfinger_val <= p_finger_end;
957 pfinger_val += p_finger_step) {
958 for (nfinger_val = n_finger_start; nfinger_val <= n_finger_end;
959 nfinger_val += n_finger_step) {
960 if (finger_test != 0) {
961 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
962 ("pfinger_val %d nfinger_val %d\n",
963 pfinger_val, nfinger_val));
Chris Packham1a07d212018-05-10 13:28:29 +1200964 /*
965 * TODO: need to check the correctness
966 * of the following two lines.
967 */
968 g_zpodt_data = pfinger_val;
969 g_znodt_data = nfinger_val;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100970 }
971
972 if (algo_type == ALGO_TYPE_DYNAMIC) {
973 ret = ddr3_tip_ddr3_auto_tune(dev_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100974 }
975 }
976 }
977
978 if (ret_tune != MV_OK) {
979 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
980 ("Run_alg: tuning failed %d\n", ret_tune));
981 ret = (ret == MV_OK) ? ret_tune : ret;
982 }
983
984 return ret;
985}
986#endif
987
988/*
989 * Select Controller
990 */
991int hws_ddr3_tip_select_ddr_controller(u32 dev_num, int enable)
992{
Chris Packham1a07d212018-05-10 13:28:29 +1200993 return config_func_info[dev_num].
994 tip_dunit_mux_select_func((u8)dev_num, enable);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100995}
996
997/*
998 * Dunit Register Write
999 */
1000int ddr3_tip_if_write(u32 dev_num, enum hws_access_type interface_access,
1001 u32 if_id, u32 reg_addr, u32 data_value, u32 mask)
1002{
Chris Packham1a07d212018-05-10 13:28:29 +12001003 config_func_info[dev_num].mv_ddr_dunit_write(reg_addr, mask, data_value);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001004
Chris Packham1a07d212018-05-10 13:28:29 +12001005 return MV_OK;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001006}
1007
1008/*
1009 * Dunit Register Read
1010 */
1011int ddr3_tip_if_read(u32 dev_num, enum hws_access_type interface_access,
1012 u32 if_id, u32 reg_addr, u32 *data, u32 mask)
1013{
Chris Packham1a07d212018-05-10 13:28:29 +12001014 config_func_info[dev_num].mv_ddr_dunit_read(reg_addr, mask, data);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001015
Chris Packham1a07d212018-05-10 13:28:29 +12001016 return MV_OK;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001017}
1018
1019/*
1020 * Dunit Register Polling
1021 */
1022int ddr3_tip_if_polling(u32 dev_num, enum hws_access_type access_type,
1023 u32 if_id, u32 exp_value, u32 mask, u32 offset,
1024 u32 poll_tries)
1025{
1026 u32 poll_cnt = 0, interface_num = 0, start_if, end_if;
1027 u32 read_data[MAX_INTERFACE_NUM];
1028 int ret;
1029 int is_fail = 0, is_if_fail;
Chris Packham1a07d212018-05-10 13:28:29 +12001030 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001031
1032 if (access_type == ACCESS_TYPE_MULTICAST) {
1033 start_if = 0;
1034 end_if = MAX_INTERFACE_NUM - 1;
1035 } else {
1036 start_if = if_id;
1037 end_if = if_id;
1038 }
1039
1040 for (interface_num = start_if; interface_num <= end_if; interface_num++) {
1041 /* polling bit 3 for n times */
Chris Packham1a07d212018-05-10 13:28:29 +12001042 VALIDATE_IF_ACTIVE(tm->if_act_mask, interface_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001043
1044 is_if_fail = 0;
1045 for (poll_cnt = 0; poll_cnt < poll_tries; poll_cnt++) {
1046 ret =
1047 ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST,
1048 interface_num, offset, read_data,
1049 mask);
1050 if (ret != MV_OK)
1051 return ret;
1052
1053 if (read_data[interface_num] == exp_value)
1054 break;
1055 }
1056
1057 if (poll_cnt >= poll_tries) {
1058 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1059 ("max poll IF #%d\n", interface_num));
1060 is_fail = 1;
1061 is_if_fail = 1;
1062 }
1063
1064 training_result[training_stage][interface_num] =
1065 (is_if_fail == 1) ? TEST_FAILED : TEST_SUCCESS;
1066 }
1067
1068 return (is_fail == 0) ? MV_OK : MV_FAIL;
1069}
1070
1071/*
1072 * Bus read access
1073 */
1074int ddr3_tip_bus_read(u32 dev_num, u32 if_id,
1075 enum hws_access_type phy_access, u32 phy_id,
1076 enum hws_ddr_phy phy_type, u32 reg_addr, u32 *data)
1077{
Chris Packham1a07d212018-05-10 13:28:29 +12001078 return config_func_info[dev_num].
1079 mv_ddr_phy_read(phy_access, phy_id, phy_type, reg_addr, data);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001080}
1081
1082/*
1083 * Bus write access
1084 */
1085int ddr3_tip_bus_write(u32 dev_num, enum hws_access_type interface_access,
1086 u32 if_id, enum hws_access_type phy_access,
1087 u32 phy_id, enum hws_ddr_phy phy_type, u32 reg_addr,
1088 u32 data_value)
1089{
Chris Packham1a07d212018-05-10 13:28:29 +12001090 return config_func_info[dev_num].
1091 mv_ddr_phy_write(phy_access, phy_id, phy_type, reg_addr, data_value, OPERATION_WRITE);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001092}
1093
Stefan Roese5ffceb82015-03-26 15:36:56 +01001094
1095/*
Stefan Roese5ffceb82015-03-26 15:36:56 +01001096 * Phy read-modify-write
1097 */
1098int ddr3_tip_bus_read_modify_write(u32 dev_num, enum hws_access_type access_type,
1099 u32 interface_id, u32 phy_id,
1100 enum hws_ddr_phy phy_type, u32 reg_addr,
1101 u32 data_value, u32 reg_mask)
1102{
1103 u32 data_val = 0, if_id, start_if, end_if;
Chris Packham1a07d212018-05-10 13:28:29 +12001104 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001105
1106 if (access_type == ACCESS_TYPE_MULTICAST) {
1107 start_if = 0;
1108 end_if = MAX_INTERFACE_NUM - 1;
1109 } else {
1110 start_if = interface_id;
1111 end_if = interface_id;
1112 }
1113
1114 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001115 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001116 CHECK_STATUS(ddr3_tip_bus_read
1117 (dev_num, if_id, ACCESS_TYPE_UNICAST, phy_id,
1118 phy_type, reg_addr, &data_val));
1119 data_value = (data_val & (~reg_mask)) | (data_value & reg_mask);
1120 CHECK_STATUS(ddr3_tip_bus_write
1121 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1122 ACCESS_TYPE_UNICAST, phy_id, phy_type, reg_addr,
1123 data_value));
1124 }
1125
1126 return MV_OK;
1127}
1128
1129/*
1130 * ADLL Calibration
1131 */
1132int adll_calibration(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +13001133 u32 if_id, enum mv_ddr_freq frequency)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001134{
1135 struct hws_tip_freq_config_info freq_config_info;
1136 u32 bus_cnt = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001137 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1138 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001139
1140 /* Reset Diver_b assert -> de-assert */
1141 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001142 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001143 0, 0x10000000));
1144 mdelay(10);
1145 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001146 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001147 0x10000000, 0x10000000));
1148
Chris Packham1a07d212018-05-10 13:28:29 +12001149 CHECK_STATUS(config_func_info[dev_num].
1150 tip_get_freq_config_info_func((u8)dev_num, frequency,
1151 &freq_config_info));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001152
Chris Packham1a07d212018-05-10 13:28:29 +12001153 for (bus_cnt = 0; bus_cnt < octets_per_if_num; bus_cnt++) {
1154 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001155 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1156 (dev_num, access_type, if_id, bus_cnt,
Chris Packham1a07d212018-05-10 13:28:29 +12001157 DDR_PHY_DATA, ADLL_CFG0_PHY_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001158 freq_config_info.bw_per_freq << 8, 0x700));
1159 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1160 (dev_num, access_type, if_id, bus_cnt,
Chris Packham1a07d212018-05-10 13:28:29 +12001161 DDR_PHY_DATA, ADLL_CFG2_PHY_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001162 freq_config_info.rate_per_freq, 0x7));
1163 }
1164
Chris Packham1a07d212018-05-10 13:28:29 +12001165 for (bus_cnt = 0; bus_cnt < DDR_IF_CTRL_SUBPHYS_NUM; bus_cnt++) {
1166 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1167 (dev_num, ACCESS_TYPE_UNICAST, if_id, bus_cnt,
1168 DDR_PHY_CONTROL, ADLL_CFG0_PHY_REG,
1169 freq_config_info.bw_per_freq << 8, 0x700));
1170 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1171 (dev_num, ACCESS_TYPE_UNICAST, if_id, bus_cnt,
1172 DDR_PHY_CONTROL, ADLL_CFG2_PHY_REG,
1173 freq_config_info.rate_per_freq, 0x7));
1174 }
1175
Stefan Roese5ffceb82015-03-26 15:36:56 +01001176 /* DUnit to Phy drive post edge, ADLL reset assert de-assert */
1177 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001178 (dev_num, access_type, if_id, DRAM_PHY_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001179 0, (0x80000000 | 0x40000000)));
Chris Packham4bf81db2018-12-03 14:26:49 +13001180 mdelay(100 / (mv_ddr_freq_get(frequency)) / mv_ddr_freq_get(MV_DDR_FREQ_LOW_FREQ));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001181 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001182 (dev_num, access_type, if_id, DRAM_PHY_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001183 (0x80000000 | 0x40000000), (0x80000000 | 0x40000000)));
1184
1185 /* polling for ADLL Done */
1186 if (ddr3_tip_if_polling(dev_num, access_type, if_id,
1187 0x3ff03ff, 0x3ff03ff, PHY_LOCK_STATUS_REG,
1188 MAX_POLLING_ITERATIONS) != MV_OK) {
1189 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1190 ("Freq_set: DDR3 poll failed(1)"));
1191 }
1192
1193 /* pup data_pup reset assert-> deassert */
1194 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001195 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001196 0, 0x60000000));
1197 mdelay(10);
1198 CHECK_STATUS(ddr3_tip_if_write
Chris Packham1a07d212018-05-10 13:28:29 +12001199 (dev_num, access_type, if_id, SDRAM_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001200 0x60000000, 0x60000000));
1201
1202 return MV_OK;
1203}
1204
1205int ddr3_tip_freq_set(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +13001206 u32 if_id, enum mv_ddr_freq frequency)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001207{
1208 u32 cl_value = 0, cwl_value = 0, mem_mask = 0, val = 0,
Chris Packham1a07d212018-05-10 13:28:29 +12001209 bus_cnt = 0, t_wr = 0, t_ckclk = 0,
1210 cnt_id;
1211 u32 end_if, start_if;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001212 u32 bus_index = 0;
1213 int is_dll_off = 0;
Chris Packham4bf81db2018-12-03 14:26:49 +13001214 enum mv_ddr_speed_bin speed_bin_index = 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001215 struct hws_tip_freq_config_info freq_config_info;
1216 enum hws_result *flow_result = training_result[training_stage];
1217 u32 adll_tap = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001218 u32 cs_num;
1219 u32 t2t;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001220 u32 cs_mask[MAX_INTERFACE_NUM];
Chris Packham1a07d212018-05-10 13:28:29 +12001221 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1222 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
1223 unsigned int tclk;
Chris Packham3a09e132018-05-10 13:28:30 +12001224 enum mv_ddr_timing timing = tm->interface_params[if_id].timing;
Chris Packham4bf81db2018-12-03 14:26:49 +13001225 u32 freq = mv_ddr_freq_get(frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001226
1227 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
1228 ("dev %d access %d IF %d freq %d\n", dev_num,
1229 access_type, if_id, frequency));
1230
Chris Packham4bf81db2018-12-03 14:26:49 +13001231 if (frequency == MV_DDR_FREQ_LOW_FREQ)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001232 is_dll_off = 1;
1233 if (access_type == ACCESS_TYPE_MULTICAST) {
1234 start_if = 0;
1235 end_if = MAX_INTERFACE_NUM - 1;
1236 } else {
1237 start_if = if_id;
1238 end_if = if_id;
1239 }
1240
1241 /* calculate interface cs mask - Oferb 4/11 */
1242 /* speed bin can be different for each interface */
1243 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
1244 /* cs enable is active low */
Chris Packham1a07d212018-05-10 13:28:29 +12001245 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001246 cs_mask[if_id] = CS_BIT_MASK;
1247 training_result[training_stage][if_id] = TEST_SUCCESS;
1248 ddr3_tip_calc_cs_mask(dev_num, if_id, effective_cs,
1249 &cs_mask[if_id]);
1250 }
1251
1252 /* speed bin can be different for each interface */
1253 /*
1254 * moti b - need to remove the loop for multicas access functions
1255 * and loop the unicast access functions
1256 */
1257 for (if_id = start_if; if_id <= end_if; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001258 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001259
1260 flow_result[if_id] = TEST_SUCCESS;
1261 speed_bin_index =
1262 tm->interface_params[if_id].speed_bin_index;
1263 if (tm->interface_params[if_id].memory_freq ==
1264 frequency) {
1265 cl_value =
1266 tm->interface_params[if_id].cas_l;
1267 cwl_value =
1268 tm->interface_params[if_id].cas_wl;
Chris Packham1a07d212018-05-10 13:28:29 +12001269 } else if (tm->cfg_src == MV_DDR_CFG_SPD) {
Chris Packham4bf81db2018-12-03 14:26:49 +13001270 tclk = 1000000 / freq;
Chris Packham1a07d212018-05-10 13:28:29 +12001271 cl_value = mv_ddr_cl_calc(tm->timing_data[MV_DDR_TAA_MIN], tclk);
1272 if (cl_value == 0) {
1273 printf("mv_ddr: unsupported cas latency value found\n");
1274 return MV_FAIL;
1275 }
1276 cwl_value = mv_ddr_cwl_calc(tclk);
1277 if (cwl_value == 0) {
1278 printf("mv_ddr: unsupported cas write latency value found\n");
1279 return MV_FAIL;
1280 }
Stefan Roese5ffceb82015-03-26 15:36:56 +01001281 } else {
Chris Packham4bf81db2018-12-03 14:26:49 +13001282 cl_value = mv_ddr_cl_val_get(speed_bin_index, frequency);
1283 cwl_value = mv_ddr_cwl_val_get(speed_bin_index, frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001284 }
1285
1286 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
1287 ("Freq_set dev 0x%x access 0x%x if 0x%x freq 0x%x speed %d:\n\t",
1288 dev_num, access_type, if_id,
1289 frequency, speed_bin_index));
1290
Chris Packham4bf81db2018-12-03 14:26:49 +13001291 for (cnt_id = 0; cnt_id < MV_DDR_FREQ_LAST; cnt_id++) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01001292 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE,
Chris Packham4bf81db2018-12-03 14:26:49 +13001293 ("%d ", mv_ddr_cl_val_get(speed_bin_index, cnt_id)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001294 }
1295
1296 DEBUG_TRAINING_IP(DEBUG_LEVEL_TRACE, ("\n"));
1297 mem_mask = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001298 for (bus_index = 0; bus_index < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001299 bus_index++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001300 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_index);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001301 mem_mask |=
1302 tm->interface_params[if_id].
1303 as_bus_params[bus_index].mirror_enable_bitmask;
1304 }
1305
1306 if (mem_mask != 0) {
Chris Packham1a07d212018-05-10 13:28:29 +12001307 /* motib redundent in KW28 */
Stefan Roese5ffceb82015-03-26 15:36:56 +01001308 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1309 if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001310 DUAL_DUNIT_CFG_REG, 0, 0x8));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001311 }
1312
1313 /* dll state after exiting SR */
1314 if (is_dll_off == 1) {
1315 CHECK_STATUS(ddr3_tip_if_write
1316 (dev_num, access_type, if_id,
1317 DFS_REG, 0x1, 0x1));
1318 } else {
1319 CHECK_STATUS(ddr3_tip_if_write
1320 (dev_num, access_type, if_id,
1321 DFS_REG, 0, 0x1));
1322 }
1323
1324 CHECK_STATUS(ddr3_tip_if_write
1325 (dev_num, access_type, if_id,
1326 DUNIT_MMASK_REG, 0, 0x1));
1327 /* DFS - block transactions */
1328 CHECK_STATUS(ddr3_tip_if_write
1329 (dev_num, access_type, if_id,
1330 DFS_REG, 0x2, 0x2));
1331
1332 /* disable ODT in case of dll off */
1333 if (is_dll_off == 1) {
1334 CHECK_STATUS(ddr3_tip_if_write
1335 (dev_num, access_type, if_id,
1336 0x1874, 0, 0x244));
1337 CHECK_STATUS(ddr3_tip_if_write
1338 (dev_num, access_type, if_id,
1339 0x1884, 0, 0x244));
1340 CHECK_STATUS(ddr3_tip_if_write
1341 (dev_num, access_type, if_id,
1342 0x1894, 0, 0x244));
1343 CHECK_STATUS(ddr3_tip_if_write
1344 (dev_num, access_type, if_id,
1345 0x18a4, 0, 0x244));
1346 }
1347
1348 /* DFS - Enter Self-Refresh */
1349 CHECK_STATUS(ddr3_tip_if_write
1350 (dev_num, access_type, if_id, DFS_REG, 0x4,
1351 0x4));
1352 /* polling on self refresh entry */
1353 if (ddr3_tip_if_polling(dev_num, ACCESS_TYPE_UNICAST,
1354 if_id, 0x8, 0x8, DFS_REG,
1355 MAX_POLLING_ITERATIONS) != MV_OK) {
1356 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1357 ("Freq_set: DDR3 poll failed on SR entry\n"));
1358 }
1359
Chris Packham1a07d212018-05-10 13:28:29 +12001360 /* Calculate 2T mode */
1361 if (mode_2t != 0xff) {
1362 t2t = mode_2t;
Chris Packham3a09e132018-05-10 13:28:30 +12001363 } else if (timing != MV_DDR_TIM_DEFAULT) {
1364 t2t = (timing == MV_DDR_TIM_2T) ? 1 : 0;
Chris Packham1a07d212018-05-10 13:28:29 +12001365 } else {
1366 /* Calculate number of CS per interface */
Chris Packham4bf81db2018-12-03 14:26:49 +13001367 cs_num = mv_ddr_cs_num_get();
Chris Packham1a07d212018-05-10 13:28:29 +12001368 t2t = (cs_num == 1) ? 0 : 1;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001369 }
1370
Stefan Roese5ffceb82015-03-26 15:36:56 +01001371
Chris Packham1a07d212018-05-10 13:28:29 +12001372 if (ddr3_tip_dev_attr_get(dev_num, MV_ATTR_INTERLEAVE_WA) == 1) {
1373 /* Use 1T mode if 1:1 ratio configured */
1374 if (config_func_info[dev_num].tip_get_clock_ratio(frequency) == 1) {
1375 /* Low freq*/
1376 CHECK_STATUS(ddr3_tip_if_write
1377 (dev_num, access_type, if_id,
1378 SDRAM_OPEN_PAGES_CTRL_REG, 0x0, 0x3C0));
1379 t2t = 0;
1380 } else {
1381 /* Middle or target freq */
1382 CHECK_STATUS(ddr3_tip_if_write
1383 (dev_num, access_type, if_id,
1384 SDRAM_OPEN_PAGES_CTRL_REG, 0x3C0, 0x3C0));
1385 }
1386 }
1387 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
1388 DUNIT_CTRL_LOW_REG, t2t << 3, 0x3 << 3));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001389
Chris Packham1a07d212018-05-10 13:28:29 +12001390 /* PLL configuration */
1391 config_func_info[dev_num].tip_set_freq_divider_func(dev_num, if_id,
1392 frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001393
1394 /* DFS - CL/CWL/WR parameters after exiting SR */
1395 CHECK_STATUS(ddr3_tip_if_write
1396 (dev_num, access_type, if_id, DFS_REG,
1397 (cl_mask_table[cl_value] << 8), 0xf00));
1398 CHECK_STATUS(ddr3_tip_if_write
1399 (dev_num, access_type, if_id, DFS_REG,
1400 (cwl_mask_table[cwl_value] << 12), 0x7000));
Chris Packham5450f0c2018-01-18 17:16:10 +13001401
Chris Packham4bf81db2018-12-03 14:26:49 +13001402 t_ckclk = (MEGA / freq);
1403 t_wr = time_to_nclk(mv_ddr_speed_bin_timing_get
Chris Packham1a07d212018-05-10 13:28:29 +12001404 (speed_bin_index,
1405 SPEED_BIN_TWR), t_ckclk);
Chris Packham5450f0c2018-01-18 17:16:10 +13001406
Stefan Roese5ffceb82015-03-26 15:36:56 +01001407 CHECK_STATUS(ddr3_tip_if_write
1408 (dev_num, access_type, if_id, DFS_REG,
Chris Packham1a07d212018-05-10 13:28:29 +12001409 (twr_mask_table[t_wr] << 16), 0x70000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001410
1411 /* Restore original RTT values if returning from DLL OFF mode */
1412 if (is_dll_off == 1) {
1413 CHECK_STATUS(ddr3_tip_if_write
1414 (dev_num, access_type, if_id, 0x1874,
1415 g_dic | g_rtt_nom, 0x266));
1416 CHECK_STATUS(ddr3_tip_if_write
1417 (dev_num, access_type, if_id, 0x1884,
1418 g_dic | g_rtt_nom, 0x266));
1419 CHECK_STATUS(ddr3_tip_if_write
1420 (dev_num, access_type, if_id, 0x1894,
1421 g_dic | g_rtt_nom, 0x266));
1422 CHECK_STATUS(ddr3_tip_if_write
1423 (dev_num, access_type, if_id, 0x18a4,
1424 g_dic | g_rtt_nom, 0x266));
1425 }
1426
Chris Packham1a07d212018-05-10 13:28:29 +12001427 /* Reset divider_b assert -> de-assert */
Stefan Roese5ffceb82015-03-26 15:36:56 +01001428 CHECK_STATUS(ddr3_tip_if_write
1429 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001430 SDRAM_CFG_REG, 0, 0x10000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001431 mdelay(10);
1432 CHECK_STATUS(ddr3_tip_if_write
1433 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001434 SDRAM_CFG_REG, 0x10000000, 0x10000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001435
Chris Packham1a07d212018-05-10 13:28:29 +12001436 /* ADLL configuration function of process and frequency */
1437 CHECK_STATUS(config_func_info[dev_num].
1438 tip_get_freq_config_info_func(dev_num, frequency,
1439 &freq_config_info));
1440
Stefan Roese5ffceb82015-03-26 15:36:56 +01001441 /* TBD check milo5 using device ID ? */
Chris Packham1a07d212018-05-10 13:28:29 +12001442 for (bus_cnt = 0; bus_cnt < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001443 bus_cnt++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001444 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_cnt);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001445 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1446 (dev_num, ACCESS_TYPE_UNICAST,
1447 if_id, bus_cnt, DDR_PHY_DATA,
1448 0x92,
1449 freq_config_info.
1450 bw_per_freq << 8
1451 /*freq_mask[dev_num][frequency] << 8 */
1452 , 0x700));
1453 CHECK_STATUS(ddr3_tip_bus_read_modify_write
1454 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1455 bus_cnt, DDR_PHY_DATA, 0x94,
1456 freq_config_info.rate_per_freq, 0x7));
1457 }
1458
Chris Packham1a07d212018-05-10 13:28:29 +12001459 /* Dunit to PHY drive post edge, ADLL reset assert -> de-assert */
Stefan Roese5ffceb82015-03-26 15:36:56 +01001460 CHECK_STATUS(ddr3_tip_if_write
1461 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001462 DRAM_PHY_CFG_REG, 0,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001463 (0x80000000 | 0x40000000)));
Chris Packham4bf81db2018-12-03 14:26:49 +13001464 mdelay(100 / (freq / mv_ddr_freq_get(MV_DDR_FREQ_LOW_FREQ)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001465 CHECK_STATUS(ddr3_tip_if_write
1466 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001467 DRAM_PHY_CFG_REG, (0x80000000 | 0x40000000),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001468 (0x80000000 | 0x40000000)));
1469
1470 /* polling for ADLL Done */
1471 if (ddr3_tip_if_polling
1472 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0x3ff03ff,
1473 0x3ff03ff, PHY_LOCK_STATUS_REG,
1474 MAX_POLLING_ITERATIONS) != MV_OK) {
1475 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1476 ("Freq_set: DDR3 poll failed(1)\n"));
1477 }
1478
1479 /* pup data_pup reset assert-> deassert */
1480 CHECK_STATUS(ddr3_tip_if_write
1481 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001482 SDRAM_CFG_REG, 0, 0x60000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001483 mdelay(10);
1484 CHECK_STATUS(ddr3_tip_if_write
1485 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001486 SDRAM_CFG_REG, 0x60000000, 0x60000000));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001487
1488 /* Set proper timing params before existing Self-Refresh */
1489 ddr3_tip_set_timing(dev_num, access_type, if_id, frequency);
1490 if (delay_enable != 0) {
Chris Packham4bf81db2018-12-03 14:26:49 +13001491 adll_tap = (is_dll_off == 1) ? 1000 : (MEGA / (freq * 64));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001492 ddr3_tip_cmd_addr_init_delay(dev_num, adll_tap);
1493 }
1494
1495 /* Exit SR */
1496 CHECK_STATUS(ddr3_tip_if_write
1497 (dev_num, access_type, if_id, DFS_REG, 0,
1498 0x4));
1499 if (ddr3_tip_if_polling
1500 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0, 0x8, DFS_REG,
1501 MAX_POLLING_ITERATIONS) != MV_OK) {
1502 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1503 ("Freq_set: DDR3 poll failed(2)"));
1504 }
1505
1506 /* Refresh Command */
1507 CHECK_STATUS(ddr3_tip_if_write
1508 (dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001509 SDRAM_OP_REG, 0x2, 0xf1f));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001510 if (ddr3_tip_if_polling
1511 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0, 0x1f,
Chris Packham1a07d212018-05-10 13:28:29 +12001512 SDRAM_OP_REG, MAX_POLLING_ITERATIONS) != MV_OK) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01001513 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1514 ("Freq_set: DDR3 poll failed(3)"));
1515 }
1516
1517 /* Release DFS Block */
1518 CHECK_STATUS(ddr3_tip_if_write
1519 (dev_num, access_type, if_id, DFS_REG, 0,
1520 0x2));
1521 /* Controller to MBUS Retry - normal */
1522 CHECK_STATUS(ddr3_tip_if_write
1523 (dev_num, access_type, if_id, DUNIT_MMASK_REG,
1524 0x1, 0x1));
1525
1526 /* MRO: Burst Length 8, CL , Auto_precharge 0x16cc */
1527 val =
1528 ((cl_mask_table[cl_value] & 0x1) << 2) |
1529 ((cl_mask_table[cl_value] & 0xe) << 3);
1530 CHECK_STATUS(ddr3_tip_if_write
1531 (dev_num, access_type, if_id, MR0_REG,
1532 val, (0x7 << 4) | (1 << 2)));
1533 /* MR2: CWL = 10 , Auto Self-Refresh - disable */
Chris Packham1a07d212018-05-10 13:28:29 +12001534 val = (cwl_mask_table[cwl_value] << 3) | g_rtt_wr;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001535 /*
1536 * nklein 24.10.13 - should not be here - leave value as set in
1537 * the init configuration val |= (1 << 9);
1538 * val |= ((tm->interface_params[if_id].
Chris Packham1a07d212018-05-10 13:28:29 +12001539 * interface_temp == MV_DDR_TEMP_HIGH) ? (1 << 7) : 0);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001540 */
1541 /* nklein 24.10.13 - see above comment */
1542 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1543 if_id, MR2_REG,
Chris Packham1a07d212018-05-10 13:28:29 +12001544 val, (0x7 << 3) | (0x3 << 9)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001545
1546 /* ODT TIMING */
1547 val = ((cl_value - cwl_value + 1) << 4) |
1548 ((cl_value - cwl_value + 6) << 8) |
1549 ((cl_value - 1) << 12) | ((cl_value + 6) << 16);
1550 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
Chris Packham1a07d212018-05-10 13:28:29 +12001551 if_id, DDR_ODT_TIMING_LOW_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001552 val, 0xffff0));
Chris Packhamae806142018-01-18 17:16:07 +13001553 val = 0x91 | ((cwl_value - 1) << 8) | ((cwl_value + 5) << 12);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001554 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
Chris Packham1a07d212018-05-10 13:28:29 +12001555 if_id, DDR_ODT_TIMING_HIGH_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001556 val, 0xffff));
1557
Chris Packham1a07d212018-05-10 13:28:29 +12001558 /* in case of ddr4 need to set the receiver to odt always 'on' (odt_config = '0')
1559 * in case of ddr3 configure the odt through the timing
1560 */
1561 if (odt_config != 0) {
1562 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id, DUNIT_ODT_CTRL_REG, 0xf, 0xf));
1563 }
1564 else {
1565 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id, DUNIT_ODT_CTRL_REG,
1566 0x30f, 0x30f));
1567 }
Stefan Roese5ffceb82015-03-26 15:36:56 +01001568
1569 /* re-write CL */
1570 val = ((cl_mask_table[cl_value] & 0x1) << 2) |
1571 ((cl_mask_table[cl_value] & 0xe) << 3);
Chris Packham1a07d212018-05-10 13:28:29 +12001572
Marek Behúnb9eaf112021-02-19 17:11:23 +01001573 cs_mask[0] = 0xc;
1574
Chris Packham1a07d212018-05-10 13:28:29 +12001575 CHECK_STATUS(ddr3_tip_write_mrs_cmd(dev_num, cs_mask, MR_CMD0,
1576 val, (0x7 << 4) | (0x1 << 2)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001577
1578 /* re-write CWL */
Chris Packham1a07d212018-05-10 13:28:29 +12001579 val = (cwl_mask_table[cwl_value] << 3) | g_rtt_wr;
1580 CHECK_STATUS(ddr3_tip_write_mrs_cmd(dev_num, cs_mask, MR_CMD2,
1581 val, (0x7 << 3) | (0x3 << 9)));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001582
1583 if (mem_mask != 0) {
1584 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1585 if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001586 DUAL_DUNIT_CFG_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001587 1 << 3, 0x8));
1588 }
1589 }
1590
1591 return MV_OK;
1592}
1593
1594/*
1595 * Set ODT values
1596 */
1597static int ddr3_tip_write_odt(u32 dev_num, enum hws_access_type access_type,
1598 u32 if_id, u32 cl_value, u32 cwl_value)
1599{
1600 /* ODT TIMING */
1601 u32 val = (cl_value - cwl_value + 6);
1602
1603 val = ((cl_value - cwl_value + 1) << 4) | ((val & 0xf) << 8) |
1604 (((cl_value - 1) & 0xf) << 12) |
1605 (((cl_value + 6) & 0xf) << 16) | (((val & 0x10) >> 4) << 21);
1606 val |= (((cl_value - 1) >> 4) << 22) | (((cl_value + 6) >> 4) << 23);
1607
1608 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001609 DDR_ODT_TIMING_LOW_REG, val, 0xffff0));
Chris Packhamae806142018-01-18 17:16:07 +13001610 val = 0x91 | ((cwl_value - 1) << 8) | ((cwl_value + 5) << 12);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001611 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001612 DDR_ODT_TIMING_HIGH_REG, val, 0xffff));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001613 if (odt_additional == 1) {
1614 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type,
1615 if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001616 SDRAM_ODT_CTRL_HIGH_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001617 0xf, 0xf));
1618 }
1619
1620 /* ODT Active */
1621 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001622 DUNIT_ODT_CTRL_REG, 0xf, 0xf));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001623
1624 return MV_OK;
1625}
1626
1627/*
1628 * Set Timing values for training
1629 */
1630static int ddr3_tip_set_timing(u32 dev_num, enum hws_access_type access_type,
Chris Packham4bf81db2018-12-03 14:26:49 +13001631 u32 if_id, enum mv_ddr_freq frequency)
Stefan Roese5ffceb82015-03-26 15:36:56 +01001632{
1633 u32 t_ckclk = 0, t_ras = 0;
1634 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 +12001635 t_rfc = 0, t_mod = 0, t_r2r = 0x3, t_r2r_high = 0,
1636 t_r2w_w2r = 0x3, t_r2w_w2r_high = 0x1, t_w2w = 0x3;
1637 u32 refresh_interval_cnt, t_hclk, t_refi, t_faw, t_pd, t_xpdll;
1638 u32 val = 0, page_size = 0, mask = 0;
Chris Packham4bf81db2018-12-03 14:26:49 +13001639 enum mv_ddr_speed_bin speed_bin_index;
Chris Packham1a07d212018-05-10 13:28:29 +12001640 enum mv_ddr_die_capacity memory_size = MV_DDR_DIE_CAP_2GBIT;
1641 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Chris Packham4bf81db2018-12-03 14:26:49 +13001642 u32 freq = mv_ddr_freq_get(frequency);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001643
1644 speed_bin_index = tm->interface_params[if_id].speed_bin_index;
1645 memory_size = tm->interface_params[if_id].memory_size;
Chris Packham4bf81db2018-12-03 14:26:49 +13001646 page_size = mv_ddr_page_size_get(tm->interface_params[if_id].bus_width, memory_size);
1647 t_ckclk = (MEGA / freq);
Chris Packham1a07d212018-05-10 13:28:29 +12001648 /* HCLK in[ps] */
Chris Packham4bf81db2018-12-03 14:26:49 +13001649 t_hclk = MEGA / (freq / config_func_info[dev_num].tip_get_clock_ratio(frequency));
Chris Packham1a07d212018-05-10 13:28:29 +12001650
1651 t_refi = (tm->interface_params[if_id].interface_temp == MV_DDR_TEMP_HIGH) ? TREFI_HIGH : TREFI_LOW;
1652 t_refi *= 1000; /* psec */
1653 refresh_interval_cnt = t_refi / t_hclk; /* no units */
1654
1655 if (page_size == 1) {
Chris Packham4bf81db2018-12-03 14:26:49 +13001656 t_faw = mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TFAW1K);
Chris Packham1a07d212018-05-10 13:28:29 +12001657 t_faw = time_to_nclk(t_faw, t_ckclk);
1658 t_faw = GET_MAX_VALUE(20, t_faw);
1659 } else { /* page size =2, we do not support page size 0.5k */
Chris Packham4bf81db2018-12-03 14:26:49 +13001660 t_faw = mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TFAW2K);
Chris Packham1a07d212018-05-10 13:28:29 +12001661 t_faw = time_to_nclk(t_faw, t_ckclk);
1662 t_faw = GET_MAX_VALUE(28, t_faw);
1663 }
1664
Chris Packham4bf81db2018-12-03 14:26:49 +13001665 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 +12001666 t_pd = time_to_nclk(t_pd, t_ckclk);
1667
Chris Packham4bf81db2018-12-03 14:26:49 +13001668 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 +12001669 t_xpdll = time_to_nclk(t_xpdll, t_ckclk);
1670
Chris Packham4bf81db2018-12-03 14:26:49 +13001671 t_rrd = (page_size == 1) ? mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001672 SPEED_BIN_TRRD1K) :
Chris Packham4bf81db2018-12-03 14:26:49 +13001673 mv_ddr_speed_bin_timing_get(speed_bin_index, SPEED_BIN_TRRD2K);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001674 t_rrd = GET_MAX_VALUE(t_ckclk * 4, t_rrd);
Chris Packham4bf81db2018-12-03 14:26:49 +13001675 t_rtp = GET_MAX_VALUE(t_ckclk * 4, mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001676 SPEED_BIN_TRTP));
Chris Packham1a07d212018-05-10 13:28:29 +12001677 t_mod = GET_MAX_VALUE(t_ckclk * 12, 15000);
Chris Packham4bf81db2018-12-03 14:26:49 +13001678 t_wtr = GET_MAX_VALUE(t_ckclk * 4, mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001679 SPEED_BIN_TWTR));
Chris Packham4bf81db2018-12-03 14:26:49 +13001680 t_ras = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001681 SPEED_BIN_TRAS),
1682 t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001683 t_rcd = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001684 SPEED_BIN_TRCD),
1685 t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001686 t_rp = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001687 SPEED_BIN_TRP),
1688 t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001689 t_wr = time_to_nclk(mv_ddr_speed_bin_timing_get(speed_bin_index,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001690 SPEED_BIN_TWR),
1691 t_ckclk);
Chris Packham1a07d212018-05-10 13:28:29 +12001692 t_wtr = time_to_nclk(t_wtr, t_ckclk);
1693 t_rrd = time_to_nclk(t_rrd, t_ckclk);
1694 t_rtp = time_to_nclk(t_rtp, t_ckclk);
Chris Packham4bf81db2018-12-03 14:26:49 +13001695 t_rfc = time_to_nclk(mv_ddr_rfc_get(memory_size) * 1000, t_ckclk);
Chris Packham1a07d212018-05-10 13:28:29 +12001696 t_mod = time_to_nclk(t_mod, t_ckclk);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001697
1698 /* SDRAM Timing Low */
Chris Packham1a07d212018-05-10 13:28:29 +12001699 val = (((t_ras - 1) & SDRAM_TIMING_LOW_TRAS_MASK) << SDRAM_TIMING_LOW_TRAS_OFFS) |
1700 (((t_rcd - 1) & SDRAM_TIMING_LOW_TRCD_MASK) << SDRAM_TIMING_LOW_TRCD_OFFS) |
1701 (((t_rcd - 1) >> SDRAM_TIMING_LOW_TRCD_OFFS & SDRAM_TIMING_HIGH_TRCD_MASK)
1702 << SDRAM_TIMING_HIGH_TRCD_OFFS) |
1703 (((t_rp - 1) & SDRAM_TIMING_LOW_TRP_MASK) << SDRAM_TIMING_LOW_TRP_OFFS) |
1704 (((t_rp - 1) >> SDRAM_TIMING_LOW_TRP_MASK & SDRAM_TIMING_HIGH_TRP_MASK)
1705 << SDRAM_TIMING_HIGH_TRP_OFFS) |
1706 (((t_wr - 1) & SDRAM_TIMING_LOW_TWR_MASK) << SDRAM_TIMING_LOW_TWR_OFFS) |
1707 (((t_wtr - 1) & SDRAM_TIMING_LOW_TWTR_MASK) << SDRAM_TIMING_LOW_TWTR_OFFS) |
1708 ((((t_ras - 1) >> 4) & SDRAM_TIMING_LOW_TRAS_HIGH_MASK) << SDRAM_TIMING_LOW_TRAS_HIGH_OFFS) |
1709 (((t_rrd - 1) & SDRAM_TIMING_LOW_TRRD_MASK) << SDRAM_TIMING_LOW_TRRD_OFFS) |
1710 (((t_rtp - 1) & SDRAM_TIMING_LOW_TRTP_MASK) << SDRAM_TIMING_LOW_TRTP_OFFS);
1711
1712 mask = (SDRAM_TIMING_LOW_TRAS_MASK << SDRAM_TIMING_LOW_TRAS_OFFS) |
1713 (SDRAM_TIMING_LOW_TRCD_MASK << SDRAM_TIMING_LOW_TRCD_OFFS) |
1714 (SDRAM_TIMING_HIGH_TRCD_MASK << SDRAM_TIMING_HIGH_TRCD_OFFS) |
1715 (SDRAM_TIMING_LOW_TRP_MASK << SDRAM_TIMING_LOW_TRP_OFFS) |
1716 (SDRAM_TIMING_HIGH_TRP_MASK << SDRAM_TIMING_HIGH_TRP_OFFS) |
1717 (SDRAM_TIMING_LOW_TWR_MASK << SDRAM_TIMING_LOW_TWR_OFFS) |
1718 (SDRAM_TIMING_LOW_TWTR_MASK << SDRAM_TIMING_LOW_TWTR_OFFS) |
1719 (SDRAM_TIMING_LOW_TRAS_HIGH_MASK << SDRAM_TIMING_LOW_TRAS_HIGH_OFFS) |
1720 (SDRAM_TIMING_LOW_TRRD_MASK << SDRAM_TIMING_LOW_TRRD_OFFS) |
1721 (SDRAM_TIMING_LOW_TRTP_MASK << SDRAM_TIMING_LOW_TRTP_OFFS);
1722
Stefan Roese5ffceb82015-03-26 15:36:56 +01001723 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001724 SDRAM_TIMING_LOW_REG, val, mask));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001725
1726 /* SDRAM Timing High */
Chris Packham1a07d212018-05-10 13:28:29 +12001727 val = 0;
1728 mask = 0;
1729
1730 val = (((t_rfc - 1) & SDRAM_TIMING_HIGH_TRFC_MASK) << SDRAM_TIMING_HIGH_TRFC_OFFS) |
1731 ((t_r2r & SDRAM_TIMING_HIGH_TR2R_MASK) << SDRAM_TIMING_HIGH_TR2R_OFFS) |
1732 ((t_r2w_w2r & SDRAM_TIMING_HIGH_TR2W_W2R_MASK) << SDRAM_TIMING_HIGH_TR2W_W2R_OFFS) |
1733 ((t_w2w & SDRAM_TIMING_HIGH_TW2W_MASK) << SDRAM_TIMING_HIGH_TW2W_OFFS) |
1734 ((((t_rfc - 1) >> 7) & SDRAM_TIMING_HIGH_TRFC_HIGH_MASK) << SDRAM_TIMING_HIGH_TRFC_HIGH_OFFS) |
1735 ((t_r2r_high & SDRAM_TIMING_HIGH_TR2R_HIGH_MASK) << SDRAM_TIMING_HIGH_TR2R_HIGH_OFFS) |
1736 ((t_r2w_w2r_high & SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_MASK) << SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_OFFS) |
1737 (((t_mod - 1) & SDRAM_TIMING_HIGH_TMOD_MASK) << SDRAM_TIMING_HIGH_TMOD_OFFS) |
1738 ((((t_mod - 1) >> 4) & SDRAM_TIMING_HIGH_TMOD_HIGH_MASK) << SDRAM_TIMING_HIGH_TMOD_HIGH_OFFS);
1739
1740 mask = (SDRAM_TIMING_HIGH_TRFC_MASK << SDRAM_TIMING_HIGH_TRFC_OFFS) |
1741 (SDRAM_TIMING_HIGH_TR2R_MASK << SDRAM_TIMING_HIGH_TR2R_OFFS) |
1742 (SDRAM_TIMING_HIGH_TR2W_W2R_MASK << SDRAM_TIMING_HIGH_TR2W_W2R_OFFS) |
1743 (SDRAM_TIMING_HIGH_TW2W_MASK << SDRAM_TIMING_HIGH_TW2W_OFFS) |
1744 (SDRAM_TIMING_HIGH_TRFC_HIGH_MASK << SDRAM_TIMING_HIGH_TRFC_HIGH_OFFS) |
1745 (SDRAM_TIMING_HIGH_TR2R_HIGH_MASK << SDRAM_TIMING_HIGH_TR2R_HIGH_OFFS) |
1746 (SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_MASK << SDRAM_TIMING_HIGH_TR2W_W2R_HIGH_OFFS) |
1747 (SDRAM_TIMING_HIGH_TMOD_MASK << SDRAM_TIMING_HIGH_TMOD_OFFS) |
1748 (SDRAM_TIMING_HIGH_TMOD_HIGH_MASK << SDRAM_TIMING_HIGH_TMOD_HIGH_OFFS);
1749
Stefan Roese5ffceb82015-03-26 15:36:56 +01001750 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001751 SDRAM_TIMING_HIGH_REG, val, mask));
1752
Stefan Roese5ffceb82015-03-26 15:36:56 +01001753 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001754 SDRAM_CFG_REG,
1755 refresh_interval_cnt << REFRESH_OFFS,
1756 REFRESH_MASK << REFRESH_OFFS));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001757 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001758 SDRAM_ADDR_CTRL_REG, (t_faw - 1) << T_FAW_OFFS,
1759 T_FAW_MASK << T_FAW_OFFS));
1760
1761 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id, DDR_TIMING_REG,
1762 (t_pd - 1) << DDR_TIMING_TPD_OFFS |
1763 (t_xpdll - 1) << DDR_TIMING_TXPDLL_OFFS,
1764 DDR_TIMING_TPD_MASK << DDR_TIMING_TPD_OFFS |
1765 DDR_TIMING_TXPDLL_MASK << DDR_TIMING_TXPDLL_OFFS));
1766
Stefan Roese5ffceb82015-03-26 15:36:56 +01001767
1768 return MV_OK;
1769}
1770
Chris Packham1a07d212018-05-10 13:28:29 +12001771
Stefan Roese5ffceb82015-03-26 15:36:56 +01001772/*
Stefan Roese5ffceb82015-03-26 15:36:56 +01001773 * Write CS Result
1774 */
1775int ddr3_tip_write_cs_result(u32 dev_num, u32 offset)
1776{
1777 u32 if_id, bus_num, cs_bitmask, data_val, cs_num;
Chris Packham1a07d212018-05-10 13:28:29 +12001778 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1779 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001780
1781 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001782 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
1783 for (bus_num = 0; bus_num < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001784 bus_num++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001785 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001786 cs_bitmask =
1787 tm->interface_params[if_id].
1788 as_bus_params[bus_num].cs_bitmask;
1789 if (cs_bitmask != effective_cs) {
1790 cs_num = GET_CS_FROM_MASK(cs_bitmask);
1791 ddr3_tip_bus_read(dev_num, if_id,
1792 ACCESS_TYPE_UNICAST, bus_num,
1793 DDR_PHY_DATA,
1794 offset +
Chris Packham1a07d212018-05-10 13:28:29 +12001795 (effective_cs * 0x4),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001796 &data_val);
1797 ddr3_tip_bus_write(dev_num,
1798 ACCESS_TYPE_UNICAST,
1799 if_id,
1800 ACCESS_TYPE_UNICAST,
1801 bus_num, DDR_PHY_DATA,
1802 offset +
Chris Packham1a07d212018-05-10 13:28:29 +12001803 (cs_num * 0x4),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001804 data_val);
1805 }
1806 }
1807 }
1808
1809 return MV_OK;
1810}
1811
1812/*
1813 * Write MRS
1814 */
Chris Packham1a07d212018-05-10 13:28:29 +12001815int 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 +01001816{
Chris Packham1a07d212018-05-10 13:28:29 +12001817 u32 if_id;
1818 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001819
Stefan Roese5ffceb82015-03-26 15:36:56 +01001820 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12001821 PARAM_NOT_CARE, mr_data[mr_num].reg_addr, data, mask));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001822 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001823 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001824 CHECK_STATUS(ddr3_tip_if_write
1825 (dev_num, ACCESS_TYPE_UNICAST, if_id,
Chris Packham1a07d212018-05-10 13:28:29 +12001826 SDRAM_OP_REG,
1827 (cs_mask_arr[if_id] << 8) | mr_data[mr_num].cmd, 0xf1f));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001828 }
1829
1830 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001831 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001832 if (ddr3_tip_if_polling(dev_num, ACCESS_TYPE_UNICAST, if_id, 0,
Chris Packham1a07d212018-05-10 13:28:29 +12001833 0x1f, SDRAM_OP_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001834 MAX_POLLING_ITERATIONS) != MV_OK) {
1835 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
1836 ("write_mrs_cmd: Poll cmd fail"));
1837 }
1838 }
1839
1840 return MV_OK;
1841}
1842
1843/*
1844 * Reset XSB Read FIFO
1845 */
1846int ddr3_tip_reset_fifo_ptr(u32 dev_num)
1847{
1848 u32 if_id = 0;
1849
1850 /* Configure PHY reset value to 0 in order to "clean" the FIFO */
1851 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1852 if_id, 0x15c8, 0, 0xff000000));
1853 /*
1854 * Move PHY to RL mode (only in RL mode the PHY overrides FIFO values
1855 * during FIFO reset)
1856 */
1857 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1858 if_id, TRAINING_SW_2_REG,
1859 0x1, 0x9));
1860 /* In order that above configuration will influence the PHY */
1861 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1862 if_id, 0x15b0,
1863 0x80000000, 0x80000000));
1864 /* Reset read fifo assertion */
1865 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1866 if_id, 0x1400, 0, 0x40000000));
1867 /* Reset read fifo deassertion */
1868 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1869 if_id, 0x1400,
1870 0x40000000, 0x40000000));
1871 /* Move PHY back to functional mode */
1872 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1873 if_id, TRAINING_SW_2_REG,
1874 0x8, 0x9));
1875 /* Stop training machine */
1876 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1877 if_id, 0x15b4, 0x10000, 0x10000));
1878
1879 return MV_OK;
1880}
1881
1882/*
1883 * Reset Phy registers
1884 */
1885int ddr3_tip_ddr3_reset_phy_regs(u32 dev_num)
1886{
1887 u32 if_id, phy_id, cs;
Chris Packham1a07d212018-05-10 13:28:29 +12001888 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1889 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01001890
1891 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001892 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
1893 for (phy_id = 0; phy_id < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01001894 phy_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12001895 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, phy_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01001896 CHECK_STATUS(ddr3_tip_bus_write
1897 (dev_num, ACCESS_TYPE_UNICAST,
1898 if_id, ACCESS_TYPE_UNICAST,
1899 phy_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +12001900 WL_PHY_REG(effective_cs),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001901 phy_reg0_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 RL_PHY_REG(effective_cs),
Stefan Roese5ffceb82015-03-26 15:36:56 +01001906 phy_reg2_val));
1907 CHECK_STATUS(ddr3_tip_bus_write
1908 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1909 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +12001910 CRX_PHY_REG(effective_cs), phy_reg3_val));
1911 CHECK_STATUS(ddr3_tip_bus_write
1912 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1913 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1914 CTX_PHY_REG(effective_cs), phy_reg1_val));
1915 CHECK_STATUS(ddr3_tip_bus_write
1916 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1917 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1918 PBS_TX_BCAST_PHY_REG(effective_cs), 0x0));
1919 CHECK_STATUS(ddr3_tip_bus_write
1920 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1921 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1922 PBS_RX_BCAST_PHY_REG(effective_cs), 0));
1923 CHECK_STATUS(ddr3_tip_bus_write
1924 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1925 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1926 PBS_TX_PHY_REG(effective_cs, DQSP_PAD), 0));
1927 CHECK_STATUS(ddr3_tip_bus_write
1928 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1929 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1930 PBS_RX_PHY_REG(effective_cs, DQSP_PAD), 0));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001931 CHECK_STATUS(ddr3_tip_bus_write
1932 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1933 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
Chris Packham1a07d212018-05-10 13:28:29 +12001934 PBS_TX_PHY_REG(effective_cs, DQSN_PAD), 0));
1935 CHECK_STATUS(ddr3_tip_bus_write
1936 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1937 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
1938 PBS_RX_PHY_REG(effective_cs, DQSN_PAD), 0));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001939 }
1940 }
1941
1942 /* Set Receiver Calibration value */
1943 for (cs = 0; cs < MAX_CS_NUM; cs++) {
1944 /* PHY register 0xdb bits[5:0] - configure to 63 */
1945 CHECK_STATUS(ddr3_tip_bus_write
1946 (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE,
1947 ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE,
Chris Packham1a07d212018-05-10 13:28:29 +12001948 DDR_PHY_DATA, VREF_BCAST_PHY_REG(cs), 63));
Stefan Roese5ffceb82015-03-26 15:36:56 +01001949 }
1950
1951 return MV_OK;
1952}
1953
1954/*
1955 * Restore Dunit registers
1956 */
1957int ddr3_tip_restore_dunit_regs(u32 dev_num)
1958{
1959 u32 index_cnt;
1960
Chris Packham1a07d212018-05-10 13:28:29 +12001961 mv_ddr_set_calib_controller();
1962
Stefan Roese5ffceb82015-03-26 15:36:56 +01001963 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12001964 PARAM_NOT_CARE, MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001965 0x1, 0x1));
1966 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12001967 PARAM_NOT_CARE, MAIN_PADS_CAL_MACH_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001968 calibration_update_control << 3,
1969 0x3 << 3));
1970 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST,
1971 PARAM_NOT_CARE,
Chris Packham1a07d212018-05-10 13:28:29 +12001972 ODPG_WR_RD_MODE_ENA_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01001973 0xffff, MASK_ALL_BITS));
1974
1975 for (index_cnt = 0; index_cnt < ARRAY_SIZE(odpg_default_value);
1976 index_cnt++) {
1977 CHECK_STATUS(ddr3_tip_if_write
1978 (dev_num, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE,
1979 odpg_default_value[index_cnt].reg_addr,
1980 odpg_default_value[index_cnt].reg_data,
1981 odpg_default_value[index_cnt].reg_mask));
1982 }
1983
1984 return MV_OK;
1985}
1986
Chris Packham1a07d212018-05-10 13:28:29 +12001987int ddr3_tip_adll_regs_bypass(u32 dev_num, u32 reg_val1, u32 reg_val2)
1988{
1989 u32 if_id, phy_id;
1990 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
1991 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
1992
1993 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
1994 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
1995 for (phy_id = 0; phy_id < octets_per_if_num; phy_id++) {
1996 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, phy_id);
1997 CHECK_STATUS(ddr3_tip_bus_write
1998 (dev_num, ACCESS_TYPE_UNICAST, if_id,
1999 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
2000 CTX_PHY_REG(effective_cs), reg_val1));
2001 CHECK_STATUS(ddr3_tip_bus_write
2002 (dev_num, ACCESS_TYPE_UNICAST, if_id,
2003 ACCESS_TYPE_UNICAST, phy_id, DDR_PHY_DATA,
2004 PBS_TX_BCAST_PHY_REG(effective_cs), reg_val2));
2005 }
2006 }
2007
2008 return MV_OK;
2009}
2010
Stefan Roese5ffceb82015-03-26 15:36:56 +01002011/*
2012 * Auto tune main flow
2013 */
2014static int ddr3_tip_ddr3_training_main_flow(u32 dev_num)
2015{
Chris Packham1a07d212018-05-10 13:28:29 +12002016/* TODO: enable this functionality for other platforms */
2017#if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_39X)
Stefan Roese5ffceb82015-03-26 15:36:56 +01002018 struct init_cntr_param init_cntr_prm;
Chris Packham1a07d212018-05-10 13:28:29 +12002019#endif
Stefan Roese5ffceb82015-03-26 15:36:56 +01002020 int ret = MV_OK;
Chris Packham1a07d212018-05-10 13:28:29 +12002021 int adll_bypass_flag = 0;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002022 u32 if_id;
Chris Packham4bf81db2018-12-03 14:26:49 +13002023 unsigned int max_cs = mv_ddr_cs_num_get();
Chris Packham1a07d212018-05-10 13:28:29 +12002024 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Chris Packham4bf81db2018-12-03 14:26:49 +13002025 enum mv_ddr_freq freq = tm->interface_params[0].memory_freq;
2026 unsigned int *freq_tbl = mv_ddr_freq_tbl_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002027
Chris Packham1a07d212018-05-10 13:28:29 +12002028#ifdef DDR_VIEWER_TOOL
Stefan Roese5ffceb82015-03-26 15:36:56 +01002029 if (debug_training == DEBUG_LEVEL_TRACE) {
2030 CHECK_STATUS(print_device_info((u8)dev_num));
2031 }
2032#endif
2033
Chris Packham1a07d212018-05-10 13:28:29 +12002034 ddr3_tip_validate_algo_components(dev_num);
2035
Stefan Roese5ffceb82015-03-26 15:36:56 +01002036 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2037 CHECK_STATUS(ddr3_tip_ddr3_reset_phy_regs(dev_num));
2038 }
2039 /* Set to 0 after each loop to avoid illegal value may be used */
2040 effective_cs = 0;
2041
Chris Packham4bf81db2018-12-03 14:26:49 +13002042 freq_tbl[MV_DDR_FREQ_LOW_FREQ] = dfs_low_freq;
Chris Packham1a07d212018-05-10 13:28:29 +12002043
Stefan Roese5ffceb82015-03-26 15:36:56 +01002044 if (is_pll_before_init != 0) {
2045 for (if_id = 0; if_id < MAX_INTERFACE_NUM; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12002046 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002047 config_func_info[dev_num].tip_set_freq_divider_func(
2048 (u8)dev_num, if_id, freq);
2049 }
2050 }
2051
Chris Packham1a07d212018-05-10 13:28:29 +12002052/* TODO: enable this functionality for other platforms */
2053#if defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_39X)
Stefan Roese5ffceb82015-03-26 15:36:56 +01002054 if (is_adll_calib_before_init != 0) {
2055 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2056 ("with adll calib before init\n"));
2057 adll_calibration(dev_num, ACCESS_TYPE_MULTICAST, 0, freq);
2058 }
2059
2060 if (is_reg_dump != 0) {
2061 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2062 ("Dump before init controller\n"));
2063 ddr3_tip_reg_dump(dev_num);
2064 }
2065
2066 if (mask_tune_func & INIT_CONTROLLER_MASK_BIT) {
2067 training_stage = INIT_CONTROLLER;
2068 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2069 ("INIT_CONTROLLER_MASK_BIT\n"));
2070 init_cntr_prm.do_mrs_phy = 1;
2071 init_cntr_prm.is_ctrl64_bit = 0;
2072 init_cntr_prm.init_phy = 1;
2073 init_cntr_prm.msys_init = 0;
2074 ret = hws_ddr3_tip_init_controller(dev_num, &init_cntr_prm);
2075 if (is_reg_dump != 0)
2076 ddr3_tip_reg_dump(dev_num);
2077 if (ret != MV_OK) {
2078 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2079 ("hws_ddr3_tip_init_controller failure\n"));
2080 if (debug_mode == 0)
2081 return MV_FAIL;
2082 }
2083 }
Chris Packham1a07d212018-05-10 13:28:29 +12002084#endif
Stefan Roese5ffceb82015-03-26 15:36:56 +01002085
Chris Packham1a07d212018-05-10 13:28:29 +12002086 ret = adll_calibration(dev_num, ACCESS_TYPE_MULTICAST, 0, freq);
2087 if (ret != MV_OK) {
2088 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2089 ("adll_calibration failure\n"));
2090 if (debug_mode == 0)
2091 return MV_FAIL;
2092 }
Stefan Roese5ffceb82015-03-26 15:36:56 +01002093
2094 if (mask_tune_func & SET_LOW_FREQ_MASK_BIT) {
2095 training_stage = SET_LOW_FREQ;
Chris Packham1a07d212018-05-10 13:28:29 +12002096
2097 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2098 ddr3_tip_adll_regs_bypass(dev_num, 0, 0x1f);
2099 adll_bypass_flag = 1;
2100 }
2101 effective_cs = 0;
2102
Stefan Roese5ffceb82015-03-26 15:36:56 +01002103 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2104 ("SET_LOW_FREQ_MASK_BIT %d\n",
Chris Packham4bf81db2018-12-03 14:26:49 +13002105 freq_tbl[low_freq]));
Stefan Roese5ffceb82015-03-26 15:36:56 +01002106 ret = ddr3_tip_freq_set(dev_num, ACCESS_TYPE_MULTICAST,
2107 PARAM_NOT_CARE, low_freq);
2108 if (is_reg_dump != 0)
2109 ddr3_tip_reg_dump(dev_num);
2110 if (ret != MV_OK) {
2111 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2112 ("ddr3_tip_freq_set failure\n"));
2113 if (debug_mode == 0)
2114 return MV_FAIL;
2115 }
2116 }
2117
Chris Packham1a07d212018-05-10 13:28:29 +12002118 if (mask_tune_func & WRITE_LEVELING_LF_MASK_BIT) {
2119 training_stage = WRITE_LEVELING_LF;
2120 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2121 ("WRITE_LEVELING_LF_MASK_BIT\n"));
2122 ret = ddr3_tip_dynamic_write_leveling(dev_num, 1);
2123 if (is_reg_dump != 0)
2124 ddr3_tip_reg_dump(dev_num);
2125 if (ret != MV_OK) {
2126 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2127 ("ddr3_tip_dynamic_write_leveling LF failure\n"));
2128 if (debug_mode == 0)
2129 return MV_FAIL;
2130 }
2131 }
2132
Stefan Roese5ffceb82015-03-26 15:36:56 +01002133 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2134 if (mask_tune_func & LOAD_PATTERN_MASK_BIT) {
2135 training_stage = LOAD_PATTERN;
2136 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2137 ("LOAD_PATTERN_MASK_BIT #%d\n",
2138 effective_cs));
2139 ret = ddr3_tip_load_all_pattern_to_mem(dev_num);
2140 if (is_reg_dump != 0)
2141 ddr3_tip_reg_dump(dev_num);
2142 if (ret != MV_OK) {
2143 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2144 ("ddr3_tip_load_all_pattern_to_mem failure CS #%d\n",
2145 effective_cs));
2146 if (debug_mode == 0)
2147 return MV_FAIL;
2148 }
2149 }
2150 }
Chris Packham1a07d212018-05-10 13:28:29 +12002151
2152 if (adll_bypass_flag == 1) {
2153 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2154 ddr3_tip_adll_regs_bypass(dev_num, phy_reg1_val, 0);
2155 adll_bypass_flag = 0;
2156 }
2157 }
2158
Stefan Roese5ffceb82015-03-26 15:36:56 +01002159 /* Set to 0 after each loop to avoid illegal value may be used */
2160 effective_cs = 0;
2161
2162 if (mask_tune_func & SET_MEDIUM_FREQ_MASK_BIT) {
2163 training_stage = SET_MEDIUM_FREQ;
2164 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2165 ("SET_MEDIUM_FREQ_MASK_BIT %d\n",
Chris Packham4bf81db2018-12-03 14:26:49 +13002166 freq_tbl[medium_freq]));
Stefan Roese5ffceb82015-03-26 15:36:56 +01002167 ret =
2168 ddr3_tip_freq_set(dev_num, ACCESS_TYPE_MULTICAST,
2169 PARAM_NOT_CARE, medium_freq);
2170 if (is_reg_dump != 0)
2171 ddr3_tip_reg_dump(dev_num);
2172 if (ret != MV_OK) {
2173 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2174 ("ddr3_tip_freq_set failure\n"));
2175 if (debug_mode == 0)
2176 return MV_FAIL;
2177 }
2178 }
2179
2180 if (mask_tune_func & WRITE_LEVELING_MASK_BIT) {
2181 training_stage = WRITE_LEVELING;
2182 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2183 ("WRITE_LEVELING_MASK_BIT\n"));
Chris Packham4bf81db2018-12-03 14:26:49 +13002184 if ((rl_mid_freq_wa == 0) || (freq_tbl[medium_freq] == 533)) {
Chris Packham1a07d212018-05-10 13:28:29 +12002185 ret = ddr3_tip_dynamic_write_leveling(dev_num, 0);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002186 } else {
2187 /* Use old WL */
2188 ret = ddr3_tip_legacy_dynamic_write_leveling(dev_num);
2189 }
2190
2191 if (is_reg_dump != 0)
2192 ddr3_tip_reg_dump(dev_num);
2193 if (ret != MV_OK) {
2194 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2195 ("ddr3_tip_dynamic_write_leveling failure\n"));
2196 if (debug_mode == 0)
2197 return MV_FAIL;
2198 }
2199 }
2200
2201 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2202 if (mask_tune_func & LOAD_PATTERN_2_MASK_BIT) {
2203 training_stage = LOAD_PATTERN_2;
2204 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2205 ("LOAD_PATTERN_2_MASK_BIT CS #%d\n",
2206 effective_cs));
2207 ret = ddr3_tip_load_all_pattern_to_mem(dev_num);
2208 if (is_reg_dump != 0)
2209 ddr3_tip_reg_dump(dev_num);
2210 if (ret != MV_OK) {
2211 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2212 ("ddr3_tip_load_all_pattern_to_mem failure CS #%d\n",
2213 effective_cs));
2214 if (debug_mode == 0)
2215 return MV_FAIL;
2216 }
2217 }
2218 }
2219 /* Set to 0 after each loop to avoid illegal value may be used */
2220 effective_cs = 0;
2221
2222 if (mask_tune_func & READ_LEVELING_MASK_BIT) {
2223 training_stage = READ_LEVELING;
2224 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2225 ("READ_LEVELING_MASK_BIT\n"));
Chris Packham4bf81db2018-12-03 14:26:49 +13002226 if ((rl_mid_freq_wa == 0) || (freq_tbl[medium_freq] == 533)) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01002227 ret = ddr3_tip_dynamic_read_leveling(dev_num, medium_freq);
2228 } else {
2229 /* Use old RL */
2230 ret = ddr3_tip_legacy_dynamic_read_leveling(dev_num);
2231 }
2232
2233 if (is_reg_dump != 0)
2234 ddr3_tip_reg_dump(dev_num);
2235 if (ret != MV_OK) {
2236 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2237 ("ddr3_tip_dynamic_read_leveling failure\n"));
2238 if (debug_mode == 0)
2239 return MV_FAIL;
2240 }
2241 }
2242
2243 if (mask_tune_func & WRITE_LEVELING_SUPP_MASK_BIT) {
2244 training_stage = WRITE_LEVELING_SUPP;
2245 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2246 ("WRITE_LEVELING_SUPP_MASK_BIT\n"));
2247 ret = ddr3_tip_dynamic_write_leveling_supp(dev_num);
2248 if (is_reg_dump != 0)
2249 ddr3_tip_reg_dump(dev_num);
2250 if (ret != MV_OK) {
2251 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2252 ("ddr3_tip_dynamic_write_leveling_supp failure\n"));
2253 if (debug_mode == 0)
2254 return MV_FAIL;
2255 }
2256 }
2257
2258 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2259 if (mask_tune_func & PBS_RX_MASK_BIT) {
2260 training_stage = PBS_RX;
2261 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2262 ("PBS_RX_MASK_BIT CS #%d\n",
2263 effective_cs));
2264 ret = ddr3_tip_pbs_rx(dev_num);
2265 if (is_reg_dump != 0)
2266 ddr3_tip_reg_dump(dev_num);
2267 if (ret != MV_OK) {
2268 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2269 ("ddr3_tip_pbs_rx failure CS #%d\n",
2270 effective_cs));
2271 if (debug_mode == 0)
2272 return MV_FAIL;
2273 }
2274 }
2275 }
2276
2277 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2278 if (mask_tune_func & PBS_TX_MASK_BIT) {
2279 training_stage = PBS_TX;
2280 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2281 ("PBS_TX_MASK_BIT CS #%d\n",
2282 effective_cs));
2283 ret = ddr3_tip_pbs_tx(dev_num);
2284 if (is_reg_dump != 0)
2285 ddr3_tip_reg_dump(dev_num);
2286 if (ret != MV_OK) {
2287 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2288 ("ddr3_tip_pbs_tx failure CS #%d\n",
2289 effective_cs));
2290 if (debug_mode == 0)
2291 return MV_FAIL;
2292 }
2293 }
2294 }
2295 /* Set to 0 after each loop to avoid illegal value may be used */
2296 effective_cs = 0;
2297
2298 if (mask_tune_func & SET_TARGET_FREQ_MASK_BIT) {
2299 training_stage = SET_TARGET_FREQ;
2300 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2301 ("SET_TARGET_FREQ_MASK_BIT %d\n",
Chris Packham4bf81db2018-12-03 14:26:49 +13002302 freq_tbl[tm->
Stefan Roese5ffceb82015-03-26 15:36:56 +01002303 interface_params[first_active_if].
2304 memory_freq]));
2305 ret = ddr3_tip_freq_set(dev_num, ACCESS_TYPE_MULTICAST,
2306 PARAM_NOT_CARE,
2307 tm->interface_params[first_active_if].
2308 memory_freq);
2309 if (is_reg_dump != 0)
2310 ddr3_tip_reg_dump(dev_num);
2311 if (ret != MV_OK) {
2312 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2313 ("ddr3_tip_freq_set failure\n"));
2314 if (debug_mode == 0)
2315 return MV_FAIL;
2316 }
2317 }
2318
2319 if (mask_tune_func & WRITE_LEVELING_TF_MASK_BIT) {
2320 training_stage = WRITE_LEVELING_TF;
2321 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2322 ("WRITE_LEVELING_TF_MASK_BIT\n"));
Chris Packham1a07d212018-05-10 13:28:29 +12002323 ret = ddr3_tip_dynamic_write_leveling(dev_num, 0);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002324 if (is_reg_dump != 0)
2325 ddr3_tip_reg_dump(dev_num);
2326 if (ret != MV_OK) {
2327 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2328 ("ddr3_tip_dynamic_write_leveling TF failure\n"));
2329 if (debug_mode == 0)
2330 return MV_FAIL;
2331 }
2332 }
2333
2334 if (mask_tune_func & LOAD_PATTERN_HIGH_MASK_BIT) {
2335 training_stage = LOAD_PATTERN_HIGH;
2336 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("LOAD_PATTERN_HIGH\n"));
2337 ret = ddr3_tip_load_all_pattern_to_mem(dev_num);
2338 if (is_reg_dump != 0)
2339 ddr3_tip_reg_dump(dev_num);
2340 if (ret != MV_OK) {
2341 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2342 ("ddr3_tip_load_all_pattern_to_mem failure\n"));
2343 if (debug_mode == 0)
2344 return MV_FAIL;
2345 }
2346 }
2347
2348 if (mask_tune_func & READ_LEVELING_TF_MASK_BIT) {
2349 training_stage = READ_LEVELING_TF;
2350 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2351 ("READ_LEVELING_TF_MASK_BIT\n"));
2352 ret = ddr3_tip_dynamic_read_leveling(dev_num, tm->
2353 interface_params[first_active_if].
2354 memory_freq);
2355 if (is_reg_dump != 0)
2356 ddr3_tip_reg_dump(dev_num);
2357 if (ret != MV_OK) {
2358 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2359 ("ddr3_tip_dynamic_read_leveling TF failure\n"));
2360 if (debug_mode == 0)
2361 return MV_FAIL;
2362 }
2363 }
2364
Chris Packham1a07d212018-05-10 13:28:29 +12002365 if (mask_tune_func & RL_DQS_BURST_MASK_BIT) {
2366 training_stage = READ_LEVELING_TF;
2367 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2368 ("RL_DQS_BURST_MASK_BIT\n"));
2369 ret = mv_ddr_rl_dqs_burst(0, 0, tm->interface_params[0].memory_freq);
2370 if (is_reg_dump != 0)
2371 ddr3_tip_reg_dump(dev_num);
2372 if (ret != MV_OK) {
2373 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2374 ("mv_ddr_rl_dqs_burst TF failure\n"));
2375 if (debug_mode == 0)
2376 return MV_FAIL;
2377 }
2378 }
2379
Stefan Roese5ffceb82015-03-26 15:36:56 +01002380 if (mask_tune_func & DM_PBS_TX_MASK_BIT) {
2381 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("DM_PBS_TX_MASK_BIT\n"));
2382 }
2383
2384 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2385 if (mask_tune_func & VREF_CALIBRATION_MASK_BIT) {
2386 training_stage = VREF_CALIBRATION;
2387 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("VREF\n"));
2388 ret = ddr3_tip_vref(dev_num);
2389 if (is_reg_dump != 0) {
2390 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2391 ("VREF Dump\n"));
2392 ddr3_tip_reg_dump(dev_num);
2393 }
2394 if (ret != MV_OK) {
2395 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2396 ("ddr3_tip_vref failure\n"));
2397 if (debug_mode == 0)
2398 return MV_FAIL;
2399 }
2400 }
2401 }
2402 /* Set to 0 after each loop to avoid illegal value may be used */
2403 effective_cs = 0;
2404
2405 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2406 if (mask_tune_func & CENTRALIZATION_RX_MASK_BIT) {
2407 training_stage = CENTRALIZATION_RX;
2408 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2409 ("CENTRALIZATION_RX_MASK_BIT CS #%d\n",
2410 effective_cs));
2411 ret = ddr3_tip_centralization_rx(dev_num);
2412 if (is_reg_dump != 0)
2413 ddr3_tip_reg_dump(dev_num);
2414 if (ret != MV_OK) {
2415 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2416 ("ddr3_tip_centralization_rx failure CS #%d\n",
2417 effective_cs));
2418 if (debug_mode == 0)
2419 return MV_FAIL;
2420 }
2421 }
2422 }
2423 /* Set to 0 after each loop to avoid illegal value may be used */
2424 effective_cs = 0;
2425
2426 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2427 if (mask_tune_func & WRITE_LEVELING_SUPP_TF_MASK_BIT) {
2428 training_stage = WRITE_LEVELING_SUPP_TF;
2429 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2430 ("WRITE_LEVELING_SUPP_TF_MASK_BIT CS #%d\n",
2431 effective_cs));
2432 ret = ddr3_tip_dynamic_write_leveling_supp(dev_num);
2433 if (is_reg_dump != 0)
2434 ddr3_tip_reg_dump(dev_num);
2435 if (ret != MV_OK) {
2436 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2437 ("ddr3_tip_dynamic_write_leveling_supp TF failure CS #%d\n",
2438 effective_cs));
2439 if (debug_mode == 0)
2440 return MV_FAIL;
2441 }
2442 }
2443 }
2444 /* Set to 0 after each loop to avoid illegal value may be used */
2445 effective_cs = 0;
2446
Chris Packham1a07d212018-05-10 13:28:29 +12002447
Stefan Roese5ffceb82015-03-26 15:36:56 +01002448 for (effective_cs = 0; effective_cs < max_cs; effective_cs++) {
2449 if (mask_tune_func & CENTRALIZATION_TX_MASK_BIT) {
2450 training_stage = CENTRALIZATION_TX;
2451 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2452 ("CENTRALIZATION_TX_MASK_BIT CS #%d\n",
2453 effective_cs));
2454 ret = ddr3_tip_centralization_tx(dev_num);
2455 if (is_reg_dump != 0)
2456 ddr3_tip_reg_dump(dev_num);
2457 if (ret != MV_OK) {
2458 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2459 ("ddr3_tip_centralization_tx failure CS #%d\n",
2460 effective_cs));
2461 if (debug_mode == 0)
2462 return MV_FAIL;
2463 }
2464 }
2465 }
2466 /* Set to 0 after each loop to avoid illegal value may be used */
2467 effective_cs = 0;
2468
2469 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO, ("restore registers to default\n"));
2470 /* restore register values */
2471 CHECK_STATUS(ddr3_tip_restore_dunit_regs(dev_num));
2472
2473 if (is_reg_dump != 0)
2474 ddr3_tip_reg_dump(dev_num);
2475
2476 return MV_OK;
2477}
2478
2479/*
2480 * DDR3 Dynamic training flow
2481 */
2482static int ddr3_tip_ddr3_auto_tune(u32 dev_num)
2483{
Chris Packham1a07d212018-05-10 13:28:29 +12002484 int status;
2485 u32 if_id, stage;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002486 int is_if_fail = 0, is_auto_tune_fail = 0;
2487
2488 training_stage = INIT_CONTROLLER;
2489
2490 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
2491 for (stage = 0; stage < MAX_STAGE_LIMIT; stage++)
2492 training_result[stage][if_id] = NO_TEST_DONE;
2493 }
2494
Chris Packham1a07d212018-05-10 13:28:29 +12002495 status = ddr3_tip_ddr3_training_main_flow(dev_num);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002496
2497 /* activate XSB test */
2498 if (xsb_validate_type != 0) {
2499 run_xsb_test(dev_num, xsb_validation_base_address, 1, 1,
2500 0x1024);
2501 }
2502
2503 if (is_reg_dump != 0)
2504 ddr3_tip_reg_dump(dev_num);
2505
2506 /* print log */
2507 CHECK_STATUS(ddr3_tip_print_log(dev_num, window_mem_addr));
2508
Chris Packham1a07d212018-05-10 13:28:29 +12002509#ifndef EXCLUDE_DEBUG_PRINTS
2510 if (status != MV_OK) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01002511 CHECK_STATUS(ddr3_tip_print_stability_log(dev_num));
2512 }
Chris Packham1a07d212018-05-10 13:28:29 +12002513#endif /* EXCLUDE_DEBUG_PRINTS */
Stefan Roese5ffceb82015-03-26 15:36:56 +01002514
2515 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
2516 is_if_fail = 0;
2517 for (stage = 0; stage < MAX_STAGE_LIMIT; stage++) {
2518 if (training_result[stage][if_id] == TEST_FAILED)
2519 is_if_fail = 1;
2520 }
2521 if (is_if_fail == 1) {
2522 is_auto_tune_fail = 1;
2523 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2524 ("Auto Tune failed for IF %d\n",
2525 if_id));
2526 }
2527 }
2528
Chris Packham1a07d212018-05-10 13:28:29 +12002529 if (((status == MV_FAIL) && (is_auto_tune_fail == 0)) ||
2530 ((status == MV_OK) && (is_auto_tune_fail == 1))) {
2531 /*
2532 * If MainFlow result and trainingResult DB not in sync,
2533 * issue warning (caused by no update of trainingResult DB
2534 * when failed)
2535 */
2536 DEBUG_TRAINING_IP(DEBUG_LEVEL_INFO,
2537 ("Warning: Algorithm return value and Result DB"
2538 "are not synced (status 0x%x result DB %d)\n",
2539 status, is_auto_tune_fail));
2540 }
2541
2542 if ((status != MV_OK) || (is_auto_tune_fail == 1))
Stefan Roese5ffceb82015-03-26 15:36:56 +01002543 return MV_FAIL;
2544 else
2545 return MV_OK;
2546}
2547
2548/*
2549 * Enable init sequence
2550 */
2551int ddr3_tip_enable_init_sequence(u32 dev_num)
2552{
2553 int is_fail = 0;
2554 u32 if_id = 0, mem_mask = 0, bus_index = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12002555 u32 octets_per_if_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
2556 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002557
2558 /* Enable init sequence */
2559 CHECK_STATUS(ddr3_tip_if_write(dev_num, ACCESS_TYPE_MULTICAST, 0,
Chris Packham1a07d212018-05-10 13:28:29 +12002560 SDRAM_INIT_CTRL_REG, 0x1, 0x1));
Stefan Roese5ffceb82015-03-26 15:36:56 +01002561
2562 for (if_id = 0; if_id <= MAX_INTERFACE_NUM - 1; if_id++) {
Chris Packham1a07d212018-05-10 13:28:29 +12002563 VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002564
2565 if (ddr3_tip_if_polling
2566 (dev_num, ACCESS_TYPE_UNICAST, if_id, 0, 0x1,
Chris Packham1a07d212018-05-10 13:28:29 +12002567 SDRAM_INIT_CTRL_REG,
Stefan Roese5ffceb82015-03-26 15:36:56 +01002568 MAX_POLLING_ITERATIONS) != MV_OK) {
2569 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2570 ("polling failed IF %d\n",
2571 if_id));
2572 is_fail = 1;
2573 continue;
2574 }
2575
2576 mem_mask = 0;
Chris Packham1a07d212018-05-10 13:28:29 +12002577 for (bus_index = 0; bus_index < octets_per_if_num;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002578 bus_index++) {
Chris Packham1a07d212018-05-10 13:28:29 +12002579 VALIDATE_BUS_ACTIVE(tm->bus_act_mask, bus_index);
Stefan Roese5ffceb82015-03-26 15:36:56 +01002580 mem_mask |=
2581 tm->interface_params[if_id].
2582 as_bus_params[bus_index].mirror_enable_bitmask;
2583 }
2584
2585 if (mem_mask != 0) {
2586 /* Disable Multi CS */
2587 CHECK_STATUS(ddr3_tip_if_write
2588 (dev_num, ACCESS_TYPE_MULTICAST,
Chris Packham1a07d212018-05-10 13:28:29 +12002589 if_id, DUAL_DUNIT_CFG_REG, 1 << 3,
Stefan Roese5ffceb82015-03-26 15:36:56 +01002590 1 << 3));
2591 }
2592 }
2593
2594 return (is_fail == 0) ? MV_OK : MV_FAIL;
2595}
2596
2597int ddr3_tip_register_dq_table(u32 dev_num, u32 *table)
2598{
2599 dq_map_table = table;
2600
2601 return MV_OK;
2602}
2603
2604/*
2605 * Check if pup search is locked
2606 */
2607int ddr3_tip_is_pup_lock(u32 *pup_buf, enum hws_training_result read_mode)
2608{
2609 u32 bit_start = 0, bit_end = 0, bit_id;
2610
2611 if (read_mode == RESULT_PER_BIT) {
2612 bit_start = 0;
2613 bit_end = BUS_WIDTH_IN_BITS - 1;
2614 } else {
2615 bit_start = 0;
2616 bit_end = 0;
2617 }
2618
2619 for (bit_id = bit_start; bit_id <= bit_end; bit_id++) {
2620 if (GET_LOCK_RESULT(pup_buf[bit_id]) == 0)
2621 return 0;
2622 }
2623
2624 return 1;
2625}
2626
2627/*
2628 * Get minimum buffer value
2629 */
2630u8 ddr3_tip_get_buf_min(u8 *buf_ptr)
2631{
2632 u8 min_val = 0xff;
2633 u8 cnt = 0;
2634
2635 for (cnt = 0; cnt < BUS_WIDTH_IN_BITS; cnt++) {
2636 if (buf_ptr[cnt] < min_val)
2637 min_val = buf_ptr[cnt];
2638 }
2639
2640 return min_val;
2641}
2642
2643/*
2644 * Get maximum buffer value
2645 */
2646u8 ddr3_tip_get_buf_max(u8 *buf_ptr)
2647{
2648 u8 max_val = 0;
2649 u8 cnt = 0;
2650
2651 for (cnt = 0; cnt < BUS_WIDTH_IN_BITS; cnt++) {
2652 if (buf_ptr[cnt] > max_val)
2653 max_val = buf_ptr[cnt];
2654 }
2655
2656 return max_val;
2657}
2658
2659/*
2660 * The following functions return memory parameters:
2661 * bus and device width, device size
2662 */
2663
2664u32 hws_ddr3_get_bus_width(void)
2665{
Chris Packham1a07d212018-05-10 13:28:29 +12002666 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002667
2668 return (DDR3_IS_16BIT_DRAM_MODE(tm->bus_act_mask) ==
2669 1) ? 16 : 32;
2670}
2671
2672u32 hws_ddr3_get_device_width(u32 if_id)
2673{
Chris Packham1a07d212018-05-10 13:28:29 +12002674 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002675
2676 return (tm->interface_params[if_id].bus_width ==
Chris Packham1a07d212018-05-10 13:28:29 +12002677 MV_DDR_DEV_WIDTH_8BIT) ? 8 : 16;
Stefan Roese5ffceb82015-03-26 15:36:56 +01002678}
2679
2680u32 hws_ddr3_get_device_size(u32 if_id)
2681{
Chris Packham1a07d212018-05-10 13:28:29 +12002682 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002683
2684 if (tm->interface_params[if_id].memory_size >=
Chris Packham1a07d212018-05-10 13:28:29 +12002685 MV_DDR_DIE_CAP_LAST) {
Stefan Roese5ffceb82015-03-26 15:36:56 +01002686 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2687 ("Error: Wrong device size of Cs: %d",
2688 tm->interface_params[if_id].memory_size));
2689 return 0;
2690 } else {
2691 return 1 << tm->interface_params[if_id].memory_size;
2692 }
2693}
2694
2695int hws_ddr3_calc_mem_cs_size(u32 if_id, u32 cs, u32 *cs_size)
2696{
2697 u32 cs_mem_size, dev_size;
2698
2699 dev_size = hws_ddr3_get_device_size(if_id);
2700 if (dev_size != 0) {
2701 cs_mem_size = ((hws_ddr3_get_bus_width() /
2702 hws_ddr3_get_device_width(if_id)) * dev_size);
2703
2704 /* the calculated result in Gbytex16 to avoid float using */
2705
2706 if (cs_mem_size == 2) {
2707 *cs_size = _128M;
2708 } else if (cs_mem_size == 4) {
2709 *cs_size = _256M;
2710 } else if (cs_mem_size == 8) {
2711 *cs_size = _512M;
2712 } else if (cs_mem_size == 16) {
2713 *cs_size = _1G;
2714 } else if (cs_mem_size == 32) {
2715 *cs_size = _2G;
2716 } else {
2717 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2718 ("Error: Wrong Memory size of Cs: %d", cs));
2719 return MV_FAIL;
2720 }
2721 return MV_OK;
2722 } else {
2723 return MV_FAIL;
2724 }
2725}
2726
2727int hws_ddr3_cs_base_adr_calc(u32 if_id, u32 cs, u32 *cs_base_addr)
2728{
2729 u32 cs_mem_size = 0;
2730#ifdef DEVICE_MAX_DRAM_ADDRESS_SIZE
2731 u32 physical_mem_size;
2732 u32 max_mem_size = DEVICE_MAX_DRAM_ADDRESS_SIZE;
2733#endif
2734
2735 if (hws_ddr3_calc_mem_cs_size(if_id, cs, &cs_mem_size) != MV_OK)
2736 return MV_FAIL;
2737
2738#ifdef DEVICE_MAX_DRAM_ADDRESS_SIZE
Chris Packham1a07d212018-05-10 13:28:29 +12002739 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
Stefan Roese5ffceb82015-03-26 15:36:56 +01002740 /*
2741 * if number of address pins doesn't allow to use max mem size that
2742 * is defined in topology mem size is defined by
2743 * DEVICE_MAX_DRAM_ADDRESS_SIZE
2744 */
Chris Packham1a07d212018-05-10 13:28:29 +12002745 physical_mem_size = mem_size[tm->interface_params[0].memory_size];
Stefan Roese5ffceb82015-03-26 15:36:56 +01002746
2747 if (hws_ddr3_get_device_width(cs) == 16) {
2748 /*
2749 * 16bit mem device can be twice more - no need in less
2750 * significant pin
2751 */
2752 max_mem_size = DEVICE_MAX_DRAM_ADDRESS_SIZE * 2;
2753 }
2754
2755 if (physical_mem_size > max_mem_size) {
2756 cs_mem_size = max_mem_size *
2757 (hws_ddr3_get_bus_width() /
2758 hws_ddr3_get_device_width(if_id));
2759 DEBUG_TRAINING_IP(DEBUG_LEVEL_ERROR,
2760 ("Updated Physical Mem size is from 0x%x to %x\n",
2761 physical_mem_size,
2762 DEVICE_MAX_DRAM_ADDRESS_SIZE));
2763 }
2764#endif
2765
2766 /* calculate CS base addr */
2767 *cs_base_addr = ((cs_mem_size) * cs) & 0xffff0000;
2768
2769 return MV_OK;
2770}
Chris Packham4bf81db2018-12-03 14:26:49 +13002771
2772/* TODO: consider to move to misl phy driver */
2773enum {
2774 MISL_PHY_DRV_OHM_30 = 0xf,
2775 MISL_PHY_DRV_OHM_48 = 0xa,
2776 MISL_PHY_DRV_OHM_80 = 0x6,
2777 MISL_PHY_DRV_OHM_120 = 0x4
2778};
2779
2780enum {
2781 MISL_PHY_ODT_OHM_60 = 0x8,
2782 MISL_PHY_ODT_OHM_80 = 0x6,
2783 MISL_PHY_ODT_OHM_120 = 0x4,
2784 MISL_PHY_ODT_OHM_240 = 0x2
2785};
2786
2787static unsigned int mv_ddr_misl_phy_drv_calc(unsigned int cfg)
2788{
2789 unsigned int val;
2790
2791 switch (cfg) {
2792 case MV_DDR_OHM_30:
2793 val = MISL_PHY_DRV_OHM_30;
2794 break;
2795 case MV_DDR_OHM_48:
2796 val = MISL_PHY_DRV_OHM_48;
2797 break;
2798 case MV_DDR_OHM_80:
2799 val = MISL_PHY_DRV_OHM_80;
2800 break;
2801 case MV_DDR_OHM_120:
2802 val = MISL_PHY_DRV_OHM_120;
2803 break;
2804 default:
2805 val = PARAM_UNDEFINED;
2806 }
2807
2808 return val;
2809}
2810
2811static unsigned int mv_ddr_misl_phy_odt_calc(unsigned int cfg)
2812{
2813 unsigned int val;
2814
2815 switch (cfg) {
2816 case MV_DDR_OHM_60:
2817 val = MISL_PHY_ODT_OHM_60;
2818 break;
2819 case MV_DDR_OHM_80:
2820 val = MISL_PHY_ODT_OHM_80;
2821 break;
2822 case MV_DDR_OHM_120:
2823 val = MISL_PHY_ODT_OHM_120;
2824 break;
2825 case MV_DDR_OHM_240:
2826 val = MISL_PHY_ODT_OHM_240;
2827 break;
2828 default:
2829 val = PARAM_UNDEFINED;
2830 }
2831
2832 return val;
2833}
2834
2835unsigned int mv_ddr_misl_phy_drv_data_p_get(void)
2836{
2837 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2838 unsigned int drv_data_p = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_data_p);
2839
2840 if (drv_data_p == PARAM_UNDEFINED)
2841 printf("error: %s: unsupported drv_data_p parameter found\n", __func__);
2842
2843 return drv_data_p;
2844}
2845
2846unsigned int mv_ddr_misl_phy_drv_data_n_get(void)
2847{
2848 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2849 unsigned int drv_data_n = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_data_n);
2850
2851 if (drv_data_n == PARAM_UNDEFINED)
2852 printf("error: %s: unsupported drv_data_n parameter found\n", __func__);
2853
2854 return drv_data_n;
2855}
2856
2857unsigned int mv_ddr_misl_phy_drv_ctrl_p_get(void)
2858{
2859 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2860 unsigned int drv_ctrl_p = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_ctrl_p);
2861
2862 if (drv_ctrl_p == PARAM_UNDEFINED)
2863 printf("error: %s: unsupported drv_ctrl_p parameter found\n", __func__);
2864
2865 return drv_ctrl_p;
2866}
2867
2868unsigned int mv_ddr_misl_phy_drv_ctrl_n_get(void)
2869{
2870 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2871 unsigned int drv_ctrl_n = mv_ddr_misl_phy_drv_calc(tm->edata.phy_edata.drv_ctrl_n);
2872
2873 if (drv_ctrl_n == PARAM_UNDEFINED)
2874 printf("error: %s: unsupported drv_ctrl_n parameter found\n", __func__);
2875
2876 return drv_ctrl_n;
2877}
2878
2879unsigned int mv_ddr_misl_phy_odt_p_get(void)
2880{
2881 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2882 unsigned int cs_num = mv_ddr_cs_num_get();
2883 unsigned int odt_p = PARAM_UNDEFINED;
2884
2885 if (cs_num > 0 && cs_num <= MAX_CS_NUM)
2886 odt_p = mv_ddr_misl_phy_odt_calc(tm->edata.phy_edata.odt_p[cs_num - 1]);
2887
2888 if (odt_p == PARAM_UNDEFINED)
2889 printf("error: %s: unsupported odt_p parameter found\n", __func__);
2890
2891 return odt_p;
2892}
2893
2894unsigned int mv_ddr_misl_phy_odt_n_get(void)
2895{
2896 struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
2897 unsigned int cs_num = mv_ddr_cs_num_get();
2898 unsigned int odt_n = PARAM_UNDEFINED;
2899
2900 if (cs_num > 0 && cs_num <= MAX_CS_NUM)
2901 odt_n = mv_ddr_misl_phy_odt_calc(tm->edata.phy_edata.odt_n[cs_num - 1]);
2902
2903 if (odt_n == PARAM_UNDEFINED)
2904 printf("error: %s: unsupported odt_n parameter found\n", __func__);
2905
2906 return odt_n;
2907}