blob: 055516b67e9ceada875aa93541f7ae4f91676b70 [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
6#ifndef _DDR3_INIT_H
7#define _DDR3_INIT_H
8
Chris Packham1a07d212018-05-10 13:28:29 +12009#include "ddr_ml_wrapper.h"
Chris Packham1a07d212018-05-10 13:28:29 +120010#include "mv_ddr_plat.h"
Chris Packham1a07d212018-05-10 13:28:29 +120011
12#include "seq_exec.h"
Stefan Roese5ffceb82015-03-26 15:36:56 +010013#include "ddr3_logging_def.h"
14#include "ddr3_training_hw_algo.h"
15#include "ddr3_training_ip.h"
16#include "ddr3_training_ip_centralization.h"
17#include "ddr3_training_ip_engine.h"
18#include "ddr3_training_ip_flow.h"
19#include "ddr3_training_ip_pbs.h"
20#include "ddr3_training_ip_prv_if.h"
Stefan Roese5ffceb82015-03-26 15:36:56 +010021#include "ddr3_training_leveling.h"
22#include "xor.h"
23
Stefan Roese5ffceb82015-03-26 15:36:56 +010024/* For checking function return values */
25#define CHECK_STATUS(orig_func) \
26 { \
27 int status; \
28 status = orig_func; \
29 if (MV_OK != status) \
30 return status; \
31 }
32
Chris Packham1a07d212018-05-10 13:28:29 +120033#define SUB_VERSION 0
34
Stefan Roese5ffceb82015-03-26 15:36:56 +010035enum log_level {
36 MV_LOG_LEVEL_0,
37 MV_LOG_LEVEL_1,
38 MV_LOG_LEVEL_2,
39 MV_LOG_LEVEL_3
40};
41
Chris Packham4bf81db2018-12-03 14:26:49 +130042/* TODO: consider to move to misl phy driver */
43#define MISL_PHY_DRV_P_OFFS 0x7
44#define MISL_PHY_DRV_N_OFFS 0x0
45#define MISL_PHY_ODT_P_OFFS 0x6
46#define MISL_PHY_ODT_N_OFFS 0x0
47
Stefan Roese5ffceb82015-03-26 15:36:56 +010048/* Globals */
Chris Packham1a07d212018-05-10 13:28:29 +120049extern u8 debug_training, debug_calibration, debug_ddr4_centralization,
50 debug_tap_tuning, debug_dm_tuning;
Stefan Roese5ffceb82015-03-26 15:36:56 +010051extern u8 is_reg_dump;
52extern u8 generic_init_controller;
Chris Packham4bf81db2018-12-03 14:26:49 +130053/* list of allowed frequency listed in order of enum mv_ddr_freq */
Stefan Roese5ffceb82015-03-26 15:36:56 +010054extern u32 is_pll_old;
Stefan Roese5ffceb82015-03-26 15:36:56 +010055extern struct pattern_info pattern_table[];
Stefan Roese5ffceb82015-03-26 15:36:56 +010056extern u8 debug_centralization, debug_training_ip, debug_training_bist,
57 debug_pbs, debug_training_static, debug_leveling;
Stefan Roese5ffceb82015-03-26 15:36:56 +010058extern struct hws_tip_config_func_db config_func_info[];
Stefan Roese5ffceb82015-03-26 15:36:56 +010059extern u8 twr_mask_table[];
60extern u8 cl_mask_table[];
61extern u8 cwl_mask_table[];
Stefan Roese5ffceb82015-03-26 15:36:56 +010062extern u32 speed_bin_table_t_rc[];
63extern u32 speed_bin_table_t_rcd_t_rp[];
Stefan Roese5ffceb82015-03-26 15:36:56 +010064
Chris Packham1a07d212018-05-10 13:28:29 +120065extern u32 vref_init_val;
Stefan Roese5ffceb82015-03-26 15:36:56 +010066extern u32 g_zpri_data;
67extern u32 g_znri_data;
68extern u32 g_zpri_ctrl;
69extern u32 g_znri_ctrl;
70extern u32 g_zpodt_data;
71extern u32 g_znodt_data;
72extern u32 g_zpodt_ctrl;
73extern u32 g_znodt_ctrl;
74extern u32 g_dic;
Chris Packham1a07d212018-05-10 13:28:29 +120075extern u32 g_odt_config;
Stefan Roese5ffceb82015-03-26 15:36:56 +010076extern u32 g_rtt_nom;
Chris Packham1a07d212018-05-10 13:28:29 +120077extern u32 g_rtt_wr;
78extern u32 g_rtt_park;
Stefan Roese5ffceb82015-03-26 15:36:56 +010079
80extern u8 debug_training_access;
Stefan Roese5ffceb82015-03-26 15:36:56 +010081extern u32 first_active_if;
Chris Packham1a07d212018-05-10 13:28:29 +120082extern u32 delay_enable, ck_delay, ca_delay;
Stefan Roese5ffceb82015-03-26 15:36:56 +010083extern u32 mask_tune_func;
84extern u32 rl_version;
85extern int rl_mid_freq_wa;
86extern u8 calibration_update_control; /* 2 external only, 1 is internal only */
Chris Packham4bf81db2018-12-03 14:26:49 +130087extern enum mv_ddr_freq medium_freq;
Stefan Roese5ffceb82015-03-26 15:36:56 +010088
Stefan Roese5ffceb82015-03-26 15:36:56 +010089extern enum hws_result training_result[MAX_STAGE_LIMIT][MAX_INTERFACE_NUM];
Chris Packham4bf81db2018-12-03 14:26:49 +130090extern enum mv_ddr_freq low_freq;
Stefan Roese5ffceb82015-03-26 15:36:56 +010091extern enum auto_tune_stage training_stage;
92extern u32 is_pll_before_init;
93extern u32 is_adll_calib_before_init;
94extern u32 is_dfs_in_init;
95extern int wl_debug_delay;
Chris Packham1a07d212018-05-10 13:28:29 +120096extern u32 silicon_delay[MAX_DEVICE_NUM];
Stefan Roese5ffceb82015-03-26 15:36:56 +010097extern u32 start_pattern, end_pattern;
98extern u32 phy_reg0_val;
99extern u32 phy_reg1_val;
100extern u32 phy_reg2_val;
101extern u32 phy_reg3_val;
102extern enum hws_pattern sweep_pattern;
103extern enum hws_pattern pbs_pattern;
Chris Packham1a07d212018-05-10 13:28:29 +1200104extern u32 g_znri_data;
105extern u32 g_zpri_data;
106extern u32 g_znri_ctrl;
107extern u32 g_zpri_ctrl;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100108extern u32 finger_test, p_finger_start, p_finger_end, n_finger_start,
109 n_finger_end, p_finger_step, n_finger_step;
Chris Packham1a07d212018-05-10 13:28:29 +1200110extern u32 mode_2t;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100111extern u32 xsb_validate_type;
112extern u32 xsb_validation_base_address;
113extern u32 odt_additional;
114extern u32 debug_mode;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100115extern u32 debug_dunit;
116extern u32 clamp_tbl[];
Chris Packham4bf81db2018-12-03 14:26:49 +1300117extern u32 freq_mask[MAX_DEVICE_NUM][MV_DDR_FREQ_LAST];
Stefan Roese5ffceb82015-03-26 15:36:56 +0100118
119extern u32 maxt_poll_tries;
120extern u32 is_bist_reset_bit;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100121
122extern u8 vref_window_size[MAX_INTERFACE_NUM][MAX_BUS_NUM];
Stefan Roese5ffceb82015-03-26 15:36:56 +0100123extern u32 effective_cs;
124extern int ddr3_tip_centr_skip_min_win_check;
125extern u32 *dq_map_table;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100126
Stefan Roese5ffceb82015-03-26 15:36:56 +0100127extern u8 debug_training_hw_alg;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100128
Stefan Roese5ffceb82015-03-26 15:36:56 +0100129extern u32 start_xsb_offset;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100130extern u32 odt_config;
Stefan Roese5ffceb82015-03-26 15:36:56 +0100131
Stefan Roese5ffceb82015-03-26 15:36:56 +0100132extern u16 mask_results_dq_reg_map[];
Stefan Roese5ffceb82015-03-26 15:36:56 +0100133
Stefan Roese5ffceb82015-03-26 15:36:56 +0100134extern u32 target_freq;
Chris Packham1a07d212018-05-10 13:28:29 +1200135extern u32 dfs_low_freq;
Chris Packham1a07d212018-05-10 13:28:29 +1200136
137extern u32 nominal_avs;
138extern u32 extension_avs;
139
Stefan Roese5ffceb82015-03-26 15:36:56 +0100140
141/* Prototypes */
Chris Packham1a07d212018-05-10 13:28:29 +1200142int ddr3_init(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100143int ddr3_tip_enable_init_sequence(u32 dev_num);
144
Chris Packham1a07d212018-05-10 13:28:29 +1200145int ddr3_hws_hw_training(enum hws_algo_type algo_mode);
146int mv_ddr_early_init(void);
147int mv_ddr_early_init2(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100148int ddr3_silicon_post_init(void);
149int ddr3_post_run_alg(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100150void ddr3_new_tip_ecc_scrub(void);
151
Stefan Roese5ffceb82015-03-26 15:36:56 +0100152int ddr3_tip_reg_write(u32 dev_num, u32 reg_addr, u32 data);
153int ddr3_tip_reg_read(u32 dev_num, u32 reg_addr, u32 *data, u32 reg_mask);
154int ddr3_silicon_get_ddr_target_freq(u32 *ddr_freq);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100155
156int print_adll(u32 dev_num, u32 adll[MAX_INTERFACE_NUM * MAX_BUS_NUM]);
Chris Packham1a07d212018-05-10 13:28:29 +1200157int print_ph(u32 dev_num, u32 adll[MAX_INTERFACE_NUM * MAX_BUS_NUM]);
158int read_phase_value(u32 dev_num, u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM],
159 int reg_addr, u32 mask);
160int write_leveling_value(u32 dev_num, u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM],
161 u32 pup_ph_values[MAX_INTERFACE_NUM * MAX_BUS_NUM], int reg_addr);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100162int ddr3_tip_restore_dunit_regs(u32 dev_num);
Chris Packham1a07d212018-05-10 13:28:29 +1200163void print_topology(struct mv_ddr_topology_map *tm);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100164
165u32 mv_board_id_get(void);
166
167int ddr3_load_topology_map(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100168void ddr3_hws_set_log_level(enum ddr_lib_debug_block block, u8 level);
Chris Packham1a07d212018-05-10 13:28:29 +1200169void mv_ddr_user_log_level_set(enum ddr_lib_debug_block block);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100170int ddr3_tip_tune_training_params(u32 dev_num,
171 struct tune_train_params *params);
172void get_target_freq(u32 freq_mode, u32 *ddr_freq, u32 *hclk_ps);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100173void ddr3_fast_path_static_cs_size_config(u32 cs_ena);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100174u32 mv_board_id_index_get(u32 board_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100175void ddr3_set_log_level(u32 n_log_level);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100176
177int hws_ddr3_cs_base_adr_calc(u32 if_id, u32 cs, u32 *cs_base_addr);
178
179int ddr3_tip_print_pbs_result(u32 dev_num, u32 cs_num, enum pbs_dir pbs_mode);
180int ddr3_tip_clean_pbs_result(u32 dev_num, enum pbs_dir pbs_mode);
Chris Packham1a07d212018-05-10 13:28:29 +1200181void mv_ddr_mc_config(void);
182int mv_ddr_mc_init(void);
183void mv_ddr_set_calib_controller(void);
Chris Packham4bf81db2018-12-03 14:26:49 +1300184/* TODO: consider to move to misl phy driver */
185unsigned int mv_ddr_misl_phy_drv_data_p_get(void);
186unsigned int mv_ddr_misl_phy_drv_data_n_get(void);
187unsigned int mv_ddr_misl_phy_drv_ctrl_p_get(void);
188unsigned int mv_ddr_misl_phy_drv_ctrl_n_get(void);
189unsigned int mv_ddr_misl_phy_odt_p_get(void);
190unsigned int mv_ddr_misl_phy_odt_n_get(void);
191
Stefan Roese5ffceb82015-03-26 15:36:56 +0100192#endif /* _DDR3_INIT_H */