blob: ba9f7881d54af37678cf62f9ed7c5a2e72844f91 [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
Tony Dinhe2c524b2023-01-18 19:03:04 -0800140#if defined(CONFIG_DDR4)
141/* if 1, SSTL & POD have same Vref and workaround is required */
142extern u8 vref_calibration_wa;
143#endif /* CONFIG_DDR4 */
Stefan Roese5ffceb82015-03-26 15:36:56 +0100144
145/* Prototypes */
Chris Packham1a07d212018-05-10 13:28:29 +1200146int ddr3_init(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100147int ddr3_tip_enable_init_sequence(u32 dev_num);
148
Chris Packham1a07d212018-05-10 13:28:29 +1200149int ddr3_hws_hw_training(enum hws_algo_type algo_mode);
150int mv_ddr_early_init(void);
151int mv_ddr_early_init2(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100152int ddr3_silicon_post_init(void);
153int ddr3_post_run_alg(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100154void ddr3_new_tip_ecc_scrub(void);
155
Stefan Roese5ffceb82015-03-26 15:36:56 +0100156int ddr3_tip_reg_write(u32 dev_num, u32 reg_addr, u32 data);
157int ddr3_tip_reg_read(u32 dev_num, u32 reg_addr, u32 *data, u32 reg_mask);
158int ddr3_silicon_get_ddr_target_freq(u32 *ddr_freq);
Tony Dinhe2c524b2023-01-18 19:03:04 -0800159#if defined(CONFIG_DDR4)
160int mv_ddr4_mode_regs_init(u8 dev_num);
161int mv_ddr4_sdram_config(u32 dev_num);
162int mv_ddr4_phy_config(u32 dev_num);
163int mv_ddr4_calibration_adjust(u32 dev_num, u8 vref_en, u8 pod_only);
164int mv_ddr4_training_main_flow(u32 dev_num);
165#endif /* CONFIG_DDR4 */
Stefan Roese5ffceb82015-03-26 15:36:56 +0100166
167int print_adll(u32 dev_num, u32 adll[MAX_INTERFACE_NUM * MAX_BUS_NUM]);
Chris Packham1a07d212018-05-10 13:28:29 +1200168int print_ph(u32 dev_num, u32 adll[MAX_INTERFACE_NUM * MAX_BUS_NUM]);
169int read_phase_value(u32 dev_num, u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM],
170 int reg_addr, u32 mask);
171int write_leveling_value(u32 dev_num, u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM],
172 u32 pup_ph_values[MAX_INTERFACE_NUM * MAX_BUS_NUM], int reg_addr);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100173int ddr3_tip_restore_dunit_regs(u32 dev_num);
Chris Packham1a07d212018-05-10 13:28:29 +1200174void print_topology(struct mv_ddr_topology_map *tm);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100175
176u32 mv_board_id_get(void);
177
178int ddr3_load_topology_map(void);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100179void ddr3_hws_set_log_level(enum ddr_lib_debug_block block, u8 level);
Chris Packham1a07d212018-05-10 13:28:29 +1200180void mv_ddr_user_log_level_set(enum ddr_lib_debug_block block);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100181int ddr3_tip_tune_training_params(u32 dev_num,
182 struct tune_train_params *params);
183void get_target_freq(u32 freq_mode, u32 *ddr_freq, u32 *hclk_ps);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100184void ddr3_fast_path_static_cs_size_config(u32 cs_ena);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100185u32 mv_board_id_index_get(u32 board_id);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100186void ddr3_set_log_level(u32 n_log_level);
Stefan Roese5ffceb82015-03-26 15:36:56 +0100187
188int hws_ddr3_cs_base_adr_calc(u32 if_id, u32 cs, u32 *cs_base_addr);
189
190int ddr3_tip_print_pbs_result(u32 dev_num, u32 cs_num, enum pbs_dir pbs_mode);
191int ddr3_tip_clean_pbs_result(u32 dev_num, enum pbs_dir pbs_mode);
Chris Packham1a07d212018-05-10 13:28:29 +1200192void mv_ddr_mc_config(void);
193int mv_ddr_mc_init(void);
194void mv_ddr_set_calib_controller(void);
Chris Packham4bf81db2018-12-03 14:26:49 +1300195/* TODO: consider to move to misl phy driver */
196unsigned int mv_ddr_misl_phy_drv_data_p_get(void);
197unsigned int mv_ddr_misl_phy_drv_data_n_get(void);
198unsigned int mv_ddr_misl_phy_drv_ctrl_p_get(void);
199unsigned int mv_ddr_misl_phy_drv_ctrl_n_get(void);
200unsigned int mv_ddr_misl_phy_odt_p_get(void);
201unsigned int mv_ddr_misl_phy_odt_n_get(void);
Tony Dinhe2c524b2023-01-18 19:03:04 -0800202#if defined(CONFIG_DDR4)
203void refresh(void);
204#endif
Chris Packham4bf81db2018-12-03 14:26:49 +1300205
Stefan Roese5ffceb82015-03-26 15:36:56 +0100206#endif /* _DDR3_INIT_H */