summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/soc/mediatek/common/include/soc/pmif_common.h16
-rw-r--r--src/soc/mediatek/common/pmif.c64
-rw-r--r--src/soc/mediatek/common/pmif_init.c54
-rw-r--r--src/soc/mediatek/mt8186/Makefile.mk2
-rw-r--r--src/soc/mediatek/mt8188/Makefile.mk4
-rw-r--r--src/soc/mediatek/mt8192/Makefile.mk4
-rw-r--r--src/soc/mediatek/mt8195/Makefile.mk4
7 files changed, 89 insertions, 59 deletions
diff --git a/src/soc/mediatek/common/include/soc/pmif_common.h b/src/soc/mediatek/common/include/soc/pmif_common.h
index a8db658c06..ee0a2664b4 100644
--- a/src/soc/mediatek/common/include/soc/pmif_common.h
+++ b/src/soc/mediatek/common/include/soc/pmif_common.h
@@ -84,4 +84,20 @@ DEFINE_BIT(PMIFSPMI_MD_CTL_SRVOL_EN, 11)
struct pmif *get_pmif_controller(int inf, int mstid);
void pmwrap_interface_init(void);
int mtk_pmif_init(void);
+void pmif_spmi_read(struct pmif *arb, u32 slvid, u32 reg, u32 *data);
+void pmif_spmi_write(struct pmif *arb, u32 slvid, u32 reg, u32 data);
+u32 pmif_spmi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask, u32 shift);
+void pmif_spmi_write_field(struct pmif *arb, u32 slvid, u32 reg,
+ u32 val, u32 mask, u32 shift);
+void pmif_spi_read(struct pmif *arb, u32 slvid, u32 reg, u32 *data);
+void pmif_spi_write(struct pmif *arb, u32 slvid, u32 reg, u32 data);
+u32 pmif_spi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask, u32 shift);
+void pmif_spi_write_field(struct pmif *arb, u32 slvid, u32 reg,
+ u32 val, u32 mask, u32 shift);
+int pmif_check_init_done(struct pmif *arb);
+
+extern const struct pmif pmif_spmi_arb[];
+extern const size_t pmif_spmi_arb_count;
+extern const struct pmif pmif_spi_arb[];
+extern const size_t pmif_spi_arb_count;
#endif /*__MEDIATEK_SOC_PMIF_COMMON__*/
diff --git a/src/soc/mediatek/common/pmif.c b/src/soc/mediatek/common/pmif.c
index a7076eead2..11e279db6b 100644
--- a/src/soc/mediatek/common/pmif.c
+++ b/src/soc/mediatek/common/pmif.c
@@ -64,18 +64,18 @@ static void pmif_send_cmd(struct pmif *arb, int write, u32 opc, u32 slvid,
}
}
-static void pmif_spmi_read(struct pmif *arb, u32 slvid, u32 reg, u32 *data)
+void pmif_spmi_read(struct pmif *arb, u32 slvid, u32 reg, u32 *data)
{
*data = 0;
pmif_send_cmd(arb, 0, PMIF_CMD_EXT_REG_LONG, slvid, reg, data, 0, 1);
}
-static void pmif_spmi_write(struct pmif *arb, u32 slvid, u32 reg, u32 data)
+void pmif_spmi_write(struct pmif *arb, u32 slvid, u32 reg, u32 data)
{
pmif_send_cmd(arb, 1, PMIF_CMD_EXT_REG_LONG, slvid, reg, NULL, data, 1);
}
-static u32 pmif_spmi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask, u32 shift)
+u32 pmif_spmi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask, u32 shift)
{
u32 data;
@@ -86,8 +86,8 @@ static u32 pmif_spmi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask,
return data;
}
-static void pmif_spmi_write_field(struct pmif *arb, u32 slvid, u32 reg,
- u32 val, u32 mask, u32 shift)
+void pmif_spmi_write_field(struct pmif *arb, u32 slvid, u32 reg,
+ u32 val, u32 mask, u32 shift)
{
u32 old, new;
@@ -97,18 +97,18 @@ static void pmif_spmi_write_field(struct pmif *arb, u32 slvid, u32 reg,
pmif_spmi_write(arb, slvid, reg, new);
}
-static void pmif_spi_read(struct pmif *arb, u32 slvid, u32 reg, u32 *data)
+void pmif_spi_read(struct pmif *arb, u32 slvid, u32 reg, u32 *data)
{
*data = 0;
pmif_send_cmd(arb, 0, PMIF_CMD_REG_0, slvid, reg, data, 0, 1);
}
-static void pmif_spi_write(struct pmif *arb, u32 slvid, u32 reg, u32 data)
+void pmif_spi_write(struct pmif *arb, u32 slvid, u32 reg, u32 data)
{
pmif_send_cmd(arb, 1, PMIF_CMD_REG_0, slvid, reg, NULL, data, 1);
}
-static u32 pmif_spi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask, u32 shift)
+u32 pmif_spi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask, u32 shift)
{
u32 data;
@@ -119,8 +119,8 @@ static u32 pmif_spi_read_field(struct pmif *arb, u32 slvid, u32 reg, u32 mask, u
return data;
}
-static void pmif_spi_write_field(struct pmif *arb, u32 slvid, u32 reg,
- u32 val, u32 mask, u32 shift)
+void pmif_spi_write_field(struct pmif *arb, u32 slvid, u32 reg,
+ u32 val, u32 mask, u32 shift)
{
u32 old, new;
@@ -130,7 +130,7 @@ static void pmif_spi_write_field(struct pmif *arb, u32 slvid, u32 reg,
pmif_spi_write(arb, slvid, reg, new);
}
-static int is_pmif_init_done(struct pmif *arb)
+int pmif_check_init_done(struct pmif *arb)
{
if (read32(&arb->mtk_pmif->init_done) & 0x1)
return 0;
@@ -138,36 +138,9 @@ static int is_pmif_init_done(struct pmif *arb)
return -E_NODEV;
}
-static const struct pmif pmif_spmi_arb[] = {
- {
- .mtk_pmif = (struct mtk_pmif_regs *)PMIF_SPMI_BASE,
- .ch = (struct chan_regs *)PMIF_SPMI_AP_CHAN,
- .mstid = SPMI_MASTER_0,
- .pmifid = PMIF_SPMI,
- .write = pmif_spmi_write,
- .read = pmif_spmi_read,
- .write_field = pmif_spmi_write_field,
- .read_field = pmif_spmi_read_field,
- .is_pmif_init_done = is_pmif_init_done,
- },
-};
-
-static const struct pmif pmif_spi_arb[] = {
- {
- .mtk_pmif = (struct mtk_pmif_regs *)PMIF_SPI_BASE,
- .ch = (struct chan_regs *)PMIF_SPI_AP_CHAN,
- .pmifid = PMIF_SPI,
- .write = pmif_spi_write,
- .read = pmif_spi_read,
- .write_field = pmif_spi_write_field,
- .read_field = pmif_spi_read_field,
- .is_pmif_init_done = is_pmif_init_done,
- },
-};
-
struct pmif *get_pmif_controller(int inf, int mstid)
{
- if (inf == PMIF_SPMI && mstid < ARRAY_SIZE(pmif_spmi_arb))
+ if (inf == PMIF_SPMI && mstid < pmif_spmi_arb_count)
return (struct pmif *)&pmif_spmi_arb[mstid];
else if (inf == PMIF_SPI)
return (struct pmif *)&pmif_spi_arb[0];
@@ -289,16 +262,3 @@ void pmwrap_interface_init(void)
pmif_select(PMIF_SLP_REQ);
}
}
-
-int mtk_pmif_init(void)
-{
- int ret;
-
- ret = pmif_clk_init();
- if (!ret)
- ret = pmif_spmi_init(get_pmif_controller(PMIF_SPMI, SPMI_MASTER_0));
- if (!ret && !CONFIG(PWRAP_WITH_PMIF_SPMI))
- ret = pmif_spi_init(get_pmif_controller(PMIF_SPI, 0));
-
- return ret;
-}
diff --git a/src/soc/mediatek/common/pmif_init.c b/src/soc/mediatek/common/pmif_init.c
new file mode 100644
index 0000000000..09158ed7dc
--- /dev/null
+++ b/src/soc/mediatek/common/pmif_init.c
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <assert.h>
+#include <console/console.h>
+#include <device/mmio.h>
+#include <soc/addressmap.h>
+#include <soc/pmif_spi.h>
+#include <soc/pmif_spmi.h>
+#include <soc/pmif_sw.h>
+#include <soc/spmi.h>
+
+const struct pmif pmif_spmi_arb[] = {
+ {
+ .mtk_pmif = (struct mtk_pmif_regs *)PMIF_SPMI_BASE,
+ .ch = (struct chan_regs *)PMIF_SPMI_AP_CHAN,
+ .mstid = SPMI_MASTER_0,
+ .pmifid = PMIF_SPMI,
+ .write = pmif_spmi_write,
+ .read = pmif_spmi_read,
+ .write_field = pmif_spmi_write_field,
+ .read_field = pmif_spmi_read_field,
+ .is_pmif_init_done = pmif_check_init_done,
+ },
+};
+
+const size_t pmif_spmi_arb_count = ARRAY_SIZE(pmif_spmi_arb);
+
+const struct pmif pmif_spi_arb[] = {
+ {
+ .mtk_pmif = (struct mtk_pmif_regs *)PMIF_SPI_BASE,
+ .ch = (struct chan_regs *)PMIF_SPI_AP_CHAN,
+ .pmifid = PMIF_SPI,
+ .write = pmif_spi_write,
+ .read = pmif_spi_read,
+ .write_field = pmif_spi_write_field,
+ .read_field = pmif_spi_read_field,
+ .is_pmif_init_done = pmif_check_init_done,
+ },
+};
+
+const size_t pmif_spi_arb_count = ARRAY_SIZE(pmif_spi_arb);
+
+int mtk_pmif_init(void)
+{
+ int ret;
+
+ ret = pmif_clk_init();
+ if (!ret)
+ ret = pmif_spmi_init(get_pmif_controller(PMIF_SPMI, SPMI_MASTER_0));
+ if (!ret && !CONFIG(PWRAP_WITH_PMIF_SPMI))
+ ret = pmif_spi_init(get_pmif_controller(PMIF_SPI, 0));
+
+ return ret;
+}
diff --git a/src/soc/mediatek/mt8186/Makefile.mk b/src/soc/mediatek/mt8186/Makefile.mk
index d44dc4592d..fda418006f 100644
--- a/src/soc/mediatek/mt8186/Makefile.mk
+++ b/src/soc/mediatek/mt8186/Makefile.mk
@@ -29,7 +29,7 @@ romstage-y += ../common/memory_test.c
romstage-y += ../common/mmu_operations.c ../common/mmu_cmops.c
romstage-y += ../common/mt6315.c mt6315.c
romstage-y += ../common/pmic_wrap.c pmic_wrap.c pmif.c mt6366.c
-romstage-y += ../common/pmif.c ../common/pmif_clk.c pmif_clk.c
+romstage-y += ../common/pmif.c ../common/pmif_clk.c ../common/pmif_init.c pmif_clk.c
romstage-y += ../common/pmif_spmi.c pmif_spmi.c
romstage-y += ../common/rtc.c ../common/rtc_osc_init.c rtc.c
diff --git a/src/soc/mediatek/mt8188/Makefile.mk b/src/soc/mediatek/mt8188/Makefile.mk
index 9015a63e34..8d1b783784 100644
--- a/src/soc/mediatek/mt8188/Makefile.mk
+++ b/src/soc/mediatek/mt8188/Makefile.mk
@@ -27,7 +27,7 @@ romstage-y += ../common/memory_test.c
romstage-y += ../common/mmu_operations.c ../common/mmu_cmops.c
romstage-y += ../common/mt6315.c mt6315.c
romstage-y += ../common/mt6359p.c mt6359p.c
-romstage-y += ../common/pmif.c ../common/pmif_clk.c pmif_clk.c
+romstage-y += ../common/pmif.c ../common/pmif_clk.c ../common/pmif_init.c pmif_clk.c
romstage-y += ../common/pmif_spi.c pmif_spi.c
romstage-y += ../common/pmif_spmi.c pmif_spmi.c
romstage-y += ../common/rtc.c ../common/rtc_osc_init.c ../common/rtc_mt6359p.c
@@ -51,7 +51,7 @@ ramstage-y += ../common/mmu_operations.c ../common/mmu_cmops.c
ramstage-$(CONFIG_COMMONLIB_STORAGE_MMC) += ../common/msdc.c msdc.c
ramstage-y += ../common/mt6359p.c mt6359p.c
ramstage-y += ../common/mtcmos.c mtcmos.c
-ramstage-y += ../common/pmif.c ../common/pmif_clk.c pmif_clk.c
+ramstage-y += ../common/pmif.c ../common/pmif_clk.c ../common/pmif_init.c pmif_clk.c
ramstage-y += ../common/pmif_spi.c pmif_spi.c
ramstage-y += ../common/pmif_spmi.c pmif_spmi.c
ramstage-y += ../common/rtc.c ../common/rtc_osc_init.c ../common/rtc_mt6359p.c
diff --git a/src/soc/mediatek/mt8192/Makefile.mk b/src/soc/mediatek/mt8192/Makefile.mk
index de2d7bf723..0847439df3 100644
--- a/src/soc/mediatek/mt8192/Makefile.mk
+++ b/src/soc/mediatek/mt8192/Makefile.mk
@@ -25,7 +25,7 @@ romstage-y += ../common/l2c_ops.c
romstage-y += ../common/memory.c ../common/memory_test.c
romstage-y += ../common/mmu_operations.c ../common/mmu_cmops.c
romstage-y += ../common/pll.c pll.c
-romstage-y += ../common/pmif.c ../common/pmif_clk.c pmif_clk.c
+romstage-y += ../common/pmif.c ../common/pmif_clk.c ../common/pmif_init.c pmif_clk.c
romstage-y += ../common/pmif_spi.c pmif_spi.c
romstage-y += ../common/pmif_spmi.c pmif_spmi.c
romstage-y += ../common/mt6315.c mt6315.c
@@ -46,7 +46,7 @@ ramstage-y += ../common/mcupm.c
ramstage-y += ../common/mmu_operations.c ../common/mmu_cmops.c
ramstage-$(CONFIG_COMMONLIB_STORAGE_MMC) += ../common/msdc.c msdc.c
ramstage-y += ../common/mtcmos.c mtcmos.c
-ramstage-y += ../common/pmif.c
+ramstage-y += ../common/pmif.c ../common/pmif_init.c
ramstage-y += ../common/rtc.c ../common/rtc_mt6359p.c
ramstage-y += soc.c
ramstage-y += ../common/spm.c spm.c
diff --git a/src/soc/mediatek/mt8195/Makefile.mk b/src/soc/mediatek/mt8195/Makefile.mk
index a3b002ed27..22f163b2d4 100644
--- a/src/soc/mediatek/mt8195/Makefile.mk
+++ b/src/soc/mediatek/mt8195/Makefile.mk
@@ -29,7 +29,7 @@ romstage-y += ../common/memory_test.c
romstage-y += ../common/mmu_operations.c ../common/mmu_cmops.c
romstage-y += ../common/pll.c pll.c
romstage-y += scp.c
-romstage-y += ../common/pmif.c ../common/pmif_clk.c pmif_clk.c
+romstage-y += ../common/pmif.c ../common/pmif_clk.c ../common/pmif_init.c pmif_clk.c
romstage-y += ../common/pmif_spi.c pmif_spi.c
romstage-y += ../common/pmif_spmi.c pmif_spmi.c
romstage-y += ../common/mt6315.c mt6315.c
@@ -62,7 +62,7 @@ ramstage-y += mt6360.c
ramstage-y += ../common/mtcmos.c mtcmos.c
ramstage-$(CONFIG_PCI) += ../common/pcie.c pcie.c
ramstage-y += ../common/pll.c pll.c
-ramstage-y += ../common/pmif.c
+ramstage-y += ../common/pmif.c ../common/pmif_init.c
ramstage-y += ../common/rtc.c ../common/rtc_mt6359p.c
ramstage-y += soc.c
ramstage-y += ../common/spm.c spm.c