2 * Copyright (C) Marvell International Ltd. and its affiliates
4 * SPDX-License-Identifier: GPL-2.0
10 #include <asm/arch/cpu.h>
11 #include <asm/arch/soc.h>
13 #include "ddr3_init.h"
15 static u32 bist_offset = 32;
16 enum hws_pattern sweep_pattern = PATTERN_KILLER_DQ0;
18 static int ddr3_tip_bist_operation(u32 dev_num,
19 enum hws_access_type access_type,
21 enum hws_bist_operation oper_type);
26 int ddr3_tip_bist_activate(u32 dev_num, enum hws_pattern pattern,
27 enum hws_access_type access_type, u32 if_num,
28 enum hws_dir direction,
29 enum hws_stress_jump addr_stress_jump,
30 enum hws_pattern_duration duration,
31 enum hws_bist_operation oper_type,
32 u32 offset, u32 cs_num, u32 pattern_addr_length)
35 u32 delay_between_burst;
37 u32 poll_cnt = 0, max_poll = 1000, i, start_if, end_if;
38 struct pattern_info *pattern_table = ddr3_tip_get_pattern_table();
39 u32 read_data[MAX_INTERFACE_NUM];
40 struct hws_topology_map *tm = ddr3_get_topology_map();
42 /* ODPG Write enable from BIST */
43 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_num,
44 ODPG_DATA_CONTROL_REG, 0x1, 0x1));
45 /* ODPG Read enable/disable from BIST */
46 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_num,
47 ODPG_DATA_CONTROL_REG,
48 (direction == OPER_READ) ?
50 CHECK_STATUS(ddr3_tip_load_pattern_to_odpg(dev_num, access_type, if_num,
53 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_num,
54 ODPG_DATA_BUF_SIZE_REG,
55 pattern_addr_length, MASK_ALL_BITS));
56 tx_burst_size = (direction == OPER_WRITE) ?
57 pattern_table[pattern].tx_burst_size : 0;
58 delay_between_burst = (direction == OPER_WRITE) ? 2 : 0;
59 rd_mode = (direction == OPER_WRITE) ? 1 : 0;
60 CHECK_STATUS(ddr3_tip_configure_odpg
61 (dev_num, access_type, if_num, direction,
62 pattern_table[pattern].num_of_phases_tx, tx_burst_size,
63 pattern_table[pattern].num_of_phases_rx,
65 rd_mode, cs_num, addr_stress_jump, duration));
66 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_num,
67 ODPG_PATTERN_ADDR_OFFSET_REG,
68 offset, MASK_ALL_BITS));
69 if (oper_type == BIST_STOP) {
70 CHECK_STATUS(ddr3_tip_bist_operation(dev_num, access_type,
73 CHECK_STATUS(ddr3_tip_bist_operation(dev_num, access_type,
75 if (duration != DURATION_CONT) {
77 * This pdelay is a WA, becuase polling fives "done"
78 * also the odpg did nmot finish its task
80 if (access_type == ACCESS_TYPE_MULTICAST) {
82 end_if = MAX_INTERFACE_NUM - 1;
88 for (i = start_if; i <= end_if; i++) {
92 for (poll_cnt = 0; poll_cnt < max_poll;
94 CHECK_STATUS(ddr3_tip_if_read
97 if_num, ODPG_BIST_DONE,
101 if ((val & 0x1) == 0x0) {
103 * In SOC type devices this bit
104 * is self clear so, if it was
111 if (poll_cnt >= max_poll) {
112 DEBUG_TRAINING_BIST_ENGINE
114 ("Bist poll failure 2\n"));
115 CHECK_STATUS(ddr3_tip_if_write
119 ODPG_DATA_CONTROL_REG, 0,
125 CHECK_STATUS(ddr3_tip_bist_operation
126 (dev_num, access_type, if_num, BIST_STOP));
130 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_num,
131 ODPG_DATA_CONTROL_REG, 0,
140 int ddr3_tip_bist_read_result(u32 dev_num, u32 if_id,
141 struct bist_result *pst_bist_result)
144 u32 read_data[MAX_INTERFACE_NUM];
145 struct hws_topology_map *tm = ddr3_get_topology_map();
147 if (IS_ACTIVE(tm->if_act_mask, if_id) == 0)
148 return MV_NOT_SUPPORTED;
149 DEBUG_TRAINING_BIST_ENGINE(DEBUG_LEVEL_TRACE,
150 ("ddr3_tip_bist_read_result if_id %d\n",
152 ret = ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST, if_id,
153 ODPG_BIST_FAILED_DATA_HI_REG, read_data,
157 pst_bist_result->bist_fail_high = read_data[if_id];
158 ret = ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST, if_id,
159 ODPG_BIST_FAILED_DATA_LOW_REG, read_data,
163 pst_bist_result->bist_fail_low = read_data[if_id];
165 ret = ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST, if_id,
166 ODPG_BIST_LAST_FAIL_ADDR_REG, read_data,
170 pst_bist_result->bist_last_fail_addr = read_data[if_id];
171 ret = ddr3_tip_if_read(dev_num, ACCESS_TYPE_UNICAST, if_id,
172 ODPG_BIST_DATA_ERROR_COUNTER_REG, read_data,
176 pst_bist_result->bist_error_cnt = read_data[if_id];
182 * BIST flow - Activate & read result
184 int hws_ddr3_run_bist(u32 dev_num, enum hws_pattern pattern, u32 *result,
190 struct bist_result st_bist_result;
191 struct hws_topology_map *tm = ddr3_get_topology_map();
193 for (i = 0; i < MAX_INTERFACE_NUM; i++) {
194 VALIDATE_ACTIVE(tm->if_act_mask, i);
195 hws_ddr3_cs_base_adr_calc(i, cs_num, &win_base);
196 ret = ddr3_tip_bist_activate(dev_num, pattern,
198 i, OPER_WRITE, STRESS_NONE,
199 DURATION_SINGLE, BIST_START,
200 bist_offset + win_base,
203 printf("ddr3_tip_bist_activate failed (0x%x)\n", ret);
207 ret = ddr3_tip_bist_activate(dev_num, pattern,
209 i, OPER_READ, STRESS_NONE,
210 DURATION_SINGLE, BIST_START,
211 bist_offset + win_base,
214 printf("ddr3_tip_bist_activate failed (0x%x)\n", ret);
218 ret = ddr3_tip_bist_read_result(dev_num, i, &st_bist_result);
220 printf("ddr3_tip_bist_read_result failed\n");
223 result[i] = st_bist_result.bist_error_cnt;
233 static int ddr3_tip_bist_operation(u32 dev_num,
234 enum hws_access_type access_type,
235 u32 if_id, enum hws_bist_operation oper_type)
237 if (oper_type == BIST_STOP) {
238 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
239 ODPG_BIST_DONE, 1 << 8, 1 << 8));
241 CHECK_STATUS(ddr3_tip_if_write(dev_num, access_type, if_id,
242 ODPG_BIST_DONE, 1, 1));
251 void ddr3_tip_print_bist_res(void)
255 struct bist_result st_bist_result[MAX_INTERFACE_NUM];
257 struct hws_topology_map *tm = ddr3_get_topology_map();
259 for (i = 0; i < MAX_INTERFACE_NUM; i++) {
260 if (IS_ACTIVE(tm->if_act_mask, i) == 0)
263 res = ddr3_tip_bist_read_result(dev_num, i, &st_bist_result[i]);
265 DEBUG_TRAINING_BIST_ENGINE(
267 ("ddr3_tip_bist_read_result failed\n"));
272 DEBUG_TRAINING_BIST_ENGINE(
274 ("interface | error_cnt | fail_low | fail_high | fail_addr\n"));
276 for (i = 0; i < MAX_INTERFACE_NUM; i++) {
277 if (IS_ACTIVE(tm->if_act_mask, i) ==
281 DEBUG_TRAINING_BIST_ENGINE(
283 ("%d | 0x%08x | 0x%08x | 0x%08x | 0x%08x\n",
284 i, st_bist_result[i].bist_error_cnt,
285 st_bist_result[i].bist_fail_low,
286 st_bist_result[i].bist_fail_high,
287 st_bist_result[i].bist_last_fail_addr));