soc/mediatek: Move auxadc driver from MT8183 to common
The auxadc (auxiliary analogue-to-digital conversion) is a unit to identify the plugged peripherals or measure the temperature or voltages. The MT8183 auxadc driver can be shared by multiple MediaTek SoCs so we should move it to the common folder. Signed-off-by: Po Xu <jg_poxu@mediatek.com> Change-Id: Id4553e99c3578fa40e28b19a6e010b52650ba41e Reviewed-on: https://review.coreboot.org/c/coreboot/+/46390 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org>
This commit is contained in:
parent
0fd62f5b79
commit
3f11803075
|
@ -13,7 +13,7 @@
|
||||||
#include <device/i2c_simple.h>
|
#include <device/i2c_simple.h>
|
||||||
#include <drivers/camera/cros_camera.h>
|
#include <drivers/camera/cros_camera.h>
|
||||||
#include <ec/google/chromeec/ec.h>
|
#include <ec/google/chromeec/ec.h>
|
||||||
#include <soc/auxadc.h>
|
#include <soc/auxadc_common.h>
|
||||||
#include <soc/i2c.h>
|
#include <soc/i2c.h>
|
||||||
#include <soc/pmic_wrap_common.h>
|
#include <soc/pmic_wrap_common.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -69,7 +69,7 @@ static const int *adc_voltages[] = {
|
||||||
|
|
||||||
static uint32_t get_adc_index(unsigned int channel)
|
static uint32_t get_adc_index(unsigned int channel)
|
||||||
{
|
{
|
||||||
int value = auxadc_get_voltage(channel);
|
int value = auxadc_get_voltage_uv(channel);
|
||||||
|
|
||||||
assert(channel < ARRAY_SIZE(adc_voltages));
|
assert(channel < ARRAY_SIZE(adc_voltages));
|
||||||
const int *voltages = adc_voltages[channel];
|
const int *voltages = adc_voltages[channel];
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
#include <device/mmio.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <delay.h>
|
#include <delay.h>
|
||||||
|
#include <device/mmio.h>
|
||||||
#include <soc/addressmap.h>
|
#include <soc/addressmap.h>
|
||||||
#include <soc/auxadc.h>
|
#include <soc/auxadc.h>
|
||||||
#include <soc/efuse.h>
|
#include <soc/efuse.h>
|
||||||
#include <soc/infracfg.h>
|
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
|
|
||||||
static struct mtk_auxadc_regs *const mtk_auxadc = (void *)AUXADC_BASE;
|
static struct mtk_auxadc_regs *const mtk_auxadc = (void *)AUXADC_BASE;
|
||||||
|
@ -36,9 +35,10 @@ static void mt_auxadc_update_cali(void)
|
||||||
cali_oe = cali_oe_a - 512;
|
cali_oe = cali_oe_a - 512;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t auxadc_get_rawdata(int channel)
|
static uint32_t auxadc_get_rawdata(int channel)
|
||||||
{
|
{
|
||||||
setbits32(&mt8183_infracfg->module_sw_cg_1_clr, 1 << 10);
|
setbits32(&mtk_infracfg->module_sw_cg_1_clr, 1 << 10);
|
||||||
assert(wait_ms(300, !(read32(&mtk_auxadc->con2) & 0x1)));
|
assert(wait_ms(300, !(read32(&mtk_auxadc->con2) & 0x1)));
|
||||||
|
|
||||||
clrbits32(&mtk_auxadc->con1, 1 << channel);
|
clrbits32(&mtk_auxadc->con1, 1 << channel);
|
||||||
|
@ -50,12 +50,12 @@ static uint32_t auxadc_get_rawdata(int channel)
|
||||||
|
|
||||||
uint32_t value = read32(&mtk_auxadc->data[channel]) & 0x0FFF;
|
uint32_t value = read32(&mtk_auxadc->data[channel]) & 0x0FFF;
|
||||||
|
|
||||||
setbits32(&mt8183_infracfg->module_sw_cg_1_set, 1 << 10);
|
setbits32(&mtk_infracfg->module_sw_cg_1_set, 1 << 10);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int auxadc_get_voltage(unsigned int channel)
|
unsigned int auxadc_get_voltage_uv(unsigned int channel)
|
||||||
{
|
{
|
||||||
uint32_t raw_value;
|
uint32_t raw_value;
|
||||||
assert(channel < 16);
|
assert(channel < 16);
|
||||||
|
@ -67,7 +67,6 @@ int auxadc_get_voltage(unsigned int channel)
|
||||||
|
|
||||||
/* 1.5V in 4096 steps */
|
/* 1.5V in 4096 steps */
|
||||||
raw_value = auxadc_get_rawdata(channel);
|
raw_value = auxadc_get_rawdata(channel);
|
||||||
|
|
||||||
raw_value = raw_value - cali_oe;
|
raw_value = raw_value - cali_oe;
|
||||||
return (int)((int64_t)raw_value * 1500000 / (4096 + cali_ge));
|
return (unsigned int)((int64_t)raw_value * 1500000 / (4096 + cali_ge));
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#ifndef _MTK_ADC_COMMON_H
|
||||||
|
#define _MTK_ADC_COMMON_H
|
||||||
|
|
||||||
|
/* Return voltage in uVolt */
|
||||||
|
unsigned int auxadc_get_voltage_uv(unsigned int channel);
|
||||||
|
#endif
|
|
@ -1,7 +1,7 @@
|
||||||
ifeq ($(CONFIG_SOC_MEDIATEK_MT8183),y)
|
ifeq ($(CONFIG_SOC_MEDIATEK_MT8183),y)
|
||||||
|
|
||||||
bootblock-y += auxadc.c
|
|
||||||
bootblock-y += bootblock.c
|
bootblock-y += bootblock.c
|
||||||
|
bootblock-y += ../common/auxadc.c
|
||||||
bootblock-y += ../common/gpio.c gpio.c
|
bootblock-y += ../common/gpio.c gpio.c
|
||||||
bootblock-y += ../common/pll.c pll.c
|
bootblock-y += ../common/pll.c pll.c
|
||||||
bootblock-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
bootblock-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
||||||
|
@ -15,7 +15,7 @@ decompressor-y += decompressor.c
|
||||||
decompressor-y += ../common/mmu_operations.c
|
decompressor-y += ../common/mmu_operations.c
|
||||||
decompressor-y += ../common/timer.c
|
decompressor-y += ../common/timer.c
|
||||||
|
|
||||||
verstage-y += auxadc.c
|
verstage-y += ../common/auxadc.c
|
||||||
verstage-y += ../common/gpio.c gpio.c
|
verstage-y += ../common/gpio.c gpio.c
|
||||||
verstage-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
verstage-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
||||||
verstage-y += mt8183.c
|
verstage-y += mt8183.c
|
||||||
|
@ -24,7 +24,7 @@ verstage-y += ../common/timer.c
|
||||||
verstage-y += ../common/uart.c
|
verstage-y += ../common/uart.c
|
||||||
verstage-y += ../common/wdt.c
|
verstage-y += ../common/wdt.c
|
||||||
|
|
||||||
romstage-y += auxadc.c
|
romstage-y += ../common/auxadc.c
|
||||||
romstage-y += ../common/cbmem.c emi.c
|
romstage-y += ../common/cbmem.c emi.c
|
||||||
romstage-y += dramc_init_setting.c
|
romstage-y += dramc_init_setting.c
|
||||||
romstage-y += dramc_param.c
|
romstage-y += dramc_param.c
|
||||||
|
@ -44,8 +44,8 @@ romstage-y += ../common/timer.c
|
||||||
romstage-y += ../common/uart.c
|
romstage-y += ../common/uart.c
|
||||||
romstage-y += ../common/wdt.c
|
romstage-y += ../common/wdt.c
|
||||||
|
|
||||||
ramstage-y += auxadc.c
|
|
||||||
ramstage-y += emi.c
|
ramstage-y += emi.c
|
||||||
|
ramstage-y += ../common/auxadc.c
|
||||||
ramstage-y += ../common/ddp.c ddp.c
|
ramstage-y += ../common/ddp.c ddp.c
|
||||||
ramstage-y += ../common/dsi.c dsi.c
|
ramstage-y += ../common/dsi.c dsi.c
|
||||||
ramstage-y += ../common/gpio.c gpio.c
|
ramstage-y += ../common/gpio.c gpio.c
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#ifndef _MTK_ADC_H
|
#ifndef _MTK_ADC_H
|
||||||
#define _MTK_ADC_H
|
#define _MTK_ADC_H
|
||||||
|
|
||||||
|
#include <soc/auxadc_common.h>
|
||||||
|
#include <soc/infracfg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef struct mtk_auxadc_regs {
|
typedef struct mtk_auxadc_regs {
|
||||||
|
@ -16,6 +18,6 @@ typedef struct mtk_auxadc_regs {
|
||||||
uint32_t misc;
|
uint32_t misc;
|
||||||
} mtk_auxadc_regs;
|
} mtk_auxadc_regs;
|
||||||
|
|
||||||
/* Return voltage in uVolt */
|
static struct mt8183_infracfg_regs *const mtk_infracfg = mt8183_infracfg;
|
||||||
int auxadc_get_voltage(unsigned int channel);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue