soc/mediatek/common: Move I2C functions to common code
To promote code reuse and maintainability, move i2c functions to common folder. The function prototype "mtk_i2c_bus_init(uint8_t bus)" used by some legacy platforms are changed to "mtk_i2c_bus_init(uint8_t bus, uint32_t speed)" for better API integration. BUG=b:379008996 BRANCH=none TEST=build passed. Signed-off-by: Vince Liu <vince-wl.liu@mediatek.corp-partner.google.com> Change-Id: I6ac7009f5af4e6379d3f73aec61d0f4abd28471c Reviewed-on: https://review.coreboot.org/c/coreboot/+/87352 Reviewed-by: Yu-Ping Wu <yupingso@google.com> Reviewed-by: Yidi Lin <yidilin@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
1e0941c295
commit
b3bdffa475
26 changed files with 55 additions and 123 deletions
|
|
@ -83,7 +83,7 @@ static bool configure_display(void)
|
|||
printk(BIOS_INFO, "%s: Starting display init\n", __func__);
|
||||
|
||||
configure_backlight_and_bridge();
|
||||
mtk_i2c_bus_init(i2c_bus);
|
||||
mtk_i2c_bus_init(i2c_bus, I2C_SPEED_FAST);
|
||||
|
||||
if (anx7625_init(i2c_bus)) {
|
||||
printk(BIOS_ERR, "%s: Can't init ANX7625 bridge\n", __func__);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ static uint8_t wfc_id(void)
|
|||
[1] = 0x5035, /* GC5035 */
|
||||
};
|
||||
|
||||
mtk_i2c_bus_init(bus);
|
||||
mtk_i2c_bus_init(bus, I2C_SPEED_FAST);
|
||||
|
||||
/* Turn on camera sensor EEPROM */
|
||||
pwrap_write(PMIC_LDO_VCAMIO_CON0, 0x1);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ struct panel_description *get_panel_description(int panel_id)
|
|||
/* To read panel EDID, we have to first power on anx7625. */
|
||||
power_on_anx7625();
|
||||
|
||||
mtk_i2c_bus_init(ANX7625_I2C_BUS);
|
||||
mtk_i2c_bus_init(ANX7625_I2C_BUS, I2C_SPEED_FAST);
|
||||
|
||||
if (anx7625_init(ANX7625_I2C_BUS)) {
|
||||
printk(BIOS_ERR, "Can't init ANX7625 bridge.\n");
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ struct panel_description *get_panel_description(int panel_id)
|
|||
power_on_ps8640();
|
||||
|
||||
u8 i2c_bus = 4, i2c_addr = 0x08;
|
||||
mtk_i2c_bus_init(i2c_bus);
|
||||
mtk_i2c_bus_init(i2c_bus, I2C_SPEED_FAST);
|
||||
|
||||
ps8640_init(i2c_bus, i2c_addr);
|
||||
struct edid *edid = &ps8640_data.edid;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ void bootblock_mainboard_init(void)
|
|||
gpio_output(GPIO(SRCLKENAI2), 1);
|
||||
|
||||
/* Init i2c bus 2 Timing register for TPM */
|
||||
mtk_i2c_bus_init(CONFIG_DRIVER_TPM_I2C_BUS);
|
||||
mtk_i2c_bus_init(CONFIG_DRIVER_TPM_I2C_BUS, I2C_SPEED_FAST);
|
||||
|
||||
mtk_spi_init(CONFIG_EC_GOOGLE_CHROMEEC_SPI_BUS, SPI_PAD1_MASK, 6*MHz,
|
||||
0);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ enum {
|
|||
|
||||
static void configure_ext_buck(void)
|
||||
{
|
||||
mtk_i2c_bus_init(EXT_BUCK_I2C_BUS);
|
||||
mtk_i2c_bus_init(EXT_BUCK_I2C_BUS, I2C_SPEED_FAST);
|
||||
|
||||
switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) {
|
||||
case 3:
|
||||
|
|
@ -97,7 +97,7 @@ static void configure_audio(void)
|
|||
}
|
||||
|
||||
/* Init i2c bus Timing register for audio codecs */
|
||||
mtk_i2c_bus_init(CODEC_I2C_BUS);
|
||||
mtk_i2c_bus_init(CODEC_I2C_BUS, I2C_SPEED_FAST);
|
||||
|
||||
/* set I2S clock to 48KHz */
|
||||
mt_pll_set_aud_div(48 * KHz);
|
||||
|
|
@ -193,7 +193,7 @@ static int read_edid_from_ps8640(struct edid *edid)
|
|||
i2c_addr = 0x18;
|
||||
}
|
||||
|
||||
mtk_i2c_bus_init(i2c_bus);
|
||||
mtk_i2c_bus_init(i2c_bus, I2C_SPEED_FAST);
|
||||
|
||||
ps8640_init(i2c_bus, i2c_addr);
|
||||
if (ps8640_get_edid(i2c_bus, i2c_addr, edid)) {
|
||||
|
|
|
|||
29
src/soc/mediatek/common/i2c_common.c
Normal file
29
src/soc/mediatek/common/i2c_common.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
|
||||
|
||||
#include <console/console.h>
|
||||
#include <device/mmio.h>
|
||||
#include <soc/i2c.h>
|
||||
#include <soc/i2c_common.h>
|
||||
#include <device/i2c_simple.h>
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
mtk_i2c_speed_init(bus, speed);
|
||||
mtk_i2c_set_gpio_pinmux(bus);
|
||||
}
|
||||
|
||||
void mtk_i2c_dump_more_info(struct mt_i2c_regs *regs)
|
||||
{
|
||||
printk(BIOS_DEBUG, "LTIMING %x\nCLK_DIV %x\n",
|
||||
read32(®s->ltiming),
|
||||
read32(®s->clock_div));
|
||||
}
|
||||
|
||||
void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
|
||||
{
|
||||
write32(®s->clock_div, bus_ctrl->ac_timing.inter_clk_div);
|
||||
write32(®s->timing, bus_ctrl->ac_timing.htiming);
|
||||
write32(®s->ltiming, bus_ctrl->ac_timing.ltiming);
|
||||
write32(®s->hs, bus_ctrl->ac_timing.hs);
|
||||
write32(®s->ext_conf, bus_ctrl->ac_timing.ext);
|
||||
}
|
||||
|
|
@ -154,5 +154,7 @@ int mtk_i2c_calculate_speed(uint8_t bus, uint32_t clk_src,
|
|||
uint32_t *timing_sample_cnt);
|
||||
void mtk_i2c_speed_init(uint8_t bus, uint32_t speed);
|
||||
void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl);
|
||||
void mtk_i2c_set_gpio_pinmux(uint8_t bus);
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -60,13 +60,14 @@ _Static_assert(ARRAY_SIZE(mtk_i2c_bus_controller) == I2C_BUS_NUMBER,
|
|||
#define I2CLOG(fmt, arg...)
|
||||
#endif /* CONFIG_DEBUG_I2C */
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus)
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
uint8_t step_div;
|
||||
uint32_t i2c_freq;
|
||||
const uint8_t sample_div = 1;
|
||||
|
||||
assert(bus < ARRAY_SIZE(mtk_i2c_bus_controller));
|
||||
assert(speed == I2C_SPEED_FAST);
|
||||
|
||||
/* Calculate i2c frequency */
|
||||
step_div = DIV_ROUND_UP(I2C_CLK_HZ, (400 * KHz * sample_div * 2));
|
||||
|
|
|
|||
|
|
@ -42,6 +42,4 @@ struct mt_i2c_regs {
|
|||
|
||||
check_member(mt_i2c_regs, debug_stat, 0x64);
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus);
|
||||
|
||||
#endif /* SOC_MEDIATEK_MT8173_I2C_H */
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ static const struct pad_func i2c_funcs[I2C_BUS_NUMBER][2] = {
|
|||
},
|
||||
};
|
||||
|
||||
static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
{
|
||||
assert(bus < I2C_BUS_NUMBER);
|
||||
|
||||
|
|
@ -122,8 +122,9 @@ static void mtk_i2c_speed_init_soc(uint8_t bus)
|
|||
clock_div - 1);
|
||||
}
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus)
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
assert(speed == I2C_SPEED_FAST);
|
||||
mtk_i2c_speed_init_soc(bus);
|
||||
mtk_i2c_set_gpio_pinmux(bus);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,4 @@ struct mt_i2c_regs {
|
|||
|
||||
check_member(mt_i2c_regs, multi_dma, 0xf8c);
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus);
|
||||
|
||||
#endif /* SOC_MEDIATEK_MT8183_I2C_H */
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ ifeq ($(CONFIG_SOC_MEDIATEK_MT8186),y)
|
|||
all-y += ../common/cpu_id.c
|
||||
all-y += ../common/flash_controller.c
|
||||
all-y += ../common/gpio_eint_v1.c ../common/gpio.c ../common/gpio_op.c gpio.c
|
||||
all-y += ../common/i2c.c i2c.c
|
||||
all-y += ../common/i2c.c ../common/i2c_common.c i2c.c
|
||||
all-y += ../common/pll.c pll.c
|
||||
all-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
||||
all-y += ../common/timer.c ../common/timer_prepare.c
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ static const struct pad_func i2c_funcs[I2C_BUS_NUMBER][2] = {
|
|||
},
|
||||
};
|
||||
|
||||
static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
{
|
||||
assert(bus < I2C_BUS_NUMBER);
|
||||
|
||||
|
|
@ -111,25 +111,3 @@ static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
|||
gpio_set_pull(ptr[i].gpio, GPIO_PULL_ENABLE, ptr[i].select);
|
||||
}
|
||||
}
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
mtk_i2c_speed_init(bus, speed);
|
||||
mtk_i2c_set_gpio_pinmux(bus);
|
||||
}
|
||||
|
||||
void mtk_i2c_dump_more_info(struct mt_i2c_regs *regs)
|
||||
{
|
||||
printk(BIOS_DEBUG, "LTIMING %x\nCLK_DIV %x\n",
|
||||
read32(®s->ltiming),
|
||||
read32(®s->clock_div));
|
||||
}
|
||||
|
||||
void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
|
||||
{
|
||||
write32(®s->clock_div, bus_ctrl->ac_timing.inter_clk_div);
|
||||
write32(®s->timing, bus_ctrl->ac_timing.htiming);
|
||||
write32(®s->ltiming, bus_ctrl->ac_timing.ltiming);
|
||||
write32(®s->hs, bus_ctrl->ac_timing.hs);
|
||||
write32(®s->ext_conf, bus_ctrl->ac_timing.ext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,4 @@ enum {
|
|||
|
||||
check_member(mt_i2c_regs, multi_dma, 0xf8c);
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed);
|
||||
|
||||
#endif /* SOC_MEDIATEK_MT8186_I2C_H */
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ ifeq ($(CONFIG_SOC_MEDIATEK_MT8188),y)
|
|||
|
||||
all-y += ../common/flash_controller.c
|
||||
all-y += ../common/gpio_eint_v1.c ../common/gpio.c ../common/gpio_op.c gpio.c
|
||||
all-y += ../common/i2c.c i2c.c
|
||||
all-y += ../common/i2c.c ../common/i2c_common.c i2c.c
|
||||
all-y += ../common/pll.c pll.c
|
||||
all-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
||||
all-y += timer.c ../common/timer_prepare.c
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ static const struct pad_func i2c_funcs[I2C_BUS_NUMBER][2] = {
|
|||
},
|
||||
};
|
||||
|
||||
static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
{
|
||||
assert(bus < I2C_BUS_NUMBER);
|
||||
|
||||
|
|
@ -94,25 +94,3 @@ static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
|||
gpio_set_pull(ptr[i].gpio, GPIO_PULL_ENABLE, ptr[i].select);
|
||||
}
|
||||
}
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
mtk_i2c_speed_init(bus, speed);
|
||||
mtk_i2c_set_gpio_pinmux(bus);
|
||||
}
|
||||
|
||||
void mtk_i2c_dump_more_info(struct mt_i2c_regs *regs)
|
||||
{
|
||||
printk(BIOS_DEBUG, "LTIMING %x\nCLK_DIV %x\n",
|
||||
read32(®s->ltiming),
|
||||
read32(®s->clock_div));
|
||||
}
|
||||
|
||||
void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
|
||||
{
|
||||
write32(®s->clock_div, bus_ctrl->ac_timing.inter_clk_div);
|
||||
write32(®s->timing, bus_ctrl->ac_timing.htiming);
|
||||
write32(®s->ltiming, bus_ctrl->ac_timing.ltiming);
|
||||
write32(®s->hs, bus_ctrl->ac_timing.hs);
|
||||
write32(®s->ext_conf, bus_ctrl->ac_timing.ext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,4 @@ enum {
|
|||
|
||||
check_member(mt_i2c_regs, dma_nreq, 0xf94);
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed);
|
||||
|
||||
#endif /* SOC_MEDIATEK_MT8188_I2C_H */
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ static const struct pad_func i2c_funcs[I2C_BUS_NUMBER][2] = {
|
|||
},
|
||||
};
|
||||
|
||||
static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
{
|
||||
assert(bus < I2C_BUS_NUMBER);
|
||||
|
||||
|
|
@ -169,8 +169,9 @@ static void mtk_i2c_speed_init_soc(uint8_t bus)
|
|||
write32(&mtk_i2c_bus_controller[bus].i2c_regs->ext_conf, I2C_FS_START_CON);
|
||||
}
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus)
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
assert(speed == I2C_SPEED_FAST);
|
||||
mtk_i2c_speed_init_soc(bus);
|
||||
mtk_i2c_set_gpio_pinmux(bus);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,4 @@ struct mt_i2c_regs {
|
|||
|
||||
check_member(mt_i2c_regs, multi_dma, 0xf8c);
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus);
|
||||
|
||||
#endif /* SOC_MEDIATEK_MT8192_I2C_H */
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ ifeq ($(CONFIG_SOC_MEDIATEK_MT8195),y)
|
|||
# for bootblock, verstage, romstage, ramstage
|
||||
all-y += ../common/flash_controller.c
|
||||
all-y += ../common/gpio_eint_v1.c ../common/gpio.c ../common/gpio_op.c gpio.c
|
||||
all-y += ../common/i2c.c i2c.c
|
||||
all-y += ../common/i2c.c ../common/i2c_common.c i2c.c
|
||||
all-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
||||
all-y += ../common/timer.c ../common/timer_prepare.c
|
||||
all-y += ../common/uart.c
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ static const struct pad_func i2c_funcs[I2C_BUS_NUMBER][2] = {
|
|||
|
||||
};
|
||||
|
||||
static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
{
|
||||
assert(bus < I2C_BUS_NUMBER);
|
||||
|
||||
|
|
@ -100,25 +100,3 @@ static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
|||
gpio_set_pull(ptr[i].gpio, GPIO_PULL_ENABLE, ptr[i].select);
|
||||
}
|
||||
}
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
mtk_i2c_speed_init(bus, speed);
|
||||
mtk_i2c_set_gpio_pinmux(bus);
|
||||
}
|
||||
|
||||
void mtk_i2c_dump_more_info(struct mt_i2c_regs *regs)
|
||||
{
|
||||
printk(BIOS_DEBUG, "LTIMING %x\nCLK_DIV %x\n",
|
||||
read32(®s->ltiming),
|
||||
read32(®s->clock_div));
|
||||
}
|
||||
|
||||
void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
|
||||
{
|
||||
write32(®s->clock_div, bus_ctrl->ac_timing.inter_clk_div);
|
||||
write32(®s->timing, bus_ctrl->ac_timing.htiming);
|
||||
write32(®s->ltiming, bus_ctrl->ac_timing.ltiming);
|
||||
write32(®s->hs, bus_ctrl->ac_timing.hs);
|
||||
write32(®s->ext_conf, bus_ctrl->ac_timing.ext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,4 @@ enum {
|
|||
|
||||
check_member(mt_i2c_regs, multi_dma, 0xf8c);
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed);
|
||||
|
||||
#endif /* SOC_MEDIATEK_MT8195_I2C_H */
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ ifeq ($(CONFIG_SOC_MEDIATEK_MT8196),y)
|
|||
all-y += ../common/flash_controller.c
|
||||
all-y += ../common/gpio.c ../common/gpio_op.c gpio.c
|
||||
all-y += ../common/gpio_eint_v2.c gpio_eint.c
|
||||
all-y += ../common/i2c.c i2c.c
|
||||
all-y += ../common/i2c.c ../common/i2c_common.c i2c.c
|
||||
all-y += ../common/pll.c pll.c
|
||||
all-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
||||
all-y += timer.c timer_prepare.c
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ static const struct pad_func i2c_funcs[I2C_BUS_NUMBER][2] = {
|
|||
},
|
||||
};
|
||||
|
||||
static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
||||
{
|
||||
assert(bus < I2C_BUS_NUMBER);
|
||||
|
||||
|
|
@ -167,25 +167,3 @@ static void mtk_i2c_set_gpio_pinmux(uint8_t bus)
|
|||
gpio_set_pull(ptr[i].gpio, GPIO_PULL_ENABLE, ptr[i].select);
|
||||
}
|
||||
}
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed)
|
||||
{
|
||||
mtk_i2c_speed_init(bus, speed);
|
||||
mtk_i2c_set_gpio_pinmux(bus);
|
||||
}
|
||||
|
||||
void mtk_i2c_dump_more_info(struct mt_i2c_regs *regs)
|
||||
{
|
||||
printk(BIOS_DEBUG, "LTIMING %x\nCLK_DIV %x\n",
|
||||
read32(®s->ltiming),
|
||||
read32(®s->clock_div));
|
||||
}
|
||||
|
||||
void mtk_i2c_config_timing(struct mt_i2c_regs *regs, struct mtk_i2c *bus_ctrl)
|
||||
{
|
||||
write32(®s->clock_div, bus_ctrl->ac_timing.inter_clk_div);
|
||||
write32(®s->timing, bus_ctrl->ac_timing.htiming);
|
||||
write32(®s->ltiming, bus_ctrl->ac_timing.ltiming);
|
||||
write32(®s->hs, bus_ctrl->ac_timing.hs);
|
||||
write32(®s->ext_conf, bus_ctrl->ac_timing.ext);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,4 @@ enum {
|
|||
|
||||
check_member(mt_i2c_regs, fifo_thresh, 0xf8);
|
||||
|
||||
void mtk_i2c_bus_init(uint8_t bus, uint32_t speed);
|
||||
|
||||
#endif /* __SOC_MEDIATEK_MT8196_I2C_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue