Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 3 | #include <device/mmio.h> |
Yidi Lin | 2368a31 | 2021-02-02 21:00:36 +0800 | [diff] [blame] | 4 | #include <soc/iocfg.h> |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 5 | #include <soc/pll.h> |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 6 | #include <soc/pmif_spmi.h> |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 7 | |
| 8 | /* IOCFG_BM, DRV_CFG2 */ |
| 9 | DEFINE_BITFIELD(SPMI_SCL, 5, 3) |
| 10 | DEFINE_BITFIELD(SPMI_SDA, 8, 6) |
| 11 | |
| 12 | /* TOPRGU, WDT_SWSYSRST2 */ |
| 13 | DEFINE_BIT(SPMI_MST_RST, 4) |
| 14 | DEFINE_BITFIELD(UNLOCK_KEY, 31, 24) |
| 15 | |
| 16 | /* TOPCKGEN, CLK_CFG_15 */ |
| 17 | DEFINE_BITFIELD(CLK_SPMI_MST_SEL, 10, 8) |
| 18 | DEFINE_BIT(CLK_SPMI_MST_INT, 12) |
| 19 | DEFINE_BIT(PDN_SPMI_MST, 15) |
| 20 | |
| 21 | /* TOPCKGEN, CLK_CFG_UPDATE2 */ |
| 22 | DEFINE_BIT(SPMI_MST_CK_UPDATE, 30) |
| 23 | |
Yidi Lin | 2368a31 | 2021-02-02 21:00:36 +0800 | [diff] [blame] | 24 | int spmi_config_master(void) |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 25 | { |
| 26 | /* Software reset */ |
| 27 | SET32_BITFIELDS(&mtk_rug->wdt_swsysrst2, SPMI_MST_RST, 1, UNLOCK_KEY, 0x85); |
| 28 | |
Hsin-Hsiung Wang | 8579f23 | 2021-03-04 10:49:14 +0800 | [diff] [blame] | 29 | SET32_BITFIELDS(&mtk_topckgen->clk_cfg_15_clr, |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 30 | 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 Lin | 2368a31 | 2021-02-02 21:00:36 +0800 | [diff] [blame] | 44 | void pmif_spmi_iocfg(void) |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 45 | { |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 46 | SET32_BITFIELDS(&mtk_iocfg_bm->drv_cfg2, SPMI_SCL, 0x2, SPMI_SDA, 0x2); |
Hsin-Hsiung Wang | 22f8370 | 2020-05-29 19:46:14 +0800 | [diff] [blame] | 47 | } |