JG Poxu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/32800
Change subject: mt8183: add efuse calibration in auxadc ......................................................................
mt8183: add efuse calibration in auxadc
due to not get efuse calibration, auxadc get value has deviated
Change-Id: Iccd6ea0ad810c993f9b62c0974279c960f890e52 Signed-off-by: jg_poxu jg_poxu@mediatek.com --- M src/soc/mediatek/mt8183/auxadc.c M src/soc/mediatek/mt8183/include/soc/addressmap.h A src/soc/mediatek/mt8183/include/soc/efuse.h 3 files changed, 66 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/00/32800/1
diff --git a/src/soc/mediatek/mt8183/auxadc.c b/src/soc/mediatek/mt8183/auxadc.c old mode 100644 new mode 100755 index a167d2b..408f911 --- a/src/soc/mediatek/mt8183/auxadc.c +++ b/src/soc/mediatek/mt8183/auxadc.c @@ -18,11 +18,43 @@ #include <delay.h> #include <soc/addressmap.h> #include <soc/auxadc.h> +#include <soc/efuse.h> #include <soc/infracfg.h> #include <timer.h>
static struct mtk_auxadc_regs *const mtk_auxadc = (void *)AUXADC_BASE; +/* For calibration EFUSE: + * 1. ADC_GE_A[9:0] *(0x11F101B4)[19:10] Default:512 + * 2. ADC_OE_A[9:0] *(0x11F101B4)[9:0] Default:512 + * 3. ADC_CALI_EN_A(1b) *(0x11F101B4)[20] + */ +#define ADC_GE_A_SHIFT 10 +#define ADC_GE_A_MASK (0x3ff << ADC_GE_A_SHIFT) +#define ADC_OE_A_SHIFT 0 +#define ADC_OE_A_MASK (0x3ff << ADC_OE_A_SHIFT) +#define ADC_CALI_EN_A_SHIFT 20 +#define ADC_CALI_EN_A_MASK (0x1 << ADC_CALI_EN_A_SHIFT) +#define AUXADC_CALI_INIT ~((uint32_t)1)
+static int cali_oe = AUXADC_CALI_INIT; +static int cali_ge = AUXADC_CALI_INIT; + +static void mt_auxadc_update_cali(void) +{ + int cali_reg; + int cali_ge_a; + int cali_oe_a; + + cali_reg = read32(&mtk_efuse->adc_cali_reg); + + if ((cali_reg & ADC_CALI_EN_A_MASK) != 0) { + cali_oe_a = (cali_reg & ADC_OE_A_MASK) >> ADC_OE_A_SHIFT; + cali_ge_a = ((cali_reg & ADC_GE_A_MASK) >> ADC_GE_A_SHIFT); + /*In sw implement guide, ge should div 4096. But we don't do that now due to it will multi 4096 later*/ + cali_ge = cali_ge_a - 512; + cali_oe = cali_oe_a - 512; + } +} static uint32_t auxadc_get_rawdata(int channel) { setbits_le32(&mt8183_infracfg->module_sw_cg_1_clr, 1 << 10); @@ -47,5 +79,8 @@ assert(channel < 16);
/* 1.5V in 4096 steps */ - return (int)((int64_t)auxadc_get_rawdata(channel) * 1500000 / 4096); + rawvalue = auxadc_get_rawdata(channel); + + rawvalue = rawvalue - cali_oe; + return (int)((int64_t)rawvalue * 1500000 / (4096 + cali_ge)); } diff --git a/src/soc/mediatek/mt8183/include/soc/addressmap.h b/src/soc/mediatek/mt8183/include/soc/addressmap.h old mode 100644 new mode 100755 index d41b2b9..e9f80d1 --- a/src/soc/mediatek/mt8183/include/soc/addressmap.h +++ b/src/soc/mediatek/mt8183/include/soc/addressmap.h @@ -50,6 +50,7 @@ IOCFG_LB_BASE = IO_PHYS + 0x01E70000, IOCFG_LM_BASE = IO_PHYS + 0x01E80000, IOCFG_BL_BASE = IO_PHYS + 0x01E90000, + EFUSEC_BASE = IO_PHYS + 0x01F10000, IOCFG_LT_BASE = IO_PHYS + 0x01F20000, IOCFG_TL_BASE = IO_PHYS + 0x01F30000, SSUSB_SIF_BASE = IO_PHYS + 0x01F40300, diff --git a/src/soc/mediatek/mt8183/include/soc/efuse.h b/src/soc/mediatek/mt8183/include/soc/efuse.h new file mode 100644 index 0000000..2705497 --- /dev/null +++ b/src/soc/mediatek/mt8183/include/soc/efuse.h @@ -0,0 +1,29 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2018 MediaTek Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _MTK_EFUSE_H +#define _MTK_EFUSE_H + +#include <stdint.h> + +struct efuse_regs { + uint32_t rserved[109]; + uint32_t adc_cali_reg; +}; + +check_member(efuse_regs, adc_cali_reg, 0x1b4); +static struct efuse_regs *const mtk_efuse = (void *)EFUSEC_BASE; + +#endif