James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* |
| 4 | * This file is created based on MT8186 Functional Specification |
| 5 | * Chapter number: 3.7 |
| 6 | */ |
| 7 | |
| 8 | #include <assert.h> |
| 9 | #include <console/console.h> |
| 10 | #include <delay.h> |
| 11 | #include <soc/mt6366.h> |
| 12 | #include <soc/pmic_wrap.h> |
Zhiyong Tao | a747770 | 2022-03-24 18:57:44 +0800 | [diff] [blame] | 13 | #include <soc/pmif.h> |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 14 | #include <soc/regulator.h> |
| 15 | #include <timer.h> |
| 16 | |
| 17 | static struct pmic_setting init_setting[] = { |
| 18 | {0x1E, 0xA, 0xA, 0}, |
| 19 | {0x22, 0x1F00, 0x1F00, 0}, |
| 20 | {0x2E, 0x1, 0x1, 0}, |
| 21 | {0x30, 0x1, 0x1, 0}, |
| 22 | {0x36, 0x8888, 0xFFFF, 0}, |
| 23 | {0x3A, 0x8888, 0xFFFF, 0}, |
| 24 | {0x3C, 0x8888, 0xFFFF, 0}, |
| 25 | {0x3E, 0x888, 0xFFF, 0}, |
| 26 | {0x94, 0x0, 0xFFFF, 0}, |
| 27 | {0x10C, 0x18, 0x18, 0}, |
| 28 | {0x112, 0x4, 0x4, 0}, |
| 29 | {0x118, 0x8, 0x8, 0}, |
| 30 | {0x12A, 0x100, 0x180, 0}, |
| 31 | {0x134, 0x80, 0x2890, 0}, |
| 32 | {0x14C, 0x20, 0x20, 0}, |
| 33 | {0x198, 0x0, 0x1FF, 0}, |
| 34 | {0x790, 0x280, 0x780, 0}, |
| 35 | {0x7AC, 0x0, 0x2000, 0}, |
| 36 | {0x98A, 0x1840, 0x1E40, 0}, |
| 37 | {0xA08, 0x1, 0x1, 0}, |
| 38 | {0xA24, 0x1E00, 0x1F00, 0}, |
| 39 | {0xA38, 0x0, 0x100, 0}, |
| 40 | {0xA3C, 0x81E0, 0x81E0, 0}, |
| 41 | {0xA44, 0xFFFF, 0xFFFF, 0}, |
| 42 | {0xA46, 0xFC00, 0xFC00, 0}, |
| 43 | {0xC8A, 0x4, 0xC, 0}, |
| 44 | {0xF8C, 0xAAA, 0xAAA, 0}, |
| 45 | {0x1188, 0x0, 0x8000, 0}, |
| 46 | {0x119E, 0x6000, 0x7000, 0}, |
| 47 | {0x11A2, 0x0, 0x3000, 0}, |
| 48 | {0x11B0, 0x4000, 0x4000, 0}, |
| 49 | {0x11B4, 0x0, 0x100, 0}, |
| 50 | {0x123A, 0x8040, 0x83FF, 0}, |
| 51 | {0x123E, 0x4, 0x4, 0}, |
| 52 | {0x1242, 0x1, 0x1, 0}, |
| 53 | {0x1260, 0x0, 0x154, 0}, |
| 54 | {0x1312, 0x8, 0x8, 0}, |
| 55 | {0x1334, 0x0, 0x100, 0}, |
| 56 | {0x138A, 0x10, 0x7F, 0}, |
| 57 | {0x138C, 0x15, 0x7F, 0}, |
| 58 | {0x138E, 0x1030, 0x3030, 0}, |
| 59 | {0x140A, 0x10, 0x7F, 0}, |
| 60 | {0x140C, 0x15, 0x7F, 0}, |
| 61 | {0x140E, 0x1030, 0x3030, 0}, |
| 62 | {0x148A, 0x10, 0x7F, 0}, |
| 63 | {0x148E, 0x1030, 0x3030, 0}, |
| 64 | {0x14A2, 0x20, 0x20, 0}, |
| 65 | {0x150A, 0x10, 0x7F, 0}, |
| 66 | {0x150E, 0x1030, 0x3030, 0}, |
| 67 | {0x158A, 0x8, 0x7F, 0}, |
| 68 | {0x158C, 0x90C, 0x7F7F, 0}, |
| 69 | {0x158E, 0x1030, 0x3030, 0}, |
| 70 | {0x159C, 0x8, 0xC, 0}, |
| 71 | {0x15A2, 0x20, 0x20, 0}, |
| 72 | {0x168A, 0x50, 0x7F, 0}, |
| 73 | {0x168C, 0x1964, 0x7F7F, 0}, |
| 74 | {0x168E, 0x2020, 0x3030, 0}, |
| 75 | {0x16A2, 0x20, 0x20, 0}, |
| 76 | {0x16AA, 0x50, 0x7F, 0}, |
| 77 | {0x170C, 0x1964, 0x7F7F, 0}, |
| 78 | {0x170E, 0x2020, 0x3030, 0}, |
| 79 | {0x172A, 0x44, 0x7F, 0}, |
| 80 | {0x178C, 0x202, 0x7F7F, 0}, |
| 81 | {0x178E, 0x70, 0x73, 0}, |
| 82 | {0x1790, 0xC, 0xC, 0}, |
| 83 | {0x1798, 0x2810, 0x3F3F, 0}, |
| 84 | {0x179A, 0x800, 0x3F00, 0}, |
| 85 | {0x179E, 0x1, 0x1, 0}, |
| 86 | {0x1808, 0x2000, 0x3000, 0}, |
| 87 | {0x180C, 0x60, 0x60, 0}, |
| 88 | {0x1814, 0x3FF0, 0x7FFF, 0}, |
| 89 | {0x1816, 0x3, 0x7, 0}, |
| 90 | {0x181A, 0x6081, 0xFFBF, 0}, |
| 91 | {0x181C, 0x503, 0x787, 0}, |
| 92 | {0x181E, 0xA462, 0xFFFF, 0}, |
| 93 | {0x1820, 0xA662, 0xFFFF, 0}, |
| 94 | {0x1824, 0xDB6, 0xFFF, 0}, |
| 95 | {0x1828, 0x160, 0x160, 0}, |
| 96 | {0x1830, 0x3FF0, 0x7FFF, 0}, |
| 97 | {0x1832, 0x3, 0x7, 0}, |
| 98 | {0x1836, 0x6081, 0xFFBF, 0}, |
| 99 | {0x1838, 0x503, 0x787, 0}, |
| 100 | {0x183A, 0xA262, 0xFFFF, 0}, |
| 101 | {0x183C, 0xA262, 0xFFFF, 0}, |
| 102 | {0x1840, 0xDB6, 0xFFF, 0}, |
| 103 | {0x1888, 0x420, 0xE7C, 0}, |
| 104 | {0x188A, 0x801, 0x3C07, 0}, |
| 105 | {0x188C, 0x1F, 0x3F, 0}, |
| 106 | {0x188E, 0x129A, 0xFFFF, 0}, |
| 107 | {0x1894, 0x58, 0x1F8, 0}, |
| 108 | {0x1896, 0x1C, 0x7C, 0}, |
| 109 | {0x1898, 0x1805, 0x3C07, 0}, |
| 110 | {0x189A, 0xF, 0xF, 0}, |
| 111 | {0x189C, 0x221A, 0xFFFF, 0}, |
| 112 | {0x18A0, 0x2E, 0x3F, 0}, |
| 113 | {0x18A2, 0x0, 0x40, 0}, |
| 114 | {0x18A4, 0x2C06, 0x3C07, 0}, |
| 115 | {0x18A6, 0xF, 0xF, 0}, |
| 116 | {0x18A8, 0x221A, 0xFFFF, 0}, |
| 117 | {0x18AC, 0x2E, 0x3F, 0}, |
| 118 | {0x18AE, 0x0, 0x40, 0}, |
| 119 | {0x18B0, 0x1805, 0x3C07, 0}, |
| 120 | {0x18B2, 0xF, 0xF, 0}, |
| 121 | {0x18B4, 0x221A, 0xFFFF, 0}, |
| 122 | {0x18B8, 0x2E, 0x3F, 0}, |
| 123 | {0x18BC, 0x50, 0x4F0, 0}, |
| 124 | {0x18BE, 0x3C, 0xFC, 0}, |
| 125 | {0x18C0, 0x0, 0x300, 0}, |
| 126 | {0x18C2, 0x8886, 0xFFFF, 0}, |
| 127 | {0x1A0E, 0x3, 0x3, 0}, |
| 128 | {0x1A10, 0x1, 0x1, 0}, |
| 129 | {0x1A12, 0x0, 0x1, 0}, |
| 130 | {0x1A14, 0x0, 0x1, 0}, |
| 131 | {0x1A16, 0x0, 0x1, 0}, |
| 132 | {0x1A18, 0x0, 0x1, 0}, |
| 133 | {0x1A1A, 0x0, 0x1, 0}, |
| 134 | {0x1A1C, 0x0, 0x1, 0}, |
| 135 | {0x1A1E, 0x0, 0x1, 0}, |
| 136 | {0x1A20, 0x0, 0x1, 0}, |
| 137 | {0x1A22, 0x0, 0x1, 0}, |
| 138 | {0x1A24, 0x0, 0x1, 0}, |
| 139 | {0x1A26, 0x0, 0x1, 0}, |
| 140 | {0x1A2C, 0x0, 0x1, 0}, |
| 141 | {0x1A2E, 0x0, 0x1, 0}, |
| 142 | {0x1A30, 0x0, 0x1, 0}, |
| 143 | {0x1A32, 0x0, 0x1, 0}, |
| 144 | {0x1A34, 0x0, 0x1, 0}, |
| 145 | {0x1A36, 0x0, 0x1, 0}, |
| 146 | {0x1A38, 0x0, 0x1, 0}, |
| 147 | {0x1A3A, 0x0, 0x1, 0}, |
| 148 | {0x1A3C, 0x0, 0x1, 0}, |
| 149 | {0x1A3E, 0x0, 0x1, 0}, |
| 150 | {0x1A40, 0x0, 0x1, 0}, |
| 151 | {0x1A42, 0x0, 0x1, 0}, |
| 152 | {0x1A44, 0x0, 0x1, 0}, |
| 153 | {0x1A46, 0x0, 0x1, 0}, |
| 154 | {0x1A48, 0x0, 0x1, 0}, |
| 155 | {0x1A4A, 0x0, 0x1, 0}, |
| 156 | {0x1A4C, 0x0, 0x1, 0}, |
| 157 | {0x1A4E, 0x0, 0x1, 0}, |
| 158 | {0x1A50, 0xE7FF, 0xE7FF, 0}, |
| 159 | {0x1A56, 0x7FFF, 0x7FFF, 0}, |
| 160 | {0x1B48, 0x10, 0x7F, 0}, |
| 161 | {0x1B4A, 0xF15, 0x7F7F, 0}, |
| 162 | {0x1B8A, 0x10, 0x7F, 0}, |
| 163 | {0x1B8C, 0xF15, 0x7F7F, 0}, |
| 164 | {0x1BA8, 0x10, 0x7F, 0}, |
| 165 | {0x1BAA, 0xF15, 0x7F7F, 0}, |
| 166 | {0x1BAC, 0x0, 0x3, 0}, |
| 167 | {0x1BCA, 0x10, 0x7F, 0}, |
| 168 | {0x1BCC, 0x70F, 0x7F7F, 0}, |
| 169 | {0x1C9E, 0x38, 0x7F, 0}, |
| 170 | {0x1CA0, 0x70F, 0x7F7F, 0}, |
Rex-BC Chen | 3a39202 | 2022-02-21 11:44:47 +0800 | [diff] [blame] | 171 | /* VSRAM_CORE: set SW mode */ |
| 172 | {0x1CA4, 0x1, 0xFFFF, 0}, |
| 173 | /* VSRAM_CORE: SW set OFF */ |
| 174 | {0x1C9C, 0x0, 0xFFFF, 0}, |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 175 | {0x1EA2, 0x1B, 0x1F, 0}, |
| 176 | {0x1EA4, 0xC00, 0x1C00, 0}, |
| 177 | {0x1EA6, 0xC00, 0x1C00, 0}, |
| 178 | {0x1EA8, 0xC00, 0x1C00, 0}, |
| 179 | }; |
| 180 | |
| 181 | static struct pmic_setting lp_setting[] = { |
| 182 | /* Suspend */ |
| 183 | /* [0:0]: RG_BUCK_VPROC11_SW_OP_EN */ |
| 184 | {0x1390, 0x1, 0x1, 0}, |
| 185 | /* [0:0]: RG_BUCK_VCORE_SW_OP_EN */ |
| 186 | {0x1490, 0x1, 0x1, 0}, |
| 187 | /* [0:0]: RG_BUCK_VGPU_SW_OP_EN */ |
| 188 | {0x1510, 0x1, 0x1, 0}, |
| 189 | /* [0:0]: RG_BUCK_VMODEM_SW_OP_EN */ |
| 190 | {0x1590, 0x1, 0x1, 0}, |
| 191 | /* [0:0]: RG_BUCK_VS1_SW_OP_EN */ |
| 192 | {0x1690, 0x1, 0x1, 0}, |
| 193 | /* [1:1]: RG_BUCK_VS2_HW0_OP_EN */ |
| 194 | {0x1710, 0x1, 0x1, 1}, |
| 195 | /* [1:1]: RG_BUCK_VS2_HW0_OP_CFG */ |
| 196 | {0x1716, 0x1, 0x1, 1}, |
| 197 | /* [1:1]: RG_BUCK_VDRAM1_HW0_OP_EN */ |
| 198 | {0x1610, 0x1, 0x1, 1}, |
| 199 | /* [1:1]: RG_BUCK_VDRAM1_HW0_OP_CFG */ |
| 200 | {0x1616, 0x1, 0x1, 1}, |
| 201 | /* [0:0]: RG_BUCK_VPROC12_SW_OP_EN */ |
| 202 | {0x1410, 0x1, 0x1, 0}, |
| 203 | /* [0:0]: RG_LDO_VSRAM_GPU_SW_OP_EN */ |
| 204 | {0x1BD0, 0x1, 0x1, 0}, |
| 205 | /* [1:1]: RG_LDO_VSRAM_OTHERS_HW0_OP_EN */ |
| 206 | {0x1BAE, 0x1, 0x1, 1}, |
| 207 | /* [1:1]: RG_LDO_VSRAM_OTHERS_HW0_OP_CFG */ |
| 208 | {0x1BB4, 0x1, 0x1, 1}, |
| 209 | /* [0:0]: RG_LDO_VSRAM_PROC11_SW_OP_EN */ |
| 210 | {0x1B4E, 0x1, 0x1, 0}, |
| 211 | /* [1:1]: RG_LDO_VXO22_HW0_OP_EN */ |
| 212 | {0x1A8A, 0x1, 0x1, 1}, |
| 213 | /* [1:1]: RG_LDO_VXO22_HW0_OP_CFG */ |
| 214 | {0x1A90, 0x1, 0x1, 1}, |
| 215 | /* [2:2]: RG_LDO_VRF18_HW1_OP_EN */ |
| 216 | {0x1C1E, 0x1, 0x1, 2}, |
| 217 | /* [2:2]: RG_LDO_VRF18_HW1_OP_CFG */ |
| 218 | {0x1C24, 0x0, 0x1, 2}, |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 219 | /* [0:0]: RG_LDO_VEFUSE_SW_OP_EN */ |
| 220 | {0x1C46, 0x1, 0x1, 0}, |
| 221 | /* [0:0]: RG_LDO_VCN33_SW_OP_EN */ |
| 222 | {0x1D1E, 0x1, 0x1, 0}, |
| 223 | /* [0:0]: RG_LDO_VCN33_SW_OP_EN */ |
| 224 | {0x1D1E, 0x1, 0x1, 0}, |
| 225 | /* [0:0]: RG_LDO_VCN28_SW_OP_EN */ |
| 226 | {0x1D8A, 0x1, 0x1, 0}, |
| 227 | /* [0:0]: RG_LDO_VCN18_SW_OP_EN */ |
| 228 | {0x1C5A, 0x1, 0x1, 0}, |
| 229 | /* [0:0]: RG_LDO_VCAMA1_SW_OP_EN */ |
| 230 | {0x1C6E, 0x1, 0x1, 0}, |
| 231 | /* [0:0]: RG_LDO_VCAMD_SW_OP_EN */ |
| 232 | {0x1C9E, 0x1, 0x1, 0}, |
| 233 | /* [0:0]: RG_LDO_VCAMA2_SW_OP_EN */ |
| 234 | {0x1C8A, 0x1, 0x1, 0}, |
| 235 | /* [0:0]: RG_LDO_VSRAM_PROC12_SW_OP_EN */ |
| 236 | {0x1B90, 0x1, 0x1, 0}, |
| 237 | /* [0:0]: RG_LDO_VCAMIO_SW_OP_EN */ |
| 238 | {0x1CB2, 0x1, 0x1, 0}, |
| 239 | /* [0:0]: RG_LDO_VLDO28_SW_OP_EN */ |
| 240 | {0x1D34, 0x1, 0x1, 0}, |
| 241 | /* [0:0]: RG_LDO_VLDO28_SW_OP_EN */ |
| 242 | {0x1D34, 0x1, 0x1, 0}, |
| 243 | /* [1:1]: RG_LDO_VA12_HW0_OP_EN */ |
| 244 | {0x1A9E, 0x1, 0x1, 1}, |
| 245 | /* [1:1]: RG_LDO_VA12_HW0_OP_CFG */ |
| 246 | {0x1AA4, 0x1, 0x1, 1}, |
| 247 | /* [1:1]: RG_LDO_VAUX18_HW0_OP_EN */ |
| 248 | {0x1AB2, 0x1, 0x1, 1}, |
| 249 | /* [1:1]: RG_LDO_VAUX18_HW0_OP_CFG */ |
| 250 | {0x1AB8, 0x1, 0x1, 1}, |
| 251 | /* [1:1]: RG_LDO_VAUD28_HW0_OP_EN */ |
| 252 | {0x1AC6, 0x1, 0x1, 1}, |
| 253 | /* [1:1]: RG_LDO_VAUD28_HW0_OP_CFG */ |
| 254 | {0x1ACC, 0x1, 0x1, 1}, |
| 255 | /* [0:0]: RG_LDO_VIO28_SW_OP_EN */ |
| 256 | {0x1ADA, 0x1, 0x1, 0}, |
| 257 | /* [0:0]: RG_LDO_VIO18_SW_OP_EN */ |
| 258 | {0x1AEE, 0x1, 0x1, 0}, |
| 259 | /* [2:2]: RG_LDO_VFE28_HW1_OP_EN */ |
| 260 | {0x1C0A, 0x1, 0x1, 2}, |
| 261 | /* [2:2]: RG_LDO_VFE28_HW1_OP_CFG */ |
| 262 | {0x1C10, 0x0, 0x1, 2}, |
| 263 | /* [1:1]: RG_LDO_VDRAM2_HW0_OP_EN */ |
| 264 | {0x1B0A, 0x1, 0x1, 1}, |
| 265 | /* [1:1]: RG_LDO_VDRAM2_HW0_OP_CFG */ |
| 266 | {0x1B10, 0x1, 0x1, 1}, |
| 267 | /* [0:0]: RG_LDO_VMC_SW_OP_EN */ |
| 268 | {0x1CC6, 0x1, 0x1, 0}, |
| 269 | /* [0:0]: RG_LDO_VMCH_SW_OP_EN */ |
| 270 | {0x1CDA, 0x1, 0x1, 0}, |
| 271 | /* [0:0]: RG_LDO_VEMC_SW_OP_EN */ |
| 272 | {0x1B1E, 0x1, 0x1, 0}, |
| 273 | /* [0:0]: RG_LDO_VSIM1_SW_OP_EN */ |
| 274 | {0x1D4A, 0x1, 0x1, 0}, |
| 275 | /* [0:0]: RG_LDO_VSIM2_SW_OP_EN */ |
| 276 | {0x1D5E, 0x1, 0x1, 0}, |
| 277 | /* [0:0]: RG_LDO_VIBR_SW_OP_EN */ |
| 278 | {0x1D0A, 0x1, 0x1, 0}, |
| 279 | /* [1:1]: RG_LDO_VUSB_HW0_OP_EN */ |
| 280 | {0x1B32, 0x1, 0x1, 1}, |
| 281 | /* [1:1]: RG_LDO_VUSB_HW0_OP_CFG */ |
| 282 | {0x1B38, 0x1, 0x1, 1}, |
| 283 | /* [1:1]: RG_LDO_VUSB_HW0_OP_EN */ |
| 284 | {0x1B32, 0x1, 0x1, 1}, |
| 285 | /* [1:1]: RG_LDO_VUSB_HW0_OP_CFG */ |
| 286 | {0x1B38, 0x1, 0x1, 1}, |
| 287 | /* [1:1]: RG_LDO_VBIF28_HW0_OP_EN */ |
| 288 | {0x1DA0, 0x1, 0x1, 1}, |
| 289 | /* [1:1]: RG_LDO_VBIF28_HW0_OP_CFG */ |
| 290 | {0x1DA6, 0x0, 0x1, 1}, |
| 291 | |
| 292 | /* Deep idle setting */ |
| 293 | /* [0:0]: RG_BUCK_VPROC11_SW_OP_EN */ |
| 294 | {0x1390, 0x1, 0x1, 0}, |
| 295 | /* [0:0]: RG_BUCK_VCORE_SW_OP_EN */ |
| 296 | {0x1490, 0x1, 0x1, 0}, |
| 297 | /* [0:0]: RG_BUCK_VGPU_SW_OP_EN */ |
| 298 | {0x1510, 0x1, 0x1, 0}, |
| 299 | /* [0:0]: RG_BUCK_VMODEM_SW_OP_EN */ |
| 300 | {0x1590, 0x1, 0x1, 0}, |
| 301 | /* [0:0]: RG_BUCK_VS1_SW_OP_EN */ |
| 302 | {0x1690, 0x1, 0x1, 0}, |
| 303 | /* [3:3]: RG_BUCK_VS2_HW2_OP_EN */ |
| 304 | {0x1710, 0x1, 0x1, 3}, |
| 305 | /* [3:3]: RG_BUCK_VS2_HW2_OP_CFG */ |
| 306 | {0x1716, 0x1, 0x1, 3}, |
| 307 | /* [3:3]: RG_BUCK_VDRAM1_HW2_OP_EN */ |
| 308 | {0x1610, 0x1, 0x1, 3}, |
| 309 | /* [3:3]: RG_BUCK_VDRAM1_HW2_OP_CFG */ |
| 310 | {0x1616, 0x1, 0x1, 3}, |
| 311 | /* [0:0]: RG_BUCK_VPROC12_SW_OP_EN */ |
| 312 | {0x1410, 0x1, 0x1, 0}, |
| 313 | /* [0:0]: RG_LDO_VSRAM_GPU_SW_OP_EN */ |
| 314 | {0x1BD0, 0x1, 0x1, 0}, |
| 315 | /* [3:3]: RG_LDO_VSRAM_OTHERS_HW2_OP_EN */ |
| 316 | {0x1BAE, 0x1, 0x1, 3}, |
| 317 | /* [3:3]: RG_LDO_VSRAM_OTHERS_HW2_OP_CFG */ |
| 318 | {0x1BB4, 0x1, 0x1, 3}, |
| 319 | /* [0:0]: RG_LDO_VSRAM_PROC11_SW_OP_EN */ |
| 320 | {0x1B4E, 0x1, 0x1, 0}, |
| 321 | /* [3:3]: RG_LDO_VXO22_HW2_OP_EN */ |
| 322 | {0x1A8A, 0x1, 0x1, 3}, |
| 323 | /* [3:3]: RG_LDO_VXO22_HW2_OP_CFG */ |
| 324 | {0x1A90, 0x1, 0x1, 3}, |
| 325 | /* [2:2]: RG_LDO_VRF18_HW1_OP_EN */ |
| 326 | {0x1C1E, 0x1, 0x1, 2}, |
| 327 | /* [2:2]: RG_LDO_VRF18_HW1_OP_CFG */ |
| 328 | {0x1C24, 0x0, 0x1, 2}, |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 329 | /* [0:0]: RG_LDO_VEFUSE_SW_OP_EN */ |
| 330 | {0x1C46, 0x1, 0x1, 0}, |
| 331 | /* [0:0]: RG_LDO_VCN33_SW_OP_EN */ |
| 332 | {0x1D1E, 0x1, 0x1, 0}, |
| 333 | /* [0:0]: RG_LDO_VCN33_SW_OP_EN */ |
| 334 | {0x1D1E, 0x1, 0x1, 0}, |
| 335 | /* [0:0]: RG_LDO_VCN28_SW_OP_EN */ |
| 336 | {0x1D8A, 0x1, 0x1, 0}, |
| 337 | /* [0:0]: RG_LDO_VCN18_SW_OP_EN */ |
| 338 | {0x1C5A, 0x1, 0x1, 0}, |
| 339 | /* [0:0]: RG_LDO_VCAMA1_SW_OP_EN */ |
| 340 | {0x1C6E, 0x1, 0x1, 0}, |
| 341 | /* [0:0]: RG_LDO_VCAMD_SW_OP_EN */ |
| 342 | {0x1C9E, 0x1, 0x1, 0}, |
| 343 | /* [0:0]: RG_LDO_VCAMA2_SW_OP_EN */ |
| 344 | {0x1C8A, 0x1, 0x1, 0}, |
| 345 | /* [0:0]: RG_LDO_VSRAM_PROC12_SW_OP_EN */ |
| 346 | {0x1B90, 0x1, 0x1, 0}, |
| 347 | /* [0:0]: RG_LDO_VCAMIO_SW_OP_EN */ |
| 348 | {0x1CB2, 0x1, 0x1, 0}, |
| 349 | /* [0:0]: RG_LDO_VLDO28_SW_OP_EN */ |
| 350 | {0x1D34, 0x1, 0x1, 0}, |
| 351 | /* [0:0]: RG_LDO_VLDO28_SW_OP_EN */ |
| 352 | {0x1D34, 0x1, 0x1, 0}, |
| 353 | /* [3:3]: RG_LDO_VA12_HW2_OP_EN */ |
| 354 | {0x1A9E, 0x1, 0x1, 3}, |
| 355 | /* [3:3]: RG_LDO_VA12_HW2_OP_CFG */ |
| 356 | {0x1AA4, 0x1, 0x1, 3}, |
| 357 | /* [3:3]: RG_LDO_VAUX18_HW2_OP_EN */ |
| 358 | {0x1AB2, 0x1, 0x1, 3}, |
| 359 | /* [3:3]: RG_LDO_VAUX18_HW2_OP_CFG */ |
| 360 | {0x1AB8, 0x1, 0x1, 3}, |
| 361 | /* [0:0]: RG_LDO_VAUD28_SW_OP_EN */ |
| 362 | {0x1AC6, 0x1, 0x1, 0}, |
| 363 | /* [0:0]: RG_LDO_VIO28_SW_OP_EN */ |
| 364 | {0x1ADA, 0x1, 0x1, 0}, |
| 365 | /* [0:0]: RG_LDO_VIO18_SW_OP_EN */ |
| 366 | {0x1AEE, 0x1, 0x1, 0}, |
| 367 | /* [2:2]: RG_LDO_VFE28_HW1_OP_EN */ |
| 368 | {0x1C0A, 0x1, 0x1, 2}, |
| 369 | /* [2:2]: RG_LDO_VFE28_HW1_OP_CFG */ |
| 370 | {0x1C10, 0x0, 0x1, 2}, |
| 371 | /* [3:3]: RG_LDO_VDRAM2_HW2_OP_EN */ |
| 372 | {0x1B0A, 0x1, 0x1, 3}, |
| 373 | /* [3:3]: RG_LDO_VDRAM2_HW2_OP_CFG */ |
| 374 | {0x1B10, 0x1, 0x1, 3}, |
| 375 | /* [0:0]: RG_LDO_VMC_SW_OP_EN */ |
| 376 | {0x1CC6, 0x1, 0x1, 0}, |
| 377 | /* [0:0]: RG_LDO_VMCH_SW_OP_EN */ |
| 378 | {0x1CDA, 0x1, 0x1, 0}, |
| 379 | /* [0:0]: RG_LDO_VEMC_SW_OP_EN */ |
| 380 | {0x1B1E, 0x1, 0x1, 0}, |
| 381 | /* [0:0]: RG_LDO_VSIM1_SW_OP_EN */ |
| 382 | {0x1D4A, 0x1, 0x1, 0}, |
| 383 | /* [0:0]: RG_LDO_VSIM2_SW_OP_EN */ |
| 384 | {0x1D5E, 0x1, 0x1, 0}, |
| 385 | /* [0:0]: RG_LDO_VIBR_SW_OP_EN */ |
| 386 | {0x1D0A, 0x1, 0x1, 0}, |
| 387 | /* [3:3]: RG_LDO_VUSB_HW2_OP_EN */ |
| 388 | {0x1B32, 0x1, 0x1, 3}, |
| 389 | /* [3:3]: RG_LDO_VUSB_HW2_OP_CFG */ |
| 390 | {0x1B38, 0x1, 0x1, 3}, |
| 391 | /* [3:3]: RG_LDO_VUSB_HW2_OP_EN */ |
| 392 | {0x1B32, 0x1, 0x1, 3}, |
| 393 | /* [3:3]: RG_LDO_VUSB_HW2_OP_CFG */ |
| 394 | {0x1B38, 0x1, 0x1, 3}, |
| 395 | /* [3:3]: RG_LDO_VBIF28_HW2_OP_EN */ |
| 396 | {0x1DA0, 0x1, 0x1, 3}, |
| 397 | /* [3:3]: RG_LDO_VBIF28_HW2_OP_CFG */ |
| 398 | {0x1DA6, 0x0, 0x1, 3}, |
| 399 | }; |
| 400 | |
| 401 | static struct pmic_setting scp_setting[] = { |
| 402 | /* scp voltage initialization */ |
| 403 | /* [6:0]: RG_BUCK_VCORE_SSHUB_VOSEL */ |
| 404 | {0x14A6, 0x20, 0x7F, 0}, |
| 405 | /* [14:8]: RG_BUCK_VCORE_SSHUB_VOSEL_SLEEP */ |
| 406 | {0x14A6, 0x20, 0x7F, 8}, |
| 407 | /* [0:0]: RG_BUCK_VCORE_SSHUB_EN */ |
| 408 | {0x14A4, 0x1, 0x1, 0}, |
| 409 | /* [1:1]: RG_BUCK_VCORE_SSHUB_SLEEP_VOSEL_EN */ |
| 410 | {0x14A4, 0x0, 0x1, 1}, |
| 411 | /* [6:0]: RG_LDO_VSRAM_OTHERS_SSHUB_VOSEL */ |
| 412 | {0x1BC6, 0x40, 0x7F, 0}, |
| 413 | /* [14:8]: RG_LDO_VSRAM_OTHERS_SSHUB_VOSEL_SLEEP */ |
| 414 | {0x1BC6, 0x40, 0x7F, 8}, |
| 415 | /* [0:0]: RG_LDO_VSRAM_OTHERS_SSHUB_EN */ |
| 416 | {0x1BC4, 0x1, 0x1, 0}, |
| 417 | /* [1:1]: RG_LDO_VSRAM_OTHERS_SSHUB_SLEEP_VOSEL_EN */ |
| 418 | {0x1BC4, 0x0, 0x1, 1}, |
| 419 | /* [4:4]: RG_SRCVOLTEN_LP_EN */ |
| 420 | {0x134, 0x1, 0x1, 4}, |
| 421 | }; |
| 422 | |
| 423 | static const int vddq_votrim[] = { |
| 424 | 0, -10000, -20000, -30000, -40000, -50000, -60000, -70000, |
| 425 | 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, |
| 426 | }; |
| 427 | |
Rex-BC Chen | fb6d6a9 | 2022-01-25 18:57:40 +0800 | [diff] [blame] | 428 | static void mt6366_protect_control(bool en_protect) |
| 429 | { |
| 430 | /* Write a magic number 0x9CA7 to disable protection */ |
| 431 | pwrap_write_field(PMIC_TOP_TMA_KEY, en_protect ? 0 : 0x9CA7, 0xFFFF, 0); |
| 432 | } |
| 433 | |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 434 | static u32 pmic_read_efuse(int i) |
| 435 | { |
| 436 | u32 efuse_data = 0; |
| 437 | |
| 438 | /* 1. Enable efuse ctrl engine clock */ |
| 439 | pwrap_write_field(PMIC_TOP_CKHWEN_CON0_CLR, 0x1, 0x1, 2); |
| 440 | pwrap_write_field(PMIC_TOP_CKPDN_CON0_CLR, 0x1, 0x1, 4); |
| 441 | |
| 442 | /* 2. */ |
| 443 | pwrap_write_field(PMIC_OTP_CON11, 0x1, 0x1, 0); |
| 444 | |
| 445 | /* 3. Set row to read */ |
| 446 | pwrap_write_field(PMIC_OTP_CON0, i * 2, 0xFF, 0); |
| 447 | |
| 448 | /* 4. Toggle RG_OTP_RD_TRIG */ |
| 449 | if (pwrap_read_field(PMIC_OTP_CON8, 0x1, 0) == 0) |
| 450 | pwrap_write_field(PMIC_OTP_CON8, 0x1, 0x1, 0); |
| 451 | else |
| 452 | pwrap_write_field(PMIC_OTP_CON8, 0, 0x1, 0); |
| 453 | |
| 454 | /* 5. Polling RG_OTP_RD_BUSY = 0 */ |
| 455 | udelay(300); |
| 456 | while (pwrap_read_field(PMIC_OTP_CON13, 0x1, 0) == 1) |
| 457 | ; |
| 458 | |
| 459 | /* 6. Read RG_OTP_DOUT_SW */ |
| 460 | udelay(100); |
| 461 | efuse_data = pwrap_read_field(PMIC_OTP_CON12, 0xFFFF, 0); |
| 462 | |
| 463 | /* 7. Disable efuse ctrl engine clock */ |
| 464 | pwrap_write_field(PMIC_TOP_CKHWEN_CON0_SET, 0x1, 0x1, 2); |
| 465 | pwrap_write_field(PMIC_TOP_CKPDN_CON0_SET, 0x1, 0x1, 4); |
| 466 | |
| 467 | return efuse_data; |
| 468 | } |
| 469 | |
| 470 | static int pmic_get_efuse_votrim(void) |
| 471 | { |
| 472 | const u32 cali_efuse = pmic_read_efuse(106) & 0xF; |
| 473 | assert(cali_efuse < ARRAY_SIZE(vddq_votrim)); |
| 474 | return vddq_votrim[cali_efuse]; |
| 475 | } |
| 476 | |
| 477 | static u32 pmic_get_vcore_vol(void) |
| 478 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 479 | u16 vol_reg; |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 480 | |
| 481 | vol_reg = pwrap_read_field(PMIC_VCORE_DBG0, 0x7F, 0); |
| 482 | return 500000 + vol_reg * 6250; |
| 483 | } |
| 484 | |
| 485 | static void pmic_set_vcore_vol(u32 vcore_uv) |
| 486 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 487 | u16 vol_reg; |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 488 | |
| 489 | assert(vcore_uv >= 500000); |
| 490 | assert(vcore_uv <= 1100000); |
| 491 | |
| 492 | vol_reg = (vcore_uv - 500000) / 6250; |
| 493 | |
| 494 | pwrap_write_field(PMIC_VCORE_OP_EN, 1, 0x7F, 0); |
| 495 | pwrap_write_field(PMIC_VCORE_VOSEL, vol_reg, 0x7F, 0); |
| 496 | udelay(1); |
| 497 | } |
| 498 | |
Rex-BC Chen | e7c9b53 | 2021-11-17 16:55:20 +0800 | [diff] [blame] | 499 | static u32 pmic_get_vproc12_vol(void) |
| 500 | { |
| 501 | u16 vol_reg; |
| 502 | |
| 503 | vol_reg = pwrap_read_field(PMIC_VPROC12_DBG0, 0x7F, 0); |
| 504 | return 500000 + vol_reg * 6250; |
| 505 | } |
| 506 | |
| 507 | static void pmic_set_vproc12_vol(u32 v_uv) |
| 508 | { |
| 509 | u16 vol_reg; |
| 510 | |
| 511 | assert(v_uv >= 500000); |
| 512 | assert(v_uv <= 1293750); |
| 513 | |
| 514 | vol_reg = (v_uv - 500000) / 6250; |
| 515 | |
| 516 | pwrap_write_field(PMIC_VPROC12_OP_EN, 1, 0x7F, 0); |
| 517 | pwrap_write_field(PMIC_VPROC12_VOSEL, vol_reg, 0x7F, 0); |
| 518 | udelay(1); |
| 519 | } |
| 520 | |
| 521 | static u32 pmic_get_vsram_proc12_vol(void) |
| 522 | { |
| 523 | u16 vol_reg; |
| 524 | |
| 525 | vol_reg = pwrap_read_field(PMIC_VSRAM_PROC12_DBG0, 0x7F, 0); |
| 526 | return 500000 + vol_reg * 6250; |
| 527 | } |
| 528 | |
| 529 | static void pmic_set_vsram_proc12_vol(u32 v_uv) |
| 530 | { |
| 531 | u16 vol_reg; |
| 532 | |
| 533 | assert(v_uv >= 500000); |
| 534 | assert(v_uv <= 1293750); |
| 535 | |
| 536 | vol_reg = (v_uv - 500000) / 6250; |
| 537 | |
| 538 | pwrap_write_field(PMIC_VSRAM_PROC12_OP_EN, 1, 0x7F, 0); |
| 539 | pwrap_write_field(PMIC_VSRAM_PROC12_VOSEL, vol_reg, 0x7F, 0); |
| 540 | udelay(1); |
| 541 | } |
| 542 | |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 543 | static u32 pmic_get_vdram1_vol(void) |
| 544 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 545 | u16 vol_reg; |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 546 | |
| 547 | vol_reg = pwrap_read_field(PMIC_VDRAM1_DBG0, 0x7F, 0); |
| 548 | return 500000 + vol_reg * 12500; |
| 549 | } |
| 550 | |
| 551 | static void pmic_set_vdram1_vol(u32 vdram_uv) |
| 552 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 553 | u16 vol_reg; |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 554 | |
| 555 | assert(vdram_uv >= 500000); |
| 556 | assert(vdram_uv <= 1300000); |
| 557 | |
| 558 | vol_reg = (vdram_uv - 500000) / 12500; |
| 559 | |
| 560 | pwrap_write_field(PMIC_VDRAM1_OP_EN, 1, 0x7F, 0); |
| 561 | pwrap_write_field(PMIC_VDRAM1_VOSEL, vol_reg, 0x7F, 0); |
| 562 | udelay(1); |
| 563 | } |
| 564 | |
| 565 | static u32 pmic_get_vddq_vol(void) |
| 566 | { |
| 567 | int efuse_votrim; |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 568 | u16 cali_trim; |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 569 | |
| 570 | if (!pwrap_read_field(PMIC_VDDQ_OP_EN, 0x1, 15)) |
| 571 | return 0; |
| 572 | |
| 573 | efuse_votrim = pmic_get_efuse_votrim(); |
| 574 | cali_trim = pwrap_read_field(PMIC_VDDQ_ELR_0, 0xF, 0); |
| 575 | assert(cali_trim < ARRAY_SIZE(vddq_votrim)); |
| 576 | return 600 * 1000 - efuse_votrim + vddq_votrim[cali_trim]; |
| 577 | } |
| 578 | |
| 579 | static void pmic_set_vddq_vol(u32 vddq_uv) |
| 580 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 581 | int target_mv, dram2_ori_mv, cali_offset_uv; |
| 582 | u16 cali_trim; |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 583 | |
| 584 | assert(vddq_uv >= 530000); |
| 585 | assert(vddq_uv <= 680000); |
| 586 | |
| 587 | /* Round down to multiple of 10 */ |
| 588 | target_mv = (vddq_uv / 1000) / 10 * 10; |
| 589 | |
| 590 | dram2_ori_mv = 600 - pmic_get_efuse_votrim() / 1000; |
| 591 | cali_offset_uv = 1000 * (target_mv - dram2_ori_mv); |
| 592 | |
| 593 | if (cali_offset_uv >= 80000) |
| 594 | cali_trim = 8; |
| 595 | else if (cali_offset_uv <= -70000) |
| 596 | cali_trim = 7; |
| 597 | else { |
| 598 | cali_trim = 0; |
| 599 | while (cali_trim < ARRAY_SIZE(vddq_votrim) && |
| 600 | vddq_votrim[cali_trim] != cali_offset_uv) |
| 601 | ++cali_trim; |
| 602 | assert(cali_trim < ARRAY_SIZE(vddq_votrim)); |
| 603 | } |
| 604 | |
Rex-BC Chen | fb6d6a9 | 2022-01-25 18:57:40 +0800 | [diff] [blame] | 605 | mt6366_protect_control(false); |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 606 | pwrap_write_field(PMIC_VDDQ_ELR_0, cali_trim, 0xF, 0); |
Rex-BC Chen | fb6d6a9 | 2022-01-25 18:57:40 +0800 | [diff] [blame] | 607 | mt6366_protect_control(true); |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 608 | udelay(1); |
| 609 | } |
| 610 | |
Rex-BC Chen | dc4c2b9 | 2021-10-28 17:17:14 +0800 | [diff] [blame] | 611 | static u32 pmic_get_vmch_vol(void) |
| 612 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 613 | u32 ret; |
| 614 | u16 vol_reg; |
Rex-BC Chen | dc4c2b9 | 2021-10-28 17:17:14 +0800 | [diff] [blame] | 615 | |
| 616 | vol_reg = pwrap_read_field(PMIC_VMCH_ANA_CON0, 0x7, 8); |
| 617 | |
| 618 | switch (vol_reg) { |
| 619 | case 2: |
| 620 | ret = 2900000; |
| 621 | break; |
| 622 | case 3: |
| 623 | ret = 3000000; |
| 624 | break; |
| 625 | case 5: |
| 626 | ret = 3300000; |
| 627 | break; |
| 628 | default: |
| 629 | printk(BIOS_ERR, "ERROR[%s] VMCH read fail: %d\n", __func__, vol_reg); |
| 630 | ret = 0; |
| 631 | break; |
| 632 | } |
| 633 | return ret; |
| 634 | } |
| 635 | |
| 636 | static void pmic_set_vmch_vol(u32 vmch_uv) |
| 637 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 638 | u16 val = 0; |
Rex-BC Chen | dc4c2b9 | 2021-10-28 17:17:14 +0800 | [diff] [blame] | 639 | |
| 640 | switch (vmch_uv) { |
| 641 | case 2900000: |
| 642 | val = 2; |
| 643 | break; |
| 644 | case 3000000: |
| 645 | val = 3; |
| 646 | break; |
| 647 | case 3300000: |
| 648 | val = 5; |
| 649 | break; |
| 650 | default: |
| 651 | die("ERROR[%s]: VMCH voltage %u is not support.\n", __func__, vmch_uv); |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | pwrap_write_field(PMIC_VMCH_ANA_CON0, val, 0x7, 8); |
| 656 | |
| 657 | /* Force SW to turn on */ |
| 658 | pwrap_write_field(PMIC_LDO_VMCH_OP_EN, 1, 0xFF, 0); |
| 659 | pwrap_write_field(PMIC_LDO_VMCH_CON0, 1, 0xFF, 0); |
| 660 | } |
| 661 | |
| 662 | static u32 pmic_get_vmc_vol(void) |
| 663 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 664 | u32 ret; |
| 665 | u16 vol_reg; |
Rex-BC Chen | dc4c2b9 | 2021-10-28 17:17:14 +0800 | [diff] [blame] | 666 | |
| 667 | vol_reg = pwrap_read_field(PMIC_VMC_ANA_CON0, 0xF, 8); |
| 668 | |
| 669 | switch (vol_reg) { |
| 670 | case 0x4: |
| 671 | ret = 1800000; |
| 672 | break; |
| 673 | case 0xA: |
| 674 | ret = 2900000; |
| 675 | break; |
| 676 | case 0xB: |
| 677 | ret = 3000000; |
| 678 | break; |
| 679 | case 0xD: |
| 680 | ret = 3300000; |
| 681 | break; |
| 682 | default: |
| 683 | printk(BIOS_ERR, "ERROR[%s] VMC read fail: %d\n", __func__, vol_reg); |
| 684 | ret = 0; |
| 685 | break; |
| 686 | } |
| 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | static void pmic_set_vmc_vol(u32 vmc_uv) |
| 691 | { |
Rex-BC Chen | 4b6c2b8 | 2021-11-23 15:20:02 +0800 | [diff] [blame] | 692 | u16 val = 0; |
Rex-BC Chen | dc4c2b9 | 2021-10-28 17:17:14 +0800 | [diff] [blame] | 693 | |
| 694 | switch (vmc_uv) { |
| 695 | case 1800000: |
| 696 | val = 0x4; |
| 697 | break; |
| 698 | case 2900000: |
| 699 | val = 0xA; |
| 700 | break; |
| 701 | case 3000000: |
| 702 | val = 0xB; |
| 703 | break; |
| 704 | case 3300000: |
| 705 | val = 0xD; |
| 706 | break; |
| 707 | default: |
| 708 | die("ERROR[%s]: VMC voltage %u is not support.\n", __func__, vmc_uv); |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | pwrap_write_field(PMIC_VMC_ANA_CON0, val, 0xF, 8); |
| 713 | |
| 714 | /* Force SW to turn on */ |
| 715 | pwrap_write_field(PMIC_LDO_VMC_OP_EN, 1, 0xFF, 0); |
| 716 | pwrap_write_field(PMIC_LDO_VMC_CON0, 1, 0xFF, 0); |
| 717 | } |
| 718 | |
Rex-BC Chen | 0069f6a | 2021-12-28 13:07:06 +0800 | [diff] [blame] | 719 | static u32 pmic_get_vrf12_vol(void) |
| 720 | { |
| 721 | return (pwrap_read_field(PMIC_LDO_VRF12_CON0, 0x3, 0) & |
| 722 | pwrap_read_field(PMIC_LDO_VRF12_OP_EN, 0x3, 0)) ? 1200000 : 0; |
| 723 | } |
| 724 | |
| 725 | static void pmic_enable_vrf12(void) |
| 726 | { |
| 727 | pwrap_write_field(PMIC_LDO_VRF12_CON0, 1, 0x3, 0); |
| 728 | pwrap_write_field(PMIC_LDO_VRF12_OP_EN, 1, 0x3, 0); |
| 729 | } |
| 730 | |
| 731 | static u32 pmic_get_vcn33_vol(void) |
| 732 | { |
| 733 | u32 ret; |
| 734 | u16 vol_reg; |
| 735 | |
| 736 | vol_reg = pwrap_read_field(PMIC_VCN33_ANA_CON0, 0x3, 8); |
| 737 | |
| 738 | switch (vol_reg) { |
| 739 | case 0x1: |
| 740 | ret = 3300000; |
| 741 | break; |
| 742 | case 0x2: |
| 743 | ret = 3400000; |
| 744 | break; |
| 745 | case 0x3: |
| 746 | ret = 3500000; |
| 747 | break; |
| 748 | default: |
| 749 | printk(BIOS_ERR, "ERROR[%s] VCN33 read fail: %d\n", __func__, vol_reg); |
| 750 | ret = 0; |
| 751 | break; |
| 752 | } |
| 753 | return ret; |
| 754 | } |
| 755 | |
| 756 | static void pmic_set_vcn33_vol(u32 vcn33_uv) |
| 757 | { |
| 758 | u16 val = 0; |
| 759 | |
| 760 | switch (vcn33_uv) { |
| 761 | case 3300000: |
| 762 | val = 0x1; |
| 763 | break; |
| 764 | case 3400000: |
| 765 | val = 0x2; |
| 766 | break; |
| 767 | case 3500000: |
| 768 | val = 0x3; |
| 769 | break; |
| 770 | default: |
| 771 | die("ERROR[%s]: VCN33 voltage %u is not support.\n", __func__, vcn33_uv); |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | pwrap_write_field(PMIC_VCN33_ANA_CON0, val, 0x3, 8); |
| 776 | |
| 777 | /* Force SW to turn on */ |
| 778 | pwrap_write_field(PMIC_LDO_VCN33_CON0_0, 1, 0x1, 0); |
| 779 | } |
| 780 | |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 781 | static void pmic_wdt_set(void) |
| 782 | { |
| 783 | /* [5]=1, RG_WDTRSTB_DEB */ |
| 784 | pwrap_write_field(PMIC_TOP_RST_MISC_SET, 0x0020, 0xFFFF, 0); |
| 785 | /* [1]=0, RG_WDTRSTB_MODE */ |
| 786 | pwrap_write_field(PMIC_TOP_RST_MISC_CLR, 0x0002, 0xFFFF, 0); |
| 787 | /* [0]=1, RG_WDTRSTB_EN */ |
| 788 | pwrap_write_field(PMIC_TOP_RST_MISC_SET, 0x0001, 0xFFFF, 0); |
| 789 | } |
| 790 | |
| 791 | static void mt6366_init_setting(void) |
| 792 | { |
Rex-BC Chen | fb6d6a9 | 2022-01-25 18:57:40 +0800 | [diff] [blame] | 793 | mt6366_protect_control(false); |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 794 | for (size_t i = 0; i < ARRAY_SIZE(init_setting); i++) |
| 795 | pwrap_write_field( |
| 796 | init_setting[i].addr, init_setting[i].val, |
| 797 | init_setting[i].mask, init_setting[i].shift); |
Rex-BC Chen | fb6d6a9 | 2022-01-25 18:57:40 +0800 | [diff] [blame] | 798 | mt6366_protect_control(true); |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | static void wk_sleep_voltage_by_ddr(void) |
| 802 | { |
| 803 | if (pwrap_read_field(PMIC_VM_MODE, 0x3, 0) == 0x2) |
| 804 | pwrap_write_field(PMIC_VDRAM1_VOSEL_SLEEP, 0x3A, 0x7F, 0); |
| 805 | } |
| 806 | |
| 807 | static void wk_power_down_seq(void) |
| 808 | { |
Rex-BC Chen | fb6d6a9 | 2022-01-25 18:57:40 +0800 | [diff] [blame] | 809 | mt6366_protect_control(false); |
zhiyong tao | c53a0aa | 2022-05-04 10:46:12 +0800 | [diff] [blame] | 810 | /* Set VPROC12 power-down time slot to 0xF to avoid 20ms delay */ |
| 811 | pwrap_write_field(PMIC_CPSDSA4, 0xF, 0x1F, 0); |
Rex-BC Chen | fb6d6a9 | 2022-01-25 18:57:40 +0800 | [diff] [blame] | 812 | mt6366_protect_control(true); |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | static void mt6366_lp_setting(void) |
| 816 | { |
| 817 | for (size_t i = 0; i < ARRAY_SIZE(lp_setting); i++) |
| 818 | pwrap_write_field( |
| 819 | lp_setting[i].addr, lp_setting[i].val, |
| 820 | lp_setting[i].mask, lp_setting[i].shift); |
| 821 | } |
| 822 | |
| 823 | static void pmic_check_hwcid(void) |
| 824 | { |
Rex-BC Chen | 69e3cab | 2022-03-14 14:37:44 +0800 | [diff] [blame] | 825 | printk(BIOS_INFO, "%s: ID = %#x\n", __func__, |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 826 | pwrap_read_field(0x8, 0xFFFF, 0)); |
| 827 | } |
| 828 | |
| 829 | void mt6366_set_power_hold(bool enable) |
| 830 | { |
| 831 | pwrap_write_field(PMIC_PWRHOLD, (enable) ? 1 : 0, 0x1, 0); |
| 832 | } |
| 833 | |
| 834 | void mt6366_init_scp_voltage(void) |
| 835 | { |
| 836 | for (size_t i = 0; i < ARRAY_SIZE(scp_setting); i++) |
| 837 | pwrap_write_field( |
| 838 | scp_setting[i].addr, scp_setting[i].val, |
| 839 | scp_setting[i].mask, scp_setting[i].shift); |
| 840 | } |
| 841 | |
| 842 | void mt6366_set_vsim2_cali_mv(u32 vsim2_mv) |
| 843 | { |
| 844 | u16 vsim2_reg, cali_mv; |
| 845 | |
| 846 | cali_mv = vsim2_mv % 100; |
| 847 | assert(cali_mv % 10 == 0); |
| 848 | |
| 849 | switch (vsim2_mv - cali_mv) { |
| 850 | case 1700: |
| 851 | vsim2_reg = 0x3; |
| 852 | break; |
| 853 | case 1800: |
| 854 | vsim2_reg = 0x4; |
| 855 | break; |
| 856 | case 2700: |
| 857 | vsim2_reg = 0x8; |
| 858 | break; |
| 859 | case 3000: |
| 860 | vsim2_reg = 0xb; |
| 861 | break; |
| 862 | case 3100: |
| 863 | vsim2_reg = 0xc; |
| 864 | break; |
| 865 | default: |
| 866 | printk(BIOS_ERR, "%s: voltage %d is not supported\n", __func__, vsim2_mv); |
| 867 | return; |
| 868 | }; |
| 869 | |
| 870 | /* [11:8]=0x8, RG_VSIM2_VOSEL */ |
| 871 | pwrap_write_field(PMIC_VSIM2_ANA_CON0, vsim2_reg, 0xF, 8); |
| 872 | |
| 873 | /* [3:0], RG_VSIM2_VOCAL */ |
| 874 | pwrap_write_field(PMIC_VSIM2_ANA_CON0, cali_mv / 10, 0xF, 0); |
| 875 | } |
| 876 | |
| 877 | void mt6366_set_voltage(enum mt6366_regulator_id id, u32 voltage_uv) |
| 878 | { |
| 879 | switch (id) { |
| 880 | case MT6366_VCORE: |
| 881 | pmic_set_vcore_vol(voltage_uv); |
| 882 | break; |
| 883 | case MT6366_VDRAM1: |
| 884 | pmic_set_vdram1_vol(voltage_uv); |
| 885 | break; |
| 886 | case MT6366_VDDQ: |
| 887 | pmic_set_vddq_vol(voltage_uv); |
| 888 | break; |
Rex-BC Chen | dc4c2b9 | 2021-10-28 17:17:14 +0800 | [diff] [blame] | 889 | case MT6366_VMCH: |
| 890 | pmic_set_vmch_vol(voltage_uv); |
| 891 | break; |
| 892 | case MT6366_VMC: |
| 893 | pmic_set_vmc_vol(voltage_uv); |
| 894 | break; |
Rex-BC Chen | e7c9b53 | 2021-11-17 16:55:20 +0800 | [diff] [blame] | 895 | case MT6366_VPROC12: |
| 896 | pmic_set_vproc12_vol(voltage_uv); |
| 897 | break; |
| 898 | case MT6366_VSRAM_PROC12: |
| 899 | pmic_set_vsram_proc12_vol(voltage_uv); |
| 900 | break; |
Rex-BC Chen | 0069f6a | 2021-12-28 13:07:06 +0800 | [diff] [blame] | 901 | case MT6366_VRF12: |
| 902 | /* VRF12 only provides 1.2V, so we just need to enable it */ |
| 903 | pmic_enable_vrf12(); |
| 904 | break; |
| 905 | case MT6366_VCN33: |
| 906 | pmic_set_vcn33_vol(voltage_uv); |
| 907 | break; |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 908 | default: |
| 909 | printk(BIOS_ERR, "%s: PMIC %d is not supported\n", __func__, id); |
| 910 | break; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | u32 mt6366_get_voltage(enum mt6366_regulator_id id) |
| 915 | { |
| 916 | switch (id) { |
| 917 | case MT6366_VCORE: |
| 918 | return pmic_get_vcore_vol(); |
| 919 | case MT6366_VDRAM1: |
| 920 | return pmic_get_vdram1_vol(); |
| 921 | case MT6366_VDDQ: |
| 922 | return pmic_get_vddq_vol(); |
Rex-BC Chen | dc4c2b9 | 2021-10-28 17:17:14 +0800 | [diff] [blame] | 923 | case MT6366_VMCH: |
| 924 | return pmic_get_vmch_vol(); |
| 925 | case MT6366_VMC: |
| 926 | return pmic_get_vmc_vol(); |
Rex-BC Chen | e7c9b53 | 2021-11-17 16:55:20 +0800 | [diff] [blame] | 927 | case MT6366_VPROC12: |
| 928 | return pmic_get_vproc12_vol(); |
| 929 | case MT6366_VSRAM_PROC12: |
| 930 | return pmic_get_vsram_proc12_vol(); |
Rex-BC Chen | 0069f6a | 2021-12-28 13:07:06 +0800 | [diff] [blame] | 931 | case MT6366_VRF12: |
| 932 | return pmic_get_vrf12_vol(); |
| 933 | case MT6366_VCN33: |
| 934 | return pmic_get_vcn33_vol(); |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 935 | default: |
| 936 | printk(BIOS_ERR, "%s: PMIC %d is not supported\n", __func__, id); |
| 937 | break; |
| 938 | } |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | void mt6366_init(void) |
| 943 | { |
| 944 | struct stopwatch voltage_settled; |
| 945 | |
| 946 | if (pwrap_init()) |
| 947 | die("ERROR - Failed to initialize pmic wrap!"); |
| 948 | |
| 949 | pmic_check_hwcid(); |
| 950 | mt6366_set_power_hold(true); |
| 951 | pmic_wdt_set(); |
| 952 | mt6366_init_setting(); |
| 953 | stopwatch_init_usecs_expire(&voltage_settled, 200); |
| 954 | wk_sleep_voltage_by_ddr(); |
| 955 | wk_power_down_seq(); |
| 956 | mt6366_lp_setting(); |
Zhiyong Tao | a747770 | 2022-03-24 18:57:44 +0800 | [diff] [blame] | 957 | pmif_spmi_set_lp_mode(); |
James Lo | 1e0765d | 2021-10-05 18:14:12 +0800 | [diff] [blame] | 958 | |
| 959 | while (!stopwatch_expired(&voltage_settled)) |
| 960 | /* wait for voltages to settle */; |
| 961 | } |