2018-11-20 10:19:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2018 NXP
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-11-20 10:19:57 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <asm/arch/ddr.h>
|
2020-04-21 06:48:09 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2018-11-20 10:19:57 +00:00
|
|
|
|
2019-12-11 10:01:19 +00:00
|
|
|
int ddr_cfg_phy(struct dram_timing_info *dram_timing)
|
2018-11-20 10:19:57 +00:00
|
|
|
{
|
|
|
|
struct dram_cfg_param *dram_cfg;
|
|
|
|
struct dram_fsp_msg *fsp_msg;
|
|
|
|
unsigned int num;
|
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
2019-12-11 10:01:19 +00:00
|
|
|
int ret;
|
2018-11-20 10:19:57 +00:00
|
|
|
|
|
|
|
/* initialize PHY configuration */
|
|
|
|
dram_cfg = dram_timing->ddrphy_cfg;
|
|
|
|
num = dram_timing->ddrphy_cfg_num;
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
/* config phy reg */
|
|
|
|
dwc_ddrphy_apb_wr(dram_cfg->reg, dram_cfg->val);
|
|
|
|
dram_cfg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load the frequency setpoint message block config */
|
|
|
|
fsp_msg = dram_timing->fsp_msg;
|
|
|
|
for (i = 0; i < dram_timing->fsp_msg_num; i++) {
|
|
|
|
debug("DRAM PHY training for %dMTS\n", fsp_msg->drate);
|
|
|
|
/* set dram PHY input clocks to desired frequency */
|
|
|
|
ddrphy_init_set_dfi_clk(fsp_msg->drate);
|
|
|
|
|
|
|
|
/* load the dram training firmware image */
|
|
|
|
dwc_ddrphy_apb_wr(0xd0000, 0x0);
|
|
|
|
ddr_load_train_firmware(fsp_msg->fw_type);
|
|
|
|
|
|
|
|
/* load the frequency set point message block parameter */
|
|
|
|
dram_cfg = fsp_msg->fsp_cfg;
|
|
|
|
num = fsp_msg->fsp_cfg_num;
|
|
|
|
for (j = 0; j < num; j++) {
|
|
|
|
dwc_ddrphy_apb_wr(dram_cfg->reg, dram_cfg->val);
|
|
|
|
dram_cfg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -------------------- excute the firmware --------------------
|
|
|
|
* Running the firmware is a simply process to taking the
|
|
|
|
* PMU out of reset and stall, then the firwmare will be run
|
|
|
|
* 1. reset the PMU;
|
|
|
|
* 2. begin the excution;
|
|
|
|
* 3. wait for the training done;
|
|
|
|
* 4. read the message block result.
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
dwc_ddrphy_apb_wr(0xd0000, 0x1);
|
|
|
|
dwc_ddrphy_apb_wr(0xd0099, 0x9);
|
|
|
|
dwc_ddrphy_apb_wr(0xd0099, 0x1);
|
|
|
|
dwc_ddrphy_apb_wr(0xd0099, 0x0);
|
|
|
|
|
|
|
|
/* Wait for the training firmware to complete */
|
2019-12-11 10:01:19 +00:00
|
|
|
ret = wait_ddrphy_training_complete();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-11-20 10:19:57 +00:00
|
|
|
|
|
|
|
/* Halt the microcontroller. */
|
|
|
|
dwc_ddrphy_apb_wr(0xd0099, 0x1);
|
|
|
|
|
|
|
|
/* Read the Message Block results */
|
|
|
|
dwc_ddrphy_apb_wr(0xd0000, 0x0);
|
2020-04-21 06:48:09 +00:00
|
|
|
|
2018-11-20 10:19:57 +00:00
|
|
|
ddrphy_init_read_msg_block(fsp_msg->fw_type);
|
2020-04-21 06:48:09 +00:00
|
|
|
|
|
|
|
if(fsp_msg->fw_type != FW_2D_IMAGE)
|
|
|
|
get_trained_CDD(i);
|
|
|
|
|
2018-11-20 10:19:57 +00:00
|
|
|
dwc_ddrphy_apb_wr(0xd0000, 0x1);
|
|
|
|
|
2020-04-21 06:48:09 +00:00
|
|
|
|
2018-11-20 10:19:57 +00:00
|
|
|
fsp_msg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load PHY Init Engine Image */
|
|
|
|
dram_cfg = dram_timing->ddrphy_pie;
|
|
|
|
num = dram_timing->ddrphy_pie_num;
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
dwc_ddrphy_apb_wr(dram_cfg->reg, dram_cfg->val);
|
|
|
|
dram_cfg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save the ddr PHY trained CSR in memory for low power use */
|
|
|
|
ddrphy_trained_csr_save(ddrphy_trained_csr, ddrphy_trained_csr_num);
|
2019-12-11 10:01:19 +00:00
|
|
|
|
|
|
|
return 0;
|
2018-11-20 10:19:57 +00:00
|
|
|
}
|