blob: a68f235382d86c7e7733fedc2d883d8536b8a32f [file] [log] [blame]
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +08003#include <device/mmio.h>
Yidi Lin2368a312021-02-02 21:00:36 +08004#include <soc/iocfg.h>
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +08005#include <soc/pll.h>
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +08006#include <soc/pmif_spmi.h>
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +08007
8/* IOCFG_BM, DRV_CFG2 */
9DEFINE_BITFIELD(SPMI_SCL, 5, 3)
10DEFINE_BITFIELD(SPMI_SDA, 8, 6)
11
12/* TOPRGU, WDT_SWSYSRST2 */
13DEFINE_BIT(SPMI_MST_RST, 4)
14DEFINE_BITFIELD(UNLOCK_KEY, 31, 24)
15
16/* TOPCKGEN, CLK_CFG_15 */
17DEFINE_BITFIELD(CLK_SPMI_MST_SEL, 10, 8)
18DEFINE_BIT(CLK_SPMI_MST_INT, 12)
19DEFINE_BIT(PDN_SPMI_MST, 15)
20
21/* TOPCKGEN, CLK_CFG_UPDATE2 */
22DEFINE_BIT(SPMI_MST_CK_UPDATE, 30)
23
Yidi Lin2368a312021-02-02 21:00:36 +080024int spmi_config_master(void)
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +080025{
26 /* Software reset */
27 SET32_BITFIELDS(&mtk_rug->wdt_swsysrst2, SPMI_MST_RST, 1, UNLOCK_KEY, 0x85);
28
Hsin-Hsiung Wang8579f232021-03-04 10:49:14 +080029 SET32_BITFIELDS(&mtk_topckgen->clk_cfg_15_clr,
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +080030 CLK_SPMI_MST_SEL, 0x7,
31 CLK_SPMI_MST_INT, 1,
32 PDN_SPMI_MST, 1);
33 SET32_BITFIELDS(&mtk_topckgen->clk_cfg_update2, SPMI_MST_CK_UPDATE, 1);
34
35 /* Software reset */
36 SET32_BITFIELDS(&mtk_rug->wdt_swsysrst2, SPMI_MST_RST, 0, UNLOCK_KEY, 0x85);
37
38 /* Enable SPMI */
39 write32(&mtk_spmi_mst->mst_req_en, 1);
40
41 return 0;
42}
43
Yidi Lin2368a312021-02-02 21:00:36 +080044void pmif_spmi_iocfg(void)
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +080045{
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +080046 SET32_BITFIELDS(&mtk_iocfg_bm->drv_cfg2, SPMI_SCL, 0x2, SPMI_SDA, 0x2);
Hsin-Hsiung Wang22f83702020-05-29 19:46:14 +080047}