Commit 72a06ef4 authored by Bai Ping's avatar Bai Ping

MLK-18431-03 imx8mm_evk: use the more generic dram init flow on imx8mm evk

Refact the lpddr4 init flow on i.MX8MM EVK board. board level only need
to provide the necessary dram init related parameter.
Signed-off-by: default avatarBai Ping <ping.bai@nxp.com>
parent 220d0cc7
......@@ -50,6 +50,7 @@ config TARGET_IMX8MM_EVK
bool "imx8mm evk"
select IMX8MM
select SUPPORT_SPL
select IMX8M_LPDDR4
endchoice
......
......@@ -8,5 +8,5 @@ obj-y += imx8mm_evk.o
ifdef CONFIG_SPL_BUILD
obj-y += spl.o
obj-y += ddr/
obj-y += lpddr4_timing.o
endif
#
# Copyright 2018 NXP
#
# SPDX-License-Identifier: GPL-2.0+
#
ifdef CONFIG_SPL_BUILD
obj-y += helper.o
obj-y += lpddr4_cfg_umctl2_m845.o
obj-y += lpddr4_phyinit_train_3000mts_fw09.o
obj-y += lpddr4_pmu_training_3000mts_fw09.o
obj-y += lpddr4_phyinit_task.o
endif
/*
* Copyright 2018 NXP
*
* SPDX-License-Identifier: GPL-2.0+
* Common file for ddr code
*/
#ifndef __M845S_DDR_H_
#define __M845S_DDR_H_
#ifdef DDR_DEBUG
#define ddr_dbg(fmt, ...) printf("DDR: debug:" fmt "\n", ##__VA_ARGS__)
#else
#define ddr_dbg(fmt, ...)
#endif
/*******************************************************************
Desc: user data type
*******************************************************************/
enum fw_type {
FW_1D_IMAGE,
FW_2D_IMAGE,
};
/*******************************************************************
Desc: prototype
*******************************************************************/
void ddr_init(void);
void lpddr4_3000mts_cfg_umctl2(void);
void ddr_load_train_code(enum fw_type type);
void dwc_ddrphy_phyinit_userCustom_E_setDfiClk(int pstate);
void dwc_ddrphy_phyinit_userCustom_J_enterMissionMode(void);
void dwc_ddrphy_phyinit_userCustom_customPostTrain(void);
void dwc_ddrphy_phyinit_userCustom_B_startClockResetPhy(void);
void dwc_ddrphy_phyinit_userCustom_A_bringupPower(void);
void dwc_ddrphy_phyinit_userCustom_overrideUserInput(void);
void dwc_ddrphy_phyinit_userCustom_H_readMsgBlock(unsigned long run_2D);
int dwc_ddrphy_phyinit_userCustom_G_waitFwDone(void);
void lpddr4_750M_cfg_phy(void);
/*******************************************************************
Desc: definition
*******************************************************************/
static inline void reg32_write(unsigned long addr, u32 val)
{
writel(val, addr);
}
static inline uint32_t reg32_read(unsigned long addr)
{
return readl(addr);
}
static inline void reg32setbit(unsigned long addr, u32 bit)
{
setbits_le32(addr, (1 << bit));
}
#endif
/*
* Copyright 2018 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <spl.h>
#include <asm/io.h>
#include <errno.h>
#include <asm/io.h>
#include <asm/arch/ddr_memory_map.h>
#include <asm/sections.h>
#include "ddr.h"
DECLARE_GLOBAL_DATA_PTR;
#define IMEM_LEN 32768//23400 //byte
#define DMEM_LEN 16384//1720 //byte
#define IMEM_2D_OFFSET 49152
#define IMEM_OFFSET_ADDR 0x00050000
#define DMEM_OFFSET_ADDR 0x00054000
#define DDR_TRAIN_CODE_BASE_ADDR IP2APB_DDRPHY_IPS_BASE_ADDR(0)
/* We need PHY iMEM PHY is 32KB padded */
void ddr_load_train_code(enum fw_type type)
{
u32 tmp32, i;
u32 error = 0;
unsigned long pr_to32, pr_from32;
unsigned long fw_offset = type ? IMEM_2D_OFFSET : 0;
unsigned long imem_start = (unsigned long)&_end + fw_offset;
unsigned long dmem_start = imem_start + IMEM_LEN;
pr_from32 = imem_start;
pr_to32 = DDR_TRAIN_CODE_BASE_ADDR + 4 * IMEM_OFFSET_ADDR;
for(i = 0x0; i < IMEM_LEN; ){
tmp32 = readl(pr_from32);
writew(tmp32 & 0x0000ffff, pr_to32);
pr_to32 += 4;
writew((tmp32 >> 16) & 0x0000ffff, pr_to32);
pr_to32 += 4;
pr_from32 += 4;
i += 4;
}
pr_from32 = dmem_start;
pr_to32 = DDR_TRAIN_CODE_BASE_ADDR + 4 * DMEM_OFFSET_ADDR;
for(i = 0x0; i < DMEM_LEN;){
tmp32 = readl(pr_from32);
writew(tmp32 & 0x0000ffff, pr_to32);
pr_to32 += 4;
writew((tmp32 >> 16) & 0x0000ffff, pr_to32);
pr_to32 += 4;
pr_from32 += 4;
i += 4;
}
printf("check ddr4_pmu_train_imem code\n");
pr_from32 = imem_start;
pr_to32 = DDR_TRAIN_CODE_BASE_ADDR + 4 * IMEM_OFFSET_ADDR;
for(i = 0x0; i < IMEM_LEN;){
tmp32 = (readw(pr_to32) & 0x0000ffff);
pr_to32 += 4;
tmp32 += ((readw(pr_to32) & 0x0000ffff) << 16);
if(tmp32 != readl(pr_from32)){
printf("%lx %lx\n", pr_from32, pr_to32);
error++;
}
pr_from32 += 4;
pr_to32 += 4;
i += 4;
}
if(error){
printf("check ddr4_pmu_train_imem code fail=%d\n",error);
}else{
printf("check ddr4_pmu_train_imem code pass\n");
}
printf("check ddr4_pmu_train_dmem code\n");
pr_from32 = dmem_start;
pr_to32 = DDR_TRAIN_CODE_BASE_ADDR + 4 * DMEM_OFFSET_ADDR;
for(i = 0x0; i < DMEM_LEN;){
tmp32 = (readw(pr_to32) & 0x0000ffff);
pr_to32 += 4;
tmp32 += ((readw(pr_to32) & 0x0000ffff) << 16);
if(tmp32 != readl(pr_from32)){
printf("%lx %lx\n", pr_from32, pr_to32);
error++;
}
pr_from32 += 4;
pr_to32 += 4;
i += 4;
}
if(error){
printf("check ddr4_pmu_train_dmem code fail=%d",error);
}else{
printf("check ddr4_pmu_train_dmem code pass\n");
}
}
/*
* Copyright 2018 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <errno.h>
#include <asm/io.h>
#include <asm/arch/ddr_memory_map.h>
#include <asm/arch/clock.h>
#include "lpddr4_define.h"
struct ddr_ctl_param
{
u32 reg; /*reg address */
u32 val; /*config param */
};
static struct ddr_ctl_param ctl_init_cfg[] =
{
{ .reg =DDRC_DBG1(0), .val = 0x00000001},
{ .reg =DDRC_PWRCTL(0), .val = 0x00000001},
#ifdef DDR_ONE_RANK
{ .reg =DDRC_MSTR(0), .val = 0xa1080020},
#else
{ .reg =DDRC_MSTR(0), .val = 0xa3080020},
#endif
#ifdef DDR_800M_CFG
{ .reg =DDRC_RFSHTMG(0), .val = 0x006100E0},
#else
{ .reg =DDRC_RFSHTMG(0), .val = 0x005b00d2},
#endif
#ifdef PHY_TRAIN
{ .reg =DDRC_INIT0(0), .val = 0xC003061B},
#else
#ifdef DDR_FAST_SIM
{ .reg =DDRC_INIT0(0), .val = 0x00030003},
#else
{ .reg =DDRC_INIT0(0), .val = 0x0003061B},
#endif
#endif
#ifdef DDR_FAST_SIM
{ .reg =DDRC_INIT1(0), .val = 0x00060000},
#else
{ .reg =DDRC_INIT1(0), .val = 0x009D0000},
#endif
{ .reg =DDRC_INIT3(0), .val = 0x00D4002D},
#ifdef WR_POST_EXT_3200
{ .reg =DDRC_INIT4(0), .val = 0x00330008},
#else
{ .reg =DDRC_INIT4(0), .val = 0x00310000},
#endif
{ .reg =DDRC_INIT6(0), .val = 0x0066004a},
{ .reg =DDRC_INIT7(0), .val = 0x0006004a},
{ .reg =DDRC_DRAMTMG0(0), .val = 0x1A201B22},
{ .reg =DDRC_DRAMTMG1(0), .val = 0x00060633},
{ .reg =DDRC_DRAMTMG3(0), .val = 0x00C0C000},
{ .reg =DDRC_DRAMTMG4(0), .val = 0x0F04080F},
{ .reg =DDRC_DRAMTMG5(0), .val = 0x02040C0C},
{ .reg =DDRC_DRAMTMG6(0), .val = 0x01010007},
{ .reg =DDRC_DRAMTMG7(0), .val = 0x00000401},
{ .reg =DDRC_DRAMTMG12(0), .val = 0x00020600},
{ .reg =DDRC_DRAMTMG13(0), .val = 0x0C100002},
{ .reg =DDRC_DRAMTMG14(0), .val = 0x000000E6},
{ .reg =DDRC_DRAMTMG17(0), .val = 0x00A00050},
{ .reg =DDRC_ZQCTL0(0), .val = 0x03200018},
{ .reg =DDRC_ZQCTL1(0), .val = 0x028061A8},
{ .reg =DDRC_ZQCTL2(0), .val = 0x00000000},
{ .reg =DDRC_DFITMG0(0), .val = 0x0497820A},
{ .reg =DDRC_DFITMG1(0), .val = 0x00080303},
{ .reg =DDRC_DFIUPD0(0), .val = 0xE0400018},
{ .reg =DDRC_DFIUPD1(0), .val = 0x00DF00E4},
{ .reg =DDRC_DFIUPD2(0), .val = 0x80000000},
{ .reg =DDRC_DFIMISC(0), .val = 0x00000011},
{ .reg =DDRC_DFITMG2(0), .val = 0x0000170A},
{ .reg =DDRC_DBICTL(0), .val = 0x00000001},
#ifdef BUG_WR_DFI
{ .reg =DDRC_DFIPHYMSTR(0), .val = 0x00000000},
#else
{ .reg =DDRC_DFIPHYMSTR(0), .val = 0x00000001},
#endif
{ .reg =DDRC_RANKCTL(0), .val = 0x00000c99},
{ .reg =DDRC_DRAMTMG2(0), .val = 0x070E171a},
#ifdef M845S_4GBx2
#ifdef DDR_ONE_RANK
{ .reg =DDRC_ADDRMAP0(0), .val = 0x0000001f},
#else
{ .reg =DDRC_ADDRMAP0(0), .val = 0x00000017},
#endif
{ .reg =DDRC_ADDRMAP1(0), .val = 0x00080808},
{ .reg =DDRC_ADDRMAP2(0), .val = 0x00000000},
{ .reg =DDRC_ADDRMAP3(0), .val = 0x00000000},
{ .reg =DDRC_ADDRMAP4(0), .val = 0x00001f1f},
{ .reg =DDRC_ADDRMAP5(0), .val = 0x07070707},
{ .reg =DDRC_ADDRMAP6(0), .val = 0x07070707},
{ .reg =DDRC_ADDRMAP7(0), .val = 0x00000f0f},
#else
#ifdef DDR_ONE_RANK
{ .reg =DDRC_ADDRMAP0(0), .val = 0x0000001f},
#else
{ .reg =DDRC_ADDRMAP0(0), .val = 0x00000016},
#endif
{ .reg =DDRC_ADDRMAP1(0), .val = 0x00080808},
{ .reg =DDRC_ADDRMAP2(0), .val = 0x00000000},
{ .reg =DDRC_ADDRMAP3(0), .val = 0x00000000},
{ .reg =DDRC_ADDRMAP4(0), .val = 0x00001f1f},
{ .reg =DDRC_ADDRMAP5(0), .val = 0x07070707},
{ .reg =DDRC_ADDRMAP6(0), .val = 0x0f070707},
{ .reg =DDRC_ADDRMAP7(0), .val = 0x00000f0f},
{ .reg =DDRC_ADDRMAP8(0), .val = 0x00000000},
{ .reg =DDRC_ADDRMAP9(0), .val = 0x0a020b06},
{ .reg =DDRC_ADDRMAP10(0), .val = 0x0a0a0a0a},
{ .reg =DDRC_ADDRMAP11(0), .val = 0x00000000},
#endif
#ifdef PERF_TEST_2
{ .reg =DDRC_SCHED(0), .val = 0x29001701},
{ .reg =DDRC_SCHED1(0), .val = 0x0000002c},
{ .reg =DDRC_PERFLPR1(0), .val = 0x900093e7},
{ .reg =DDRC_PCCFG(0), .val = 0x00000111},
{ .reg =DDRC_PCFGW_0(0), .val = 0x000072ff},
{ .reg =DDRC_PCFGQOS0_0(0), .val = 0x02100e07},
{ .reg =DDRC_PCFGQOS1_0(0), .val = 0x00620096},
{ .reg =DDRC_PCFGWQOS0_0(0), .val = 0x01100e07},
{ .reg =DDRC_PCFGWQOS1_0(0), .val = 0x0000012c},
#else
{ .reg =DDRC_SCHED(0), .val = 0x29001701},
{ .reg =DDRC_SCHED1(0), .val = 0x0000002c},
{ .reg =DDRC_PERFHPR1(0), .val = 0x04000030},
{ .reg =DDRC_PERFLPR1(0), .val = 0x900093e7},
{ .reg =DDRC_PCCFG(0), .val = 0x00000111},
{ .reg =DDRC_PCFGW_0(0), .val = 0x000072ff},
{ .reg =DDRC_PCFGQOS0_0(0), .val = 0x02100e07},
{ .reg =DDRC_PCFGQOS1_0(0), .val = 0x00620096},
{ .reg =DDRC_PCFGWQOS0_0(0), .val = 0x01100e07},
{ .reg =DDRC_PCFGWQOS1_0(0), .val = 0x0000012c},
#endif
#ifdef P1_400
{ .reg =DDRC_FREQ1_DRAMTMG0(0), .val = 0x0d0b010c},
{ .reg =DDRC_FREQ1_DRAMTMG1(0), .val = 0x00030410},
{ .reg =DDRC_FREQ1_DRAMTMG2(0), .val = 0x0305090c},
{ .reg =DDRC_FREQ1_DRAMTMG3(0), .val = 0x00505006},
{ .reg =DDRC_FREQ1_DRAMTMG4(0), .val = 0x05040305},
{ .reg =DDRC_FREQ1_DRAMTMG5(0), .val = 0x0d0e0504},
{ .reg =DDRC_FREQ1_DRAMTMG6(0), .val = 0x0a060004},
{ .reg =DDRC_FREQ1_DRAMTMG7(0), .val = 0x0000090e},
{ .reg =DDRC_FREQ1_DRAMTMG14(0), .val = 0x00000032},
{ .reg =DDRC_FREQ1_DRAMTMG15(0), .val = 0x00000000},
{ .reg =DDRC_FREQ1_DRAMTMG17(0), .val = 0x0036001b},
{ .reg =DDRC_FREQ1_DERATEINT(0), .val = 0x7e9fbeb1},
{ .reg =DDRC_FREQ1_DFITMG0(0), .val = 0x03818200},
{ .reg =DDRC_FREQ1_DFITMG2(0), .val = 0x00000000},
{ .reg =DDRC_FREQ1_RFSHTMG(0), .val = 0x000C001c},
{ .reg =DDRC_FREQ1_INIT3(0), .val = 0x00840000},
{ .reg =DDRC_FREQ1_INIT4(0), .val = 0x00310000},
{ .reg =DDRC_FREQ1_INIT6(0), .val = 0x0066004a},
{ .reg =DDRC_FREQ1_INIT7(0), .val = 0x0006004a},
#else
#ifdef WEI_667
{ .reg =DDRC_FREQ1_DRAMTMG0(0), .val = 0x0d0b0107},
{ .reg =DDRC_FREQ1_DRAMTMG1(0), .val = 0x00030410},
{ .reg =DDRC_FREQ1_DRAMTMG2(0), .val = 0x0305080c},
{ .reg =DDRC_FREQ1_DRAMTMG3(0), .val = 0x00505006},
{ .reg =DDRC_FREQ1_DRAMTMG4(0), .val = 0x05040305},
{ .reg =DDRC_FREQ1_DRAMTMG5(0), .val = 0x0f0b0504},
{ .reg =DDRC_FREQ1_DRAMTMG6(0), .val = 0x0e0c000c},
{ .reg =DDRC_FREQ1_DRAMTMG7(0), .val = 0x00000607},
{ .reg =DDRC_FREQ1_DRAMTMG14(0), .val = 0x00000066},
{ .reg =DDRC_FREQ1_DRAMTMG15(0), .val = 0x80000000},
{ .reg =DDRC_FREQ1_DRAMTMG17(0), .val = 0x0036001b},
{ .reg =DDRC_FREQ1_DFITMG0(0), .val = 0x03858202},
{ .reg =DDRC_FREQ1_DFITMG2(0), .val = 0x00000502},
{ .reg =DDRC_FREQ1_DERATEEN(0), .val = 0x00000001},
{ .reg =DDRC_FREQ1_DERATEINT(0), .val = 0x2545eb1c},
{ .reg =DDRC_FREQ1_RFSHTMG(0), .val = 0x0014002f},
{ .reg =DDRC_FREQ1_INIT3(0), .val = 0x00140009},
{ .reg =DDRC_FREQ1_INIT4(0), .val = 0x00310000},
{ .reg =DDRC_FREQ1_INIT6(0), .val = 0x0066004d},
{ .reg =DDRC_FREQ1_INIT7(0), .val = 0x0006004d},
#else
{ .reg =DDRC_FREQ1_DERATEEN(0), .val = 0x0000000},
{ .reg =DDRC_FREQ1_DERATEINT(0), .val = 0x0800000},
{ .reg =DDRC_FREQ1_RFSHCTL0(0), .val = 0x0210000},
{ .reg =DDRC_FREQ1_RFSHTMG(0), .val = 0x014001E},
{ .reg =DDRC_FREQ1_INIT3(0), .val = 0x0140009},
{ .reg =DDRC_FREQ1_INIT4(0), .val = 0x00310000},
{ .reg =DDRC_FREQ1_INIT6(0), .val = 0x0066004a},
{ .reg =DDRC_FREQ1_INIT7(0), .val = 0x0006004a},
{ .reg =DDRC_FREQ1_DRAMTMG0(0), .val = 0xB070A07},
{ .reg =DDRC_FREQ1_DRAMTMG1(0), .val = 0x003040A},
{ .reg =DDRC_FREQ1_DRAMTMG2(0), .val = 0x305080C},
{ .reg =DDRC_FREQ1_DRAMTMG3(0), .val = 0x0505000},
{ .reg =DDRC_FREQ1_DRAMTMG4(0), .val = 0x3040203},
{ .reg =DDRC_FREQ1_DRAMTMG5(0), .val = 0x2030303},
{ .reg =DDRC_FREQ1_DRAMTMG6(0), .val = 0x2020004},
{ .reg =DDRC_FREQ1_DRAMTMG7(0), .val = 0x0000302},
{ .reg =DDRC_FREQ1_DRAMTMG12(0), .val = 0x0020310},
{ .reg =DDRC_FREQ1_DRAMTMG13(0), .val = 0xA100002},
{ .reg =DDRC_FREQ1_DRAMTMG14(0), .val = 0x0000020},
{ .reg =DDRC_FREQ1_DRAMTMG17(0), .val = 0x0220011},
{ .reg =DDRC_FREQ1_ZQCTL0(0), .val = 0x0A70005},
{ .reg =DDRC_FREQ1_DFITMG0(0), .val = 0x3858202},
{ .reg =DDRC_FREQ1_DFITMG1(0), .val = 0x0000404},
{ .reg =DDRC_FREQ1_DFITMG2(0), .val = 0x0000502},
#endif
#endif
{ .reg =DDRC_FREQ2_DRAMTMG0(0), .val = 0x0d0b010c},
{ .reg =DDRC_FREQ2_DRAMTMG1(0), .val = 0x00030410},
{ .reg =DDRC_FREQ2_DRAMTMG2(0), .val = 0x0305090c},
{ .reg =DDRC_FREQ2_DRAMTMG3(0), .val = 0x00505006},
{ .reg =DDRC_FREQ2_DRAMTMG4(0), .val = 0x05040305},
{ .reg =DDRC_FREQ2_DRAMTMG5(0), .val = 0x0d0e0504},
{ .reg =DDRC_FREQ2_DRAMTMG6(0), .val = 0x0a060004},
{ .reg =DDRC_FREQ2_DRAMTMG7(0), .val = 0x0000090e},
{ .reg =DDRC_FREQ2_DRAMTMG14(0), .val = 0x00000032},
{ .reg =DDRC_FREQ2_DRAMTMG17(0), .val = 0x0036001b},
{ .reg =DDRC_FREQ2_DERATEINT(0), .val = 0x7e9fbeb1},
{ .reg =DDRC_FREQ2_DFITMG0(0), .val = 0x03818200},
{ .reg =DDRC_FREQ2_DFITMG2(0), .val = 0x00000000},
{ .reg =DDRC_FREQ2_RFSHTMG(0), .val = 0x00030007},
{ .reg =DDRC_FREQ2_INIT3(0), .val = 0x00840000},
{ .reg =DDRC_FREQ2_INIT4(0), .val = 0x00310000},
{ .reg =DDRC_FREQ2_INIT6(0), .val = 0x0066004a},
{ .reg =DDRC_FREQ2_INIT7(0), .val = 0x0006004a},
#ifdef DDR_BOOT_P2
{ .reg =DDRC_MSTR2(0), .val = 0x2},
#else
#ifdef DDR_BOOT_P1
{ .reg =DDRC_MSTR2(0), .val = 0x1},
#else
{ .reg =DDRC_MSTR2(0), .val = 0x0},
#endif
#endif
};
void lpddr4_3000mts_cfg_umctl2(void)
{
u32 index, reg, val, num;
num = sizeof(ctl_init_cfg)/sizeof(struct ddr_ctl_param);
for (index = 0; index < num; index++) {
val = ctl_init_cfg[index].val;
reg = ctl_init_cfg[index].reg;
writel(val, (void __iomem *)(u64)reg);
}
}
/*
* Copyright 2018 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef LPDDR4_DEFINE_H
#define LPDDR4_DEFINE_H
#include "ddr.h"
#define RUN_ON_SILICON
#define DFI_BUG_WR
#define DEVINIT_PHY
#define DDR_ONE_RANK
#define BUG_WR_DFI
#define M845S_4GBx2
#ifdef LPDDR4_667MTS
#define P0_667
#endif
#ifdef LPDDR4_1600MTS
#define P0_1600
#endif
#ifdef LPDDR4_DVFS
#define DVFS_TEST
#define PHY_TRAIN
#define DDR_BOOT_P1
#endif
#ifdef LPDDR4_RETENTION
#define NORMAL_RET_EN
#endif
#ifdef P0_667
#define P0_DRATE 667
#else
#ifdef P0_1600
#define P0_DRATE 1600
#else
#define P0_DRATE 3000
#endif
#endif
#define P1_DRATE 667
#define P2_DRATE 100
#ifdef RUN_ON_SILICON
#define PHY_TRAIN
#define ADD_P0_2D_BF_P1
#ifdef HWFFC
#define ADD_TRAIN_1D_P2
#endif
#else
#define DDR_FAST_SIM
#endif
#ifdef PHY_TRAIN
#define ADD_TRAIN_1D_P0
#ifdef DVFS_TEST
#define ADD_TRAIN_1D_P1
#endif
#endif
/* define BOOT FREQ, not modify */
#ifdef DDR_BOOT_P1
#define BOOT_FREQ P1_DRATE
#else
#ifdef DDR_BOOT_P2
#define BOOT_FREQ P2_DRATE
#else
#define BOOT_FREQ P0_DRATE
#endif
#endif
/* #define P1_FREQ 167 */
#ifdef PHY_TRAIN
#define CLOCK_SWITCH_PLL P0_DRATE
#else
#define CLOCK_SWITCH_PLL BOOT_FREQ
#endif
#define DDR_CSD2_BASE_ADDR 0x80000000
#define GPC_PU_PWRHSK 0x303A01FC
//----------------------------------------------------------------
// PHY training feature
//----------------------------------------------------------------
#define LPDDR4_HDT_CTL_2D 0xC8 //stage completion
#define LPDDR4_HDT_CTL_3200_1D 0xC8 //stage completion
#define LPDDR4_HDT_CTL_400_1D 0xC8 //stage completion
#define LPDDR4_HDT_CTL_100_1D 0xC8 //stage completion
#define LPDDR4_HDT_CTL_2D 0xC8 //stage completion
#define LPDDR4_HDT_CTL_3200_1D 0xC8 //stage completion
#define LPDDR4_HDT_CTL_400_1D 0xC8 //stage completion
#define LPDDR4_HDT_CTL_100_1D 0xC8 //stage completion
#ifdef RUN_ON_SILICON
// 400/100 training seq
#define LPDDR4_TRAIN_SEQ_P2 0x121f
#define LPDDR4_TRAIN_SEQ_P1 0x121f
#define LPDDR4_TRAIN_SEQ_P0 0x121f
#else
#define LPDDR4_TRAIN_SEQ_P2 0x7
#define LPDDR4_TRAIN_SEQ_P1 0x7
#define LPDDR4_TRAIN_SEQ_P0 0x7
#endif
//2D share & weight
#define LPDDR4_2D_WEIGHT 0x1f7f
#define LPDDR4_2D_SHARE 1
#define LPDDR4_CATRAIN_3200_1d 0
#define LPDDR4_CATRAIN_400 0
#define LPDDR4_CATRAIN_100 0
#define LPDDR4_CATRAIN_3200_2d 0
/* MRS parameter */
/* for LPDDR4 Rtt */
#define LPDDR4_RTT40 6
#define LPDDR4_RTT48 5
#define LPDDR4_RTT60 4
#define LPDDR4_RTT80 3
#define LPDDR4_RTT120 2
#define LPDDR4_RTT240 1
#define LPDDR4_RTT_DIS 0
/* for LPDDR4 Ron */
#define LPDDR4_RON34 7
#define LPDDR4_RON40 6
#define LPDDR4_RON48 5
#define LPDDR4_RON60 4
#define LPDDR4_RON80 3
#define LPDDR4_PHY_ADDR_RON60 0x1
#define LPDDR4_PHY_ADDR_RON40 0x3
#define LPDDR4_PHY_ADDR_RON30 0x7
#define LPDDR4_PHY_ADDR_RON24 0xf
#define LPDDR4_PHY_ADDR_RON20 0x1f
/* for read channel */
#define LPDDR4_RON LPDDR4_RON40 /* MR3[5:3] */
#define LPDDR4_PHY_RTT 30 /* //30//40//28 */
/* #define LPDDR4_PHY_VREF_VALUE 27//17//17//20//16///17,//for M845S */
#define LPDDR4_PHY_VREF_VALUE 17 /*//17//20//16///17,//for M850D*/
/* for write channel */
#define LPDDR4_PHY_RON 30
#define LPDDR4_PHY_ADDR_RON LPDDR4_PHY_ADDR_RON40
#define LPDDR4_RTT_DQ LPDDR4_RTT40
#define LPDDR4_RTT_CA LPDDR4_RTT40
#define LPDDR4_RTT_CA_BANK0 LPDDR4_RTT40
#define LPDDR4_RTT_CA_BANK1 LPDDR4_RTT40
#define LPDDR4_VREF_VALUE_CA ((1 << 6)|0xd)
#define LPDDR4_VREF_VALUE_DQ_RANK0 ((1 << 6)|0xd)
#define LPDDR4_VREF_VALUE_DQ_RANK1 ((1 << 6)|0xd)
#define LPDDR4_MR22_RANK0 ((0 << 5)|(0 << 4)|(0 << 3)|(LPDDR4_RTT40))
#define LPDDR4_MR22_RANK1 ((1 << 5)|(0 << 4)|(1 << 3)|(LPDDR4_RTT40))
#define LPDDR4_MR3_PU_CAL 1
#endif
/*
* Copyright 2018 NXP
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <errno.h>
#include <asm/io.h>
#include <asm/arch/ddr_memory_map.h>
#include <asm/arch/clock.h>
#include "lpddr4_define.h"
void dwc_ddrphy_phyinit_userCustom_E_setDfiClk(int pstate)
{
if(pstate==2)
dram_pll_init(DRAM_PLL_OUT_100M);
else if(pstate==1)
dram_pll_init(DRAM_PLL_OUT_667M);
else
dram_pll_init(DRAM_PLL_OUT_750M);
}
int dwc_ddrphy_phyinit_userCustom_G_waitFwDone(void)
{
volatile unsigned int tmp, tmp_t;
volatile unsigned int train_ok;
volatile unsigned int train_fail;
volatile unsigned int stream_msg;
int ret = 0;
train_ok = 0;
train_fail = 0;
stream_msg = 0;
while (train_ok == 0 && train_fail == 0) {
tmp = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0004);
tmp_t = tmp & 0x01;
while (tmp_t){
tmp = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0004);
tmp_t = tmp & 0x01;
}
#ifdef PRINT_PMU
printf("get the training message\n");
#endif
tmp = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0032);
#ifdef PRINT_PMU
printf("PMU major stream =0x%x\n",tmp);
#endif
if (tmp==0x08) {
stream_msg = 1;
#ifdef DDR_PRINT_ALL_MESSAGE
reg32_write(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0031, 0x0);
do {
tmp_t = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0004);
}while((tmp_t & 0x1) == 0x0);
reg32_write(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0031, 0x1);
do {
tmp_t = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0004);
}while((tmp_t & 0x1) == 0x1);
/* read_mbox_mssg */
stream_nb_args = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) +4 * 0xd0032);
/* read_mbox_msb */
stream_index = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 4 * 0xd0034);
stream_index = (stream_index << 16) | stream_nb_args;
#ifdef PRINT_PMU
printf("PMU stream_index=0x%x nb_args=%d\n",stream_index, stream_nb_args);
#endif
<