hsin-hsiung wang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/35147 )
Change subject: mediatek/mt8183: Allow modifying vdram2 voltage ......................................................................
mediatek/mt8183: Allow modifying vdram2 voltage
DRAM DVFS needs to be calibrated with different vdram2 voltages to get correct parameters. A new API is added to allow changing vdram2 voltage.
BUG=b:80501386 BRANCH=none TEST=measure vdram2 voltage with multimeter
Change-Id: I5f0d82596a1709bf0d37885f257646133f18f210 Signed-off-by: Hsin-Hsiung Wang hsin-hsiung.wang@mediatek.com --- M src/soc/mediatek/mt8183/include/soc/mt6358.h M src/soc/mediatek/mt8183/mt6358.c 2 files changed, 99 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/47/35147/1
diff --git a/src/soc/mediatek/mt8183/include/soc/mt6358.h b/src/soc/mediatek/mt8183/include/soc/mt6358.h index 6ed654c..9d689b0 100644 --- a/src/soc/mediatek/mt8183/include/soc/mt6358.h +++ b/src/soc/mediatek/mt8183/include/soc/mt6358.h @@ -19,9 +19,18 @@ enum { PMIC_SWCID = 0x000a, PMIC_VM_MODE = 0x004e, + PMIC_TOP_CKPDN_CON0_SET = 0x010e, + PMIC_TOP_CKPDN_CON0_CLR = 0x0110, + PMIC_TOP_CKHWEN_CON0_SET = 0x012c, + PMIC_TOP_CKHWEN_CON0_CLR = 0x012e, PMIC_TOP_RST_MISC = 0x014c, PMIC_TOP_RST_MISC_SET = 0x014e, PMIC_TOP_RST_MISC_CLR = 0x0150, + PMIC_OTP_CON0 = 0x038a, + PMIC_OTP_CON8 = 0x039a, + PMIC_OTP_CON11 = 0x03a0, + PMIC_OTP_CON12 = 0x03a2, + PMIC_OTP_CON13 = 0x03a4, PMIC_TOP_TMA_KEY = 0x03a8, PMIC_PWRHOLD = 0x0a08, PMIC_CPSDSA4 = 0x0a2e, @@ -33,7 +42,9 @@ PMIC_VDRAM1_DBG0 = 0x161e, PMIC_VDRAM1_VOSEL = 0x1626, PMIC_SMPS_ANA_CON0 = 0x1808, + PMIC_VDRAM2_OP_EN = 0x1b16, PMIC_VSIM2_ANA_CON0 = 0x1e30, + PMIC_VDRAM2_ELR_0 = 0x1ec4, };
struct pmic_setting { @@ -51,5 +62,7 @@ void pmic_set_vcore_vol(unsigned int vcore_uv); unsigned int pmic_get_vdram1_vol(void); void pmic_set_vdram1_vol(unsigned int vdram_uv); +unsigned int pmic_get_vdram2_vol(void); +void pmic_set_vdram2_vol(unsigned int vdram2_uv);
#endif /* __SOC_MEDIATEK_MT6358_H__ */ diff --git a/src/soc/mediatek/mt8183/mt6358.c b/src/soc/mediatek/mt8183/mt6358.c index 703de81..f389219 100644 --- a/src/soc/mediatek/mt8183/mt6358.c +++ b/src/soc/mediatek/mt8183/mt6358.c @@ -15,6 +15,7 @@
#include <assert.h> #include <console/console.h> +#include <delay.h> #include <soc/pmic_wrap.h> #include <soc/mt6358.h> #include <timer.h> @@ -752,6 +753,45 @@ /* [4:4]: RG_SRCVOLTEN_LP_EN */ {0x134, 0x1, 0x1, 4}, }; +static const int vdram2_votrim[] = { + 0, (-1)*10000, (-1)*20000, (-1)*30000, (-1)*40000, (-1)*50000, (-1)*60000, + (-1)*70000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, +}; + +static unsigned int pmic_read_efuse(int i) +{ + unsigned int efuse_data = 0; + + /* 1. enable efuse ctrl engine clock */ + pwrap_write_field(PMIC_TOP_CKHWEN_CON0_CLR, 0x1, 0x1, 2); + pwrap_write_field(PMIC_TOP_CKPDN_CON0_CLR, 0x1, 0x1, 4); + + /* 2. */ + pwrap_write_field(PMIC_OTP_CON11, 0x1, 0x1, 0); + + /* 3. Set row to read */ + pwrap_write_field(PMIC_OTP_CON0, i * 2, 0xFF, 0); + + /* 4. Toggle RG_OTP_RD_TRIG */ + if (pwrap_read_field(PMIC_OTP_CON8, 0x1, 0) == 0) + pwrap_write_field(PMIC_OTP_CON8, 0x1, 0x1, 0); + else + pwrap_write_field(PMIC_OTP_CON8, 0, 0x1, 0); + + /* 5. Polling RG_OTP_RD_BUSY = 0 */ + udelay(300); + while (pwrap_read_field(PMIC_OTP_CON13, 0x1, 0) == 1) + ; + /* 6. Read RG_OTP_DOUT_SW */ + udelay(100); + efuse_data = pwrap_read_field(PMIC_OTP_CON12, 0xFFFF, 0); + /* 7. disable efuse ctrl engine clock */ + pwrap_write_field(PMIC_TOP_CKHWEN_CON0_SET, 0x1, 0x1, 2); + pwrap_write_field(PMIC_TOP_CKPDN_CON0_SET, 0x1, 0x1, 4); + + return efuse_data; +} + void pmic_set_power_hold(bool enable) { pwrap_write_field(PMIC_PWRHOLD, (enable) ? 1 : 0, 0x1, 0); @@ -851,6 +891,52 @@ pwrap_write_field(PMIC_VDRAM1_VOSEL, vol_reg, 0x7F, 0); }
+unsigned int pmic_get_vdram2_vol(void) +{ + unsigned int cali_trim, cali_efuse; + + if (!pwrap_read_field(PMIC_VDRAM2_OP_EN, 0x1, 15)) + return 0; + + cali_efuse = pmic_read_efuse(104) & 0xF; + cali_trim = pwrap_read_field(PMIC_VDRAM2_ELR_0, 0xF, 0); + return (600 * 1000 - vdram2_votrim[cali_efuse] + vdram2_votrim[cali_trim]); +} + +void pmic_set_vdram2_vol(unsigned int vdram2_uv) +{ + int dram2_ori_mv, cali_efuse, cali_offset_mv, cali_trim, target_mv; + + if (vdram2_uv > 680000) { + assert(0); + return; + } if (vdram2_uv < 530000) { + assert(0); + return; + } + + target_mv = vdram2_uv / 1000 / 10; + target_mv = target_mv * 10; + + cali_efuse = pmic_read_efuse(104) & 0xF; + dram2_ori_mv = 600 - vdram2_votrim[cali_efuse] / 1000; + + if (target_mv >= (dram2_ori_mv + 80)) + cali_trim = 8; + else if ((dram2_ori_mv - 70) >= target_mv) + cali_trim = 7; + else { + cali_trim = 0; + cali_offset_mv = 1000 * (target_mv - dram2_ori_mv); + while ((cali_trim < 15) && (vdram2_votrim[cali_trim] != cali_offset_mv)) ++cali_trim; + } + + pwrap_write_field(PMIC_TOP_TMA_KEY, 0x9CA7, 0xFFFF, 0); + pwrap_write_field(PMIC_VDRAM2_ELR_0, cali_trim, 0xF, 0); + pwrap_write_field(PMIC_TOP_TMA_KEY, 0, 0xFFFF, 0); + udelay(1); +} + static void pmic_wdt_set(void) { /* [5]=1, RG_WDTRSTB_DEB */