rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2012 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Filename: |
| 38 | * --------- |
| 39 | * pcie.c |
| 40 | * |
| 41 | * Project: |
| 42 | * -------- |
| 43 | * VMOLY |
| 44 | * |
| 45 | * Description: |
| 46 | * ------------ |
| 47 | * PCIE device driver |
| 48 | * |
| 49 | * Author: |
| 50 | * ------- |
| 51 | * ------- |
| 52 | * |
| 53 | * ========================================================================== |
| 54 | * $Log$ |
| 55 | * |
| 56 | * 11 11 2020 cindy.tu |
| 57 | * [MOLY00520457] [PCIE][Colgin] PCIE driver |
| 58 | * |
| 59 | * 11 11 2020 cindy.tu |
| 60 | * [MOLY00520457] [PCIE][Colgin] PCIE driver |
| 61 | * |
| 62 | * Sync to MD700. |
| 63 | * |
| 64 | * 11 09 2020 cindy.tu |
| 65 | * [MOLY00591928] [MT6880][Colgin][PCIE][RDIT]Potential race condition in PERST interrupt handing flow |
| 66 | * |
| 67 | * 10 09 2020 cindy.tu |
| 68 | * [MOLY00579078] [MT6880][Colgin][M.2][Low Power] Colgin Data Card(連 RVP) Flight mode suspend current: 4.3 mA > target 4.1 mA |
| 69 | * |
| 70 | * . |
| 71 | * |
| 72 | * 09 28 2020 cindy.tu |
| 73 | * [MOLY00573840] [MT6880][Colgin][M.2][Low Power] Colgin Data Card(連 RVP) Flight mode suspend current: 5.6 mA > target 4.2 mA |
| 74 | * |
| 75 | * 09 03 2020 cindy.tu |
| 76 | * [MOLY00520457] [PCIE][Colgin] PCIE driver |
| 77 | * |
| 78 | * Update L2 flow |
| 79 | * |
| 80 | * 08 19 2020 cody.lee |
| 81 | * [MOLY00557699] [Colgin] MTCMOS CTRL API - bus protection fix |
| 82 | * + SRAM chain |
| 83 | * |
| 84 | * 08 04 2020 cindy.tu |
| 85 | * [MOLY00520457] [PCIE][Colgin] PCIE driver |
| 86 | * |
| 87 | * Merge PCIE driver to T700 branch |
| 88 | * |
| 89 | * 07 13 2020 cody.lee |
| 90 | * [MOLY00545672] [Colgin] PCIE MTCMOS CTRL API |
| 91 | * |
| 92 | * 07 06 2020 cindy.tu |
| 93 | * [MOLY00520457] [PCIE][Colgin] PCIE driver |
| 94 | * |
| 95 | * Sync PCIE to MT6880 MP. |
| 96 | * |
| 97 | * 05 27 2020 cindy.tu |
| 98 | * [MOLY00520457] [PCIE][Colgin] PCIE driver |
| 99 | * |
| 100 | * Fix build error. |
| 101 | * |
| 102 | * 05 05 2020 cindy.tu |
| 103 | * [MOLY00520457] [PCIE][Colgin] PCIE driver |
| 104 | * |
| 105 | * 04 30 2020 cindy.tu |
| 106 | * [MOLY00518788] [PCIE][Mercury] PCIE link API |
| 107 | * EWSP0000108141 |
| 108 | * |
| 109 | * 04 16 2020 cindy.tu |
| 110 | * [MOLY00503259] [PCIE][M70] PCIE link API |
| 111 | * |
| 112 | * [PCIE] Integrate with MHCCIF and add test cases. |
| 113 | * |
| 114 | * 03 05 2020 cindy.tu |
| 115 | * [MOLY00503259] [PCIE][M70] PCIE link API |
| 116 | * |
| 117 | * [SWRD]M70 PCIE. |
| 118 | * |
| 119 | * |
| 120 | ****************************************************************************/ |
| 121 | |
| 122 | #include "kal_public_api.h" |
| 123 | #include "drv_comm.h" |
| 124 | #include "pcie_if.h" |
| 125 | #include "pcie_mac.h" |
| 126 | #include "pcie_dbg.h" |
| 127 | #include "pcie.h" |
| 128 | |
| 129 | #define STA_POWER_ON 1 |
| 130 | #define STA_POWER_DOWN 0 |
| 131 | |
| 132 | /* Define MTCMOS Power Status Mask */ |
| 133 | #define PCIE_PWR_STA_MASK (0x1 << 10) |
| 134 | #define MCUSYS_SPMC_PWR_STA_MASK (0x1 << 14) |
| 135 | |
| 136 | /* Define MTCMOS Bus Protect Mask */ |
| 137 | #define PCIE_PROT_STEP1_0_MASK ((0x1 << 6) \ |
| 138 | |(0x1 << 17) \ |
| 139 | |(0x1 << 18)) |
| 140 | #define PCIE_PROT_STEP1_0_ACK_MASK ((0x1 << 6) \ |
| 141 | |(0x1 << 17) \ |
| 142 | |(0x1 << 18)) |
| 143 | #define PCIE_PROT_STEP2_0_MASK ((0x1 << 16) \ |
| 144 | |(0x1 << 19) \ |
| 145 | |(0x1 << 20) \ |
| 146 | |(0x1 << 24)) |
| 147 | #define PCIE_PROT_STEP2_0_ACK_MASK ((0x1 << 16) \ |
| 148 | |(0x1 << 19) \ |
| 149 | |(0x1 << 20) \ |
| 150 | |(0x1 << 24)) |
| 151 | |
| 152 | #define PCIE_SW_CG_1 ((0x1 << 15) | (0x1 <<18) | (0x1 << 19)) |
| 153 | #define PCIE_SW_CG_3 ((0x1 <<15) | (0x1 << 27)) |
| 154 | #define PCIE_SW_CG_4 ((0x1 << 13) | (0x1 << 22) | (0x1 <<23) | (0x1 << 24)) |
| 155 | |
| 156 | /* Define Non-CPU SRAM Mask */ |
| 157 | #define MD1_SRAM_PDN (0x1 << 8) //MD1_PWR_CON 0x300 //PCIE_SRAM_PDN |
| 158 | #define MD1_SRAM_PDN_ACK (0x0 << 12) //PCIE_SRAM_PDN_ACK |
| 159 | #define MD1_SRAM_PDN_ACK_BIT0 (0x1 << 12) //PCIE_SRAM_PDN_ACK_BIT0 |
| 160 | |
| 161 | #define PEXTP_D_2LX1_PWR_ACK_IDX 12 |
| 162 | #define PEXTP_D_2LX1_PHY_PWR_ACK_IDX 3 |
| 163 | |
| 164 | /* Define MTCMOS power control */ |
| 165 | #define PWR_RST_B (0x1 << 0) |
| 166 | #define PWR_ISO (0x1 << 1) |
| 167 | #define PWR_ON (0x1 << 2) |
| 168 | #define PWR_ON_2ND (0x1 << 3) |
| 169 | #define PWR_CLK_DIS (0x1 << 4) |
| 170 | #define SRAM_PD_OFFSET (0x1 << 8) |
| 171 | #define SRAM_PD_ACK_OFFSET (0x1 << 12) |
| 172 | |
| 173 | #ifdef CHIP10992 |
| 174 | #define SPM_BASE (BASE_INFRA_AO_SLEEP_CTRL) |
| 175 | #else |
| 176 | #define SPM_BASE 0 |
| 177 | #endif |
| 178 | #define POWERON_CONFIG_EN (SPM_BASE + 0x0000) |
| 179 | #define PWR_STATUS (SPM_BASE + 0x016C) |
| 180 | #define PWR_STATUS_2ND (SPM_BASE + 0x0170) |
| 181 | #define MCUPM_PWR_CON (SPM_BASE + 0x03C0) //PCIE_PWR_CON |
| 182 | |
| 183 | #define PEXTP_D_2LX1_PWR_CON (SPM_BASE + 0x330) |
| 184 | #define PEXTP_D_2LX1_PHY_PWR_CON (SPM_BASE + 0x30C) |
| 185 | |
| 186 | #define SPM_PROJECT_CODE 0xb16 |
| 187 | #define SPM_REGWR_CFG_KEY (SPM_PROJECT_CODE << 16) |
| 188 | |
| 189 | #define INFRA_TOPAXI_PROTECTEN_SET (BASE_INFRA_AO_CONFIG + 0x02A0) |
| 190 | #define INFRA_TOPAXI_PROTECTEN_CLR (BASE_INFRA_AO_CONFIG + 0x02A4) |
| 191 | #define INFRA_TOPAXI_PROTECTEN_STA1 (BASE_INFRA_AO_CONFIG + 0x0228) |
| 192 | |
| 193 | #define INFRA_TOPAXI_PROTECTEN_1_SET (BASE_INFRA_AO_CONFIG + 0x2A8) |
| 194 | #define INFRA_TOPAXI_PROTECTEN_1_CLR (BASE_INFRA_AO_CONFIG + 0x2AC) |
| 195 | #define INFRA_TOPAXI_PROTECTEN_STA1_1 (BASE_INFRA_AO_CONFIG + 0x258) |
| 196 | |
| 197 | #define INFRA_TOPAXI_PROTECTEN_SET_2 (BASE_INFRA_AO_CONFIG + 0x714) |
| 198 | #define INFRA_TOPAXI_PROTECTEN_CLR_2 (BASE_INFRA_AO_CONFIG + 0x718) |
| 199 | #define INFRA_TOPAXI_PROTECTEN_STA1_2 (BASE_INFRA_AO_CONFIG + 0x724) |
| 200 | |
| 201 | #define INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_SET (BASE_INFRA_AO_CONFIG + 0xB84) |
| 202 | #define INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_CLR (BASE_INFRA_AO_CONFIG + 0xB88) |
| 203 | #define INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_STA1 (BASE_INFRA_AO_CONFIG + 0xB90) |
| 204 | |
| 205 | #define INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_SET_1 (BASE_INFRA_AO_CONFIG + 0xBA4) |
| 206 | #define INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_CLR_1 (BASE_INFRA_AO_CONFIG + 0xBA8) |
| 207 | #define INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_STA1_1 (BASE_INFRA_AO_CONFIG + 0xBB0) |
| 208 | |
| 209 | #define INFRA_TOPAXI_PROTECTEN_MM_SET (BASE_INFRA_AO_CONFIG + 0x2D4) |
| 210 | #define INFRA_TOPAXI_PROTECTEN_MM_CLR (BASE_INFRA_AO_CONFIG + 0x2D8) |
| 211 | #define INFRA_TOPAXI_PROTECTEN_MM_STA1 (BASE_INFRA_AO_CONFIG + 0x2EC) |
| 212 | |
| 213 | #define INFRA_TOPAXI_MODULE_SW_CG_1_SET (BASE_INFRA_AO_CONFIG + 0x088) |
| 214 | #define INFRA_TOPAXI_MODULE_SW_CG_1_CLR (BASE_INFRA_AO_CONFIG + 0x08C) |
| 215 | #define INFRA_TOPAXI_MODULE_SW_CG_3_SET (BASE_INFRA_AO_CONFIG + 0x0C0) |
| 216 | #define INFRA_TOPAXI_MODULE_SW_CG_3_CLR (BASE_INFRA_AO_CONFIG + 0x0C4) |
| 217 | #define INFRA_TOPAXI_MODULE_SW_CG_4_SET (BASE_INFRA_AO_CONFIG + 0x0E0) |
| 218 | #define INFRA_TOPAXI_MODULE_SW_CG_4_CLR (BASE_INFRA_AO_CONFIG + 0x0E4) |
| 219 | |
| 220 | #define TOPRGU_WDT_SWSYSRST (BASE_INFRA_AO_TOPRGU + 0x0018) |
| 221 | |
| 222 | PCIE_detect_result_e g_pcie_detect_result = PCIE_LINK_UNKNOWN; |
| 223 | |
| 224 | void spm_mtcmos_rsb_on(kal_uint32 reg_addr, int ack_index); |
| 225 | void spm_mtcmos_rsb_off(kal_uint32 reg_addr, int ack_index); |
| 226 | |
| 227 | extern kal_uint32 g_ltssm; |
| 228 | extern kal_uint32 Plat_SW_Code(void); |
| 229 | |
| 230 | #ifdef CHIP10992 |
| 231 | void toprgu_ctrl_pcie_off(void) |
| 232 | { |
| 233 | /* Set PCIE PHY ip+reset_mode */ |
| 234 | DRV_WriteReg32(TOPRGU_WDT_SWSYSRST, (DRV_Reg32(TOPRGU_WDT_SWSYSRST) & 0x00EFFFFF) | 0x88100000); |
| 235 | } |
| 236 | #endif |
| 237 | |
| 238 | #ifdef MT6298 |
| 239 | void phy_ctrl_pcie_off(void) |
| 240 | { |
| 241 | DRV_WriteReg32(0xC1F80020, (DRV_Reg32(0xC1F80020) | 0x1) ); |
| 242 | } |
| 243 | #endif |
| 244 | |
| 245 | void spm_mtcmos_ctrl_pcie(int state) |
| 246 | { |
| 247 | /* TINFO="enable SPM register control" */ |
| 248 | DRV_WriteReg32(POWERON_CONFIG_EN, (SPM_PROJECT_CODE << 16) | (0x1 << 0)); |
| 249 | |
| 250 | if (state == STA_POWER_DOWN) { |
| 251 | /* TINFO="Start to turn off PCIE" */ |
| 252 | /* TINFO="Set bus protect - step1 : 0" */ |
| 253 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_SET, PCIE_PROT_STEP1_0_MASK); |
| 254 | #ifndef IGNORE_MTCMOS_CHECK |
| 255 | while ((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_STA1) & PCIE_PROT_STEP1_0_ACK_MASK) != PCIE_PROT_STEP1_0_ACK_MASK) { |
| 256 | } |
| 257 | #endif |
| 258 | /* TINFO="Set bus protect - step2 : 0" */ |
| 259 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_SET, PCIE_PROT_STEP2_0_MASK); |
| 260 | #ifndef IGNORE_MTCMOS_CHECK |
| 261 | while ((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_STA1) & PCIE_PROT_STEP2_0_ACK_MASK) != PCIE_PROT_STEP2_0_ACK_MASK) { |
| 262 | } |
| 263 | #endif |
| 264 | /* TINFO="Set SRAM_PDN = 1" */ |
| 265 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) | MD1_SRAM_PDN); |
| 266 | #ifndef IGNORE_MTCMOS_CHECK |
| 267 | /* TINFO="Wait until MD1_SRAM_PDN_ACK = 1" */ |
| 268 | while ((DRV_Reg32(MCUPM_PWR_CON) & MD1_SRAM_PDN_ACK) != MD1_SRAM_PDN_ACK) { |
| 269 | /* Need f_fsmi_ck for SRAM PDN delay IP. */ |
| 270 | } |
| 271 | #endif |
| 272 | /* TINFO="Set PWR_ISO = 1" */ |
| 273 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) | PWR_ISO); |
| 274 | /* TINFO="Set PWR_CLK_DIS = 1" */ |
| 275 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) | PWR_CLK_DIS); |
| 276 | /* TINFO="Set PWR_RST_B = 0" */ |
| 277 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) & ~PWR_RST_B); |
| 278 | /* TINFO="Set PWR_ON = 0" */ |
| 279 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) & ~PWR_ON); |
| 280 | /* TINFO="Set PWR_ON_2ND = 0" */ |
| 281 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) & ~PWR_ON_2ND); |
| 282 | #ifndef IGNORE_MTCMOS_CHECK |
| 283 | /* TINFO="Wait until PWR_STATUS = 0 and PWR_STATUS_2ND = 0" */ |
| 284 | while ((DRV_Reg32(PWR_STATUS) & PCIE_PWR_STA_MASK) |
| 285 | || (DRV_Reg32(PWR_STATUS_2ND) & PCIE_PWR_STA_MASK)) { |
| 286 | /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */ |
| 287 | } |
| 288 | #endif |
| 289 | /* TINFO="Finish to turn off PCIE" */ |
| 290 | } else { /* STA_POWER_ON */ |
| 291 | /* TINFO="Start to turn on PCIE" */ |
| 292 | /* TINFO="Set PWR_ON = 1" */ |
| 293 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) | PWR_ON); |
| 294 | /* TINFO="Set PWR_ON_2ND = 1" */ |
| 295 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) | PWR_ON_2ND); |
| 296 | #ifndef IGNORE_MTCMOS_CHECK |
| 297 | /* TINFO="Wait until PWR_STATUS = 1 and PWR_STATUS_2ND = 1" */ |
| 298 | while (((DRV_Reg32(PWR_STATUS) & PCIE_PWR_STA_MASK) != PCIE_PWR_STA_MASK) |
| 299 | || ((DRV_Reg32(PWR_STATUS_2ND) & PCIE_PWR_STA_MASK) != PCIE_PWR_STA_MASK)) { |
| 300 | /* No logic between pwr_on and pwr_ack. Print SRAM / MTCMOS control and PWR_ACK for debug. */ |
| 301 | } |
| 302 | #endif |
| 303 | /* TINFO="Set PWR_CLK_DIS = 0" */ |
| 304 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) & ~PWR_CLK_DIS); |
| 305 | /* TINFO="Set PWR_ISO = 0" */ |
| 306 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) & ~PWR_ISO); |
| 307 | /* TINFO="Set PWR_RST_B = 1" */ |
| 308 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) | PWR_RST_B); |
| 309 | /* TINFO="Set SRAM_PDN = 0" */ |
| 310 | DRV_WriteReg32(MCUPM_PWR_CON, DRV_Reg32(MCUPM_PWR_CON) & ~(0x1 << 8)); |
| 311 | #ifndef IGNORE_MTCMOS_CHECK |
| 312 | /* TINFO="Wait until MD1_SRAM_PDN_ACK = 0" */ |
| 313 | while (DRV_Reg32(MCUPM_PWR_CON) & MD1_SRAM_PDN_ACK) { |
| 314 | /* Need f_fsmi_ck for SRAM PDN delay IP. */ |
| 315 | } |
| 316 | #endif |
| 317 | /* TINFO="Release bus protect - step2 : 0" */ |
| 318 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_CLR, PCIE_PROT_STEP2_0_MASK); |
| 319 | #ifndef IGNORE_MTCMOS_CHECK |
| 320 | /* Note that this protect ack check after releasing protect has been ignored */ |
| 321 | #endif |
| 322 | /* TINFO="Release bus protect - step1 : 0" */ |
| 323 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_CLR, PCIE_PROT_STEP1_0_MASK); |
| 324 | #ifndef IGNORE_MTCMOS_CHECK |
| 325 | /* Note that this protect ack check after releasing protect has been ignored */ |
| 326 | #endif |
| 327 | /* TINFO="Finish to turn on PCIE" */ |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | void pcie_cg_enable(void) |
| 332 | { |
| 333 | DRV_WriteReg32(INFRA_TOPAXI_MODULE_SW_CG_1_SET, PCIE_SW_CG_1); |
| 334 | DRV_WriteReg32(INFRA_TOPAXI_MODULE_SW_CG_3_SET, PCIE_SW_CG_3); |
| 335 | DRV_WriteReg32(INFRA_TOPAXI_MODULE_SW_CG_4_SET, PCIE_SW_CG_4); |
| 336 | } |
| 337 | |
| 338 | void pcie_cg_disable(void) |
| 339 | { |
| 340 | DRV_WriteReg32(INFRA_TOPAXI_MODULE_SW_CG_1_CLR, PCIE_SW_CG_1); |
| 341 | DRV_WriteReg32(INFRA_TOPAXI_MODULE_SW_CG_3_CLR, PCIE_SW_CG_3); |
| 342 | DRV_WriteReg32(INFRA_TOPAXI_MODULE_SW_CG_4_CLR, PCIE_SW_CG_4); |
| 343 | } |
| 344 | |
| 345 | void pcie_power_off(void) |
| 346 | { |
| 347 | pcie_printf(PCIE_UARTDBG_INFO, "Power off PCIE\r\n"); |
| 348 | |
| 349 | /* Power off pcie mtcmos */ |
| 350 | spm_mtcmos_ctrl_pcie(STA_POWER_DOWN); |
| 351 | |
| 352 | /* Set PCIE PHY reset mode */ |
| 353 | #ifdef CHIP10992 |
| 354 | toprgu_ctrl_pcie_off(); |
| 355 | #endif |
| 356 | |
| 357 | #ifdef MT6298 |
| 358 | phy_ctrl_pcie_off(); |
| 359 | #endif |
| 360 | } |
| 361 | |
| 362 | PCIE_detect_result_e pcie_get_link_state(void) |
| 363 | { |
| 364 | if(g_pcie_detect_result == PCIE_LINK_UNKNOWN){ |
| 365 | g_pcie_detect_result = pcie_detect(); |
| 366 | } |
| 367 | |
| 368 | dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_NIL, "[PCIE][LINK]Link state %d, LTSSM %x", g_pcie_detect_result, g_ltssm); |
| 369 | |
| 370 | return g_pcie_detect_result; |
| 371 | } |
| 372 | |
| 373 | void pcie_mac_mtcmos_ctrl(kal_bool enable){ |
| 374 | |
| 375 | dhl_print(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_NIL, "[PCIE][MTCMOS]Plat Code %d", Plat_SW_Code()); |
| 376 | |
| 377 | if (enable) { |
| 378 | |
| 379 | if(Plat_SW_Code() == 0) |
| 380 | { |
| 381 | spm_mtcmos_rsb_on(PEXTP_D_2LX1_PWR_CON,PEXTP_D_2LX1_PWR_ACK_IDX); |
| 382 | } |
| 383 | else |
| 384 | { |
| 385 | spm_mtcmos_on(PEXTP_D_2LX1_PWR_CON,PEXTP_D_2LX1_PWR_ACK_IDX); |
| 386 | } |
| 387 | spm_mtcmos_sram_chain_on(PEXTP_D_2LX1_PWR_CON); |
| 388 | clr_protect_pextp_d_2lx1(); |
| 389 | } |
| 390 | else { |
| 391 | set_protect_pextp_d_2lx1(); |
| 392 | spm_mtcmos_sram_chain_off(PEXTP_D_2LX1_PWR_CON); |
| 393 | |
| 394 | if(Plat_SW_Code() == 0) |
| 395 | { |
| 396 | spm_mtcmos_rsb_off(PEXTP_D_2LX1_PWR_CON,PEXTP_D_2LX1_PWR_ACK_IDX); |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | spm_mtcmos_off(PEXTP_D_2LX1_PWR_CON,PEXTP_D_2LX1_PWR_ACK_IDX); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | void pcie_phy_mtcmos_ctrl(kal_bool enable){ |
| 406 | if (enable) { |
| 407 | spm_mtcmos_on(PEXTP_D_2LX1_PHY_PWR_CON,PEXTP_D_2LX1_PHY_PWR_ACK_IDX); |
| 408 | } |
| 409 | else { |
| 410 | spm_mtcmos_off(PEXTP_D_2LX1_PHY_PWR_CON,PEXTP_D_2LX1_PHY_PWR_ACK_IDX); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | void spm_mtcmos_rsb_on(kal_uint32 reg_addr, int ack_index) |
| 415 | { |
| 416 | /* TINFO="Set PWR_RST_B = 1" */ |
| 417 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) | PWR_RST_B); |
| 418 | } |
| 419 | |
| 420 | void spm_mtcmos_rsb_off(kal_uint32 reg_addr, int ack_index) |
| 421 | { |
| 422 | /* TINFO="Set PWR_RST_B = 0" */ |
| 423 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) & ~PWR_RST_B); |
| 424 | } |
| 425 | |
| 426 | void spm_mtcmos_on(kal_uint32 reg_addr, int ack_index){ |
| 427 | /* TINFO="Set PWR_ON = 1" */ |
| 428 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) | PWR_ON); |
| 429 | #ifndef IGNORE_MTCMOS_CHECK |
| 430 | while ((DRV_Reg32(PWR_STATUS) & (0x1<<ack_index)) != (0x1<<ack_index)); |
| 431 | #endif |
| 432 | /* TINFO="Set PWR_ON_2ND = 1" */ |
| 433 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) | PWR_ON_2ND); |
| 434 | #ifndef IGNORE_MTCMOS_CHECK |
| 435 | while ((DRV_Reg32(PWR_STATUS_2ND) & (0x1<<ack_index)) != (0x1<<ack_index)); |
| 436 | #endif |
| 437 | /* TINFO="Set PWR_CLK_DIS = 0" */ |
| 438 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) & ~PWR_CLK_DIS); |
| 439 | /* TINFO="Set PWR_ISO = 0" */ |
| 440 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) & ~PWR_ISO); |
| 441 | /* TINFO="Set PWR_RST_B = 1" */ |
| 442 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) | PWR_RST_B); |
| 443 | } |
| 444 | |
| 445 | void spm_mtcmos_off(kal_uint32 reg_addr, int ack_index){ |
| 446 | /* TINFO="Set PWR_ISO = 1" */ |
| 447 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) | PWR_ISO); |
| 448 | /* TINFO="Set PWR_CLK_DIS = 1" */ |
| 449 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) | PWR_CLK_DIS); |
| 450 | /* TINFO="Set PWR_RST_B = 0" */ |
| 451 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) & ~PWR_RST_B); |
| 452 | /* TINFO="Set PWR_ON = 0" */ |
| 453 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) & ~PWR_ON); |
| 454 | #ifndef IGNORE_MTCMOS_CHECK |
| 455 | while ((DRV_Reg32(PWR_STATUS) & (0x1<<ack_index))); |
| 456 | #endif |
| 457 | /* TINFO="Set PWR_ON_2ND = 0" */ |
| 458 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) & ~PWR_ON_2ND); |
| 459 | #ifndef IGNORE_MTCMOS_CHECK |
| 460 | while ((DRV_Reg32(PWR_STATUS_2ND) & (0x1<<ack_index))); |
| 461 | #endif |
| 462 | } |
| 463 | |
| 464 | void spm_mtcmos_sram_chain_on(kal_uint32 reg_addr){ |
| 465 | /* TINFO="Start to turn on MTCMOS_SRAM CHAIN" */ |
| 466 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) & ~SRAM_PD_OFFSET); |
| 467 | /* TINFO="WAITING MTCMOS_SRAM_ACK" */ |
| 468 | while((DRV_Reg32(reg_addr) & SRAM_PD_ACK_OFFSET) == SRAM_PD_ACK_OFFSET); |
| 469 | } |
| 470 | |
| 471 | void spm_mtcmos_sram_chain_off(kal_uint32 reg_addr){ |
| 472 | /* TINFO="Start to turn off MTCMOS_SRAM CHAIN" */ |
| 473 | DRV_WriteReg32(reg_addr, DRV_Reg32(reg_addr) | SRAM_PD_OFFSET); |
| 474 | /* TINFO="WAITING MTCMOS_SRAM_ACK" */ |
| 475 | while((DRV_Reg32(reg_addr) & SRAM_PD_ACK_OFFSET) != SRAM_PD_ACK_OFFSET); |
| 476 | } |
| 477 | |
| 478 | void set_protect_pextp_d_2lx1(void){ |
| 479 | set_prot0(BUS_PROT0_PCIE0); |
| 480 | set_prot3(BUS_PROT3_PCIE0); |
| 481 | set_prot4(BUS_PROT4_PCIE0); |
| 482 | } |
| 483 | |
| 484 | void clr_protect_pextp_d_2lx1(void){ |
| 485 | clr_prot0(BUS_PROT0_PCIE0); |
| 486 | clr_prot3(BUS_PROT3_PCIE0); |
| 487 | clr_prot4(BUS_PROT4_PCIE0); |
| 488 | } |
| 489 | |
| 490 | //////////////// |
| 491 | void set_prot0(unsigned int prot){ |
| 492 | /*TINFO="SET PROTECT0"*/ |
| 493 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_SET,prot); |
| 494 | /*TINFO="WAIT PROTECT0 ACK"*/ |
| 495 | while((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_STA1)&prot) != prot); |
| 496 | } |
| 497 | |
| 498 | void clr_prot0(unsigned int prot){ |
| 499 | /*TINFO="CLR PROTECT0"*/ |
| 500 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_CLR,prot); |
| 501 | } |
| 502 | |
| 503 | void set_prot1(unsigned int prot){ |
| 504 | /*TINFO="SET PROTECT1"*/ |
| 505 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_1_SET,prot); |
| 506 | /*TINFO="WAIT PROTECT1 ACK"*/ |
| 507 | while((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_STA1_1)&prot) != prot); |
| 508 | } |
| 509 | void clr_prot1(unsigned int prot){ |
| 510 | /*TINFO="CLR PROTECT1"*/ |
| 511 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_1_CLR,prot); |
| 512 | } |
| 513 | |
| 514 | void set_prot2(unsigned int prot){ |
| 515 | /*TINFO="SET PROTECT2"*/ |
| 516 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_SET_2,prot); |
| 517 | /*TINFO="WAIT PROTECT2 ACK"*/ |
| 518 | while((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_STA1_2)&prot) != prot); |
| 519 | } |
| 520 | void clr_prot2(unsigned int prot){ |
| 521 | /*TINFO="CLR PROTECT2"*/ |
| 522 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_CLR_2,prot); |
| 523 | } |
| 524 | |
| 525 | void set_prot3(unsigned int prot){ |
| 526 | /*TINFO="SET PROTECT3"*/ |
| 527 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_SET,prot); |
| 528 | /*TINFO="WAIT PROTECT3 ACK"*/ |
| 529 | while((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_STA1)&prot) != prot); |
| 530 | } |
| 531 | |
| 532 | void clr_prot3(unsigned int prot){ |
| 533 | /*TINFO="CLR PROTECT3"*/ |
| 534 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_CLR,prot); |
| 535 | } |
| 536 | |
| 537 | void set_prot4(unsigned int prot){ |
| 538 | /*TINFO="SET PROTECT4"*/ |
| 539 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_SET_1,prot); |
| 540 | /*TINFO="WAIT PROTECT4 ACK"*/ |
| 541 | while((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_STA1_1)&prot) != prot); |
| 542 | } |
| 543 | |
| 544 | void clr_prot4(unsigned int prot){ |
| 545 | /*TINFO="CLR PROTECT4"*/ |
| 546 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_INFRA_VDNR_CLR_1,prot); |
| 547 | } |
| 548 | |
| 549 | void set_prot6(unsigned int prot){ |
| 550 | /*TINFO="SET PROTECT6"*/ |
| 551 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_MM_SET,prot); |
| 552 | /*TINFO="WAIT PROTECT6 ACK"*/ |
| 553 | while((DRV_Reg32(INFRA_TOPAXI_PROTECTEN_MM_STA1)&prot) != prot); |
| 554 | } |
| 555 | void clr_prot6(unsigned int prot){ |
| 556 | /*TINFO="CLR PROTECT6"*/ |
| 557 | DRV_WriteReg32(INFRA_TOPAXI_PROTECTEN_MM_CLR,prot); |
| 558 | } |
| 559 | //////////////// |