Yidi Lin | 2368a31 | 2021-02-02 21:00:36 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <delay.h> |
| 5 | #include <soc/mt6315.h> |
| 6 | #include <soc/pmif.h> |
Hui Liu | a5c9682 | 2022-07-05 14:53:22 +0800 | [diff] [blame] | 7 | #include <soc/pmif_spmi.h> |
Yidi Lin | 2368a31 | 2021-02-02 21:00:36 +0800 | [diff] [blame] | 8 | |
| 9 | static struct pmif *pmif_arb = NULL; |
| 10 | |
| 11 | static void mt6315_read(u32 slvid, u32 reg, u32 *data) |
| 12 | { |
| 13 | pmif_arb->read(pmif_arb, slvid, reg, data); |
| 14 | } |
| 15 | |
| 16 | static void mt6315_write(u32 slvid, u32 reg, u32 data) |
| 17 | { |
| 18 | pmif_arb->write(pmif_arb, slvid, reg, data); |
| 19 | } |
| 20 | |
| 21 | void mt6315_write_field(u32 slvid, u32 reg, u32 val, u32 mask, u32 shift) |
| 22 | { |
| 23 | pmif_arb->write_field(pmif_arb, slvid, reg, val, mask, shift); |
| 24 | } |
| 25 | |
| 26 | static void mt6315_wdt_enable(u32 slvid) |
| 27 | { |
| 28 | mt6315_write(slvid, 0x3A9, 0x63); |
| 29 | mt6315_write(slvid, 0x3A8, 0x15); |
| 30 | mt6315_write(slvid, 0x127, 0x2); |
| 31 | mt6315_write(slvid, 0x127, 0x1); |
| 32 | mt6315_write(slvid, 0x127, 0x8); |
| 33 | udelay(50); |
| 34 | mt6315_write(slvid, 0x128, 0x8); |
| 35 | mt6315_write(slvid, 0x3A8, 0); |
| 36 | mt6315_write(slvid, 0x3A9, 0); |
| 37 | } |
| 38 | |
| 39 | void mt6315_buck_set_voltage(u32 slvid, u32 buck_id, u32 buck_uv) |
| 40 | { |
| 41 | unsigned int vol_reg, vol_val; |
| 42 | |
| 43 | if (!pmif_arb) |
| 44 | die("ERROR: pmif_arb not initialized"); |
| 45 | |
| 46 | switch (buck_id) { |
| 47 | case MT6315_BUCK_1: |
| 48 | vol_reg = MT6315_BUCK_TOP_ELR0; |
| 49 | break; |
| 50 | case MT6315_BUCK_3: |
| 51 | vol_reg = MT6315_BUCK_TOP_ELR3; |
| 52 | break; |
| 53 | default: |
| 54 | die("ERROR: Unknown buck_id %u", buck_id); |
| 55 | return; |
| 56 | }; |
| 57 | |
| 58 | vol_val = buck_uv / 6250; |
| 59 | mt6315_write(slvid, vol_reg, vol_val); |
| 60 | } |
| 61 | |
| 62 | u32 mt6315_buck_get_voltage(u32 slvid, u32 buck_id) |
| 63 | { |
| 64 | u32 vol_reg, vol; |
| 65 | |
| 66 | if (!pmif_arb) |
| 67 | die("ERROR: pmif_arb not initialized"); |
| 68 | |
| 69 | switch (buck_id) { |
| 70 | case MT6315_BUCK_1: |
| 71 | vol_reg = MT6315_BUCK_VBUCK1_DBG0; |
| 72 | break; |
| 73 | case MT6315_BUCK_3: |
| 74 | vol_reg = MT6315_BUCK_VBUCK1_DBG3; |
| 75 | break; |
| 76 | default: |
| 77 | die("ERROR: Unknown buck_id %u", buck_id); |
| 78 | return 0; |
| 79 | }; |
| 80 | |
| 81 | mt6315_read(slvid, vol_reg, &vol); |
| 82 | return vol * 6250; |
| 83 | } |
| 84 | |
| 85 | static void init_pmif_arb(void) |
| 86 | { |
| 87 | if (!pmif_arb) { |
| 88 | pmif_arb = get_pmif_controller(PMIF_SPMI, 0); |
| 89 | if (!pmif_arb) |
| 90 | die("ERROR: No spmi device"); |
| 91 | } |
| 92 | |
| 93 | if (pmif_arb->is_pmif_init_done(pmif_arb)) |
| 94 | die("ERROR - Failed to initialize pmif spmi"); |
| 95 | } |
| 96 | |
| 97 | void mt6315_init(void) |
| 98 | { |
Hui Liu | a5c9682 | 2022-07-05 14:53:22 +0800 | [diff] [blame] | 99 | size_t i; |
| 100 | |
Yidi Lin | 2368a31 | 2021-02-02 21:00:36 +0800 | [diff] [blame] | 101 | init_pmif_arb(); |
Hui Liu | a5c9682 | 2022-07-05 14:53:22 +0800 | [diff] [blame] | 102 | |
| 103 | for (i = 0; i < spmi_dev_cnt; i++) |
| 104 | mt6315_wdt_enable(spmi_dev[i].slvid); |
| 105 | |
Yidi Lin | 2368a31 | 2021-02-02 21:00:36 +0800 | [diff] [blame] | 106 | mt6315_init_setting(); |
| 107 | } |