| .. | .. |
|---|
| 1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 2 | 1 | /** @file pcie_core.c |
|---|
| 3 | 2 | * |
|---|
| 4 | 3 | * Contains PCIe related functions that are shared between different driver models (e.g. firmware |
|---|
| 5 | 4 | * builds, DHD builds, BMAC builds), in order to avoid code duplication. |
|---|
| 6 | 5 | * |
|---|
| 7 | | - * Copyright (C) 1999-2019, Broadcom Corporation |
|---|
| 8 | | - * |
|---|
| 6 | + * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation |
|---|
| 7 | + * |
|---|
| 8 | + * Copyright (C) 1999-2017, Broadcom Corporation |
|---|
| 9 | + * |
|---|
| 9 | 10 | * Unless you and Broadcom execute a separate written software license |
|---|
| 10 | 11 | * agreement governing use of this software, this software is licensed to you |
|---|
| 11 | 12 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
|---|
| 12 | 13 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
|---|
| 13 | 14 | * following added to such license: |
|---|
| 14 | | - * |
|---|
| 15 | + * |
|---|
| 15 | 16 | * As a special exception, the copyright holders of this software give you |
|---|
| 16 | 17 | * permission to link this software with independent modules, and to copy and |
|---|
| 17 | 18 | * distribute the resulting executable under terms of your choice, provided that |
|---|
| .. | .. |
|---|
| 19 | 20 | * the license of that module. An independent module is a module which is not |
|---|
| 20 | 21 | * derived from this software. The special exception does not apply to any |
|---|
| 21 | 22 | * modifications of the software. |
|---|
| 22 | | - * |
|---|
| 23 | + * |
|---|
| 23 | 24 | * Notwithstanding the above, under no circumstances may you combine this |
|---|
| 24 | 25 | * software in any way with any other Broadcom software provided under a license |
|---|
| 25 | 26 | * other than the GPL, without Broadcom's express prior written consent. |
|---|
| .. | .. |
|---|
| 27 | 28 | * |
|---|
| 28 | 29 | * <<Broadcom-WL-IPTag/Open:>> |
|---|
| 29 | 30 | * |
|---|
| 30 | | - * $Id: pcie_core.c 444841 2013-12-21 04:32:29Z $ |
|---|
| 31 | + * $Id: pcie_core.c 701962 2017-05-30 06:13:15Z $ |
|---|
| 31 | 32 | */ |
|---|
| 32 | 33 | |
|---|
| 33 | 34 | #include <bcm_cfg.h> |
|---|
| .. | .. |
|---|
| 38 | 39 | #include <siutils.h> |
|---|
| 39 | 40 | #include <hndsoc.h> |
|---|
| 40 | 41 | #include <sbchipc.h> |
|---|
| 41 | | - |
|---|
| 42 | +#include <pcicfg.h> |
|---|
| 43 | +#include <bcmdevs.h> |
|---|
| 44 | +#include <siutils_priv.h> |
|---|
| 42 | 45 | #include "pcie_core.h" |
|---|
| 46 | + |
|---|
| 47 | +extern int dhdpcie_dongle_host_pre_wd_reset_sequence(si_t *sih, osl_t *osh); |
|---|
| 48 | +extern int dhdpcie_dongle_host_post_wd_reset_sequence(si_t *sih, osl_t *osh); |
|---|
| 43 | 49 | |
|---|
| 44 | 50 | /* local prototypes */ |
|---|
| 45 | 51 | |
|---|
| .. | .. |
|---|
| 49 | 55 | |
|---|
| 50 | 56 | #ifdef BCMDRIVER |
|---|
| 51 | 57 | |
|---|
| 52 | | -void pcie_watchdog_reset(osl_t *osh, si_t *sih, sbpcieregs_t *sbpcieregs) |
|---|
| 58 | +/* wd_mask/wd_val is only for chipc_corerev >= 65 */ |
|---|
| 59 | +void pcie_watchdog_reset(osl_t *osh, si_t *sih, uint32 wd_mask, uint32 wd_val) |
|---|
| 53 | 60 | { |
|---|
| 54 | 61 | uint32 val, i, lsc; |
|---|
| 55 | 62 | uint16 cfg_offset[] = {PCIECFGREG_STATUS_CMD, PCIECFGREG_PM_CSR, |
|---|
| .. | .. |
|---|
| 58 | 65 | PCIECFGREG_LINK_STATUS_CTRL2, PCIECFGREG_RBAR_CTRL, |
|---|
| 59 | 66 | PCIECFGREG_PML1_SUB_CTRL1, PCIECFGREG_REG_BAR2_CONFIG, |
|---|
| 60 | 67 | PCIECFGREG_REG_BAR3_CONFIG}; |
|---|
| 61 | | - sbpcieregs_t *pcie = NULL; |
|---|
| 68 | + sbpcieregs_t *pcieregs = NULL; |
|---|
| 62 | 69 | uint32 origidx = si_coreidx(sih); |
|---|
| 70 | + int32 bcmerror = BCME_ERROR; |
|---|
| 71 | + |
|---|
| 72 | +#ifdef BCMQT |
|---|
| 73 | + /* To avoid hang on FPGA, donot reset watchdog */ |
|---|
| 74 | + if (CCREV(sih->ccrev) < 65) { |
|---|
| 75 | + si_setcoreidx(sih, origidx); |
|---|
| 76 | + return; |
|---|
| 77 | + } |
|---|
| 78 | +#endif // endif |
|---|
| 79 | +#ifdef BCMFPGA_HW |
|---|
| 80 | + if (CCREV(sih->ccrev) < 67) { |
|---|
| 81 | + /* To avoid hang on FPGA, donot reset watchdog */ |
|---|
| 82 | + si_setcoreidx(sih, origidx); |
|---|
| 83 | + return; |
|---|
| 84 | + } |
|---|
| 85 | +#endif // endif |
|---|
| 63 | 86 | |
|---|
| 64 | 87 | /* Switch to PCIE2 core */ |
|---|
| 65 | | - pcie = (sbpcieregs_t *)si_setcore(sih, PCIE2_CORE_ID, 0); |
|---|
| 66 | | - BCM_REFERENCE(pcie); |
|---|
| 67 | | - ASSERT(pcie != NULL); |
|---|
| 88 | + pcieregs = (sbpcieregs_t *)si_setcore(sih, PCIE2_CORE_ID, 0); |
|---|
| 89 | + BCM_REFERENCE(pcieregs); |
|---|
| 90 | + ASSERT(pcieregs != NULL); |
|---|
| 68 | 91 | |
|---|
| 69 | 92 | /* Disable/restore ASPM Control to protect the watchdog reset */ |
|---|
| 70 | | - W_REG(osh, &sbpcieregs->configaddr, PCIECFGREG_LINK_STATUS_CTRL); |
|---|
| 71 | | - lsc = R_REG(osh, &sbpcieregs->configdata); |
|---|
| 93 | + W_REG(osh, &pcieregs->configaddr, PCIECFGREG_LINK_STATUS_CTRL); |
|---|
| 94 | + lsc = R_REG(osh, &pcieregs->configdata); |
|---|
| 72 | 95 | val = lsc & (~PCIE_ASPM_ENAB); |
|---|
| 73 | | - W_REG(osh, &sbpcieregs->configdata, val); |
|---|
| 96 | + W_REG(osh, &pcieregs->configdata, val); |
|---|
| 97 | + |
|---|
| 98 | + /* |
|---|
| 99 | + * CYW55560 - As part of watchdog reset, ARM gets reset and bootloader starts from fresh, |
|---|
| 100 | + * So, pre wd reset sequcnce defined to make sure that pre init for bootloader can be done |
|---|
| 101 | + */ |
|---|
| 102 | + if (sih->chip == CYW55560_CHIP_ID) { |
|---|
| 103 | + if ((bcmerror = dhdpcie_dongle_host_pre_wd_reset_sequence(sih, osh))) { |
|---|
| 104 | + SI_ERROR(("%s: error %d pre wd reset seq\n", __FUNCTION__, bcmerror)); |
|---|
| 105 | + return; |
|---|
| 106 | + } |
|---|
| 107 | + } |
|---|
| 74 | 108 | |
|---|
| 75 | 109 | si_corereg(sih, SI_CC_IDX, OFFSETOF(chipcregs_t, watchdog), ~0, 4); |
|---|
| 76 | | - OSL_DELAY(100000); |
|---|
| 77 | 110 | |
|---|
| 78 | | - W_REG(osh, &sbpcieregs->configaddr, PCIECFGREG_LINK_STATUS_CTRL); |
|---|
| 79 | | - W_REG(osh, &sbpcieregs->configdata, lsc); |
|---|
| 111 | +#ifdef BCMQT |
|---|
| 112 | + OSL_DELAY(10000000); |
|---|
| 113 | +#else |
|---|
| 114 | + OSL_DELAY(100000); |
|---|
| 115 | +#endif // endif |
|---|
| 116 | + |
|---|
| 117 | + /* |
|---|
| 118 | + * CYW55560 - Once watchdog reset initiated, bootloader takes much time to be ready, |
|---|
| 119 | + * [BL_READY bit set], to make sure that host should not access backplane till bootloader |
|---|
| 120 | + * is not ready, post wd reset sequence is performed. |
|---|
| 121 | + */ |
|---|
| 122 | + if (sih->chip == CYW55560_CHIP_ID) { |
|---|
| 123 | + if ((bcmerror = dhdpcie_dongle_host_post_wd_reset_sequence(sih, osh))) { |
|---|
| 124 | + SI_ERROR(("%s: error %d post wd reset seq.\n", __FUNCTION__, bcmerror)); |
|---|
| 125 | + return; |
|---|
| 126 | + } |
|---|
| 127 | + } |
|---|
| 128 | + |
|---|
| 129 | + W_REG(osh, &pcieregs->configaddr, PCIECFGREG_LINK_STATUS_CTRL); |
|---|
| 130 | + W_REG(osh, &pcieregs->configdata, lsc); |
|---|
| 80 | 131 | |
|---|
| 81 | 132 | if (sih->buscorerev <= 13) { |
|---|
| 82 | 133 | /* Write configuration registers back to the shadow registers |
|---|
| 83 | 134 | * cause shadow registers are cleared out after watchdog reset. |
|---|
| 84 | 135 | */ |
|---|
| 85 | 136 | for (i = 0; i < ARRAYSIZE(cfg_offset); i++) { |
|---|
| 86 | | - W_REG(osh, &sbpcieregs->configaddr, cfg_offset[i]); |
|---|
| 87 | | - val = R_REG(osh, &sbpcieregs->configdata); |
|---|
| 88 | | - W_REG(osh, &sbpcieregs->configdata, val); |
|---|
| 137 | + W_REG(osh, &pcieregs->configaddr, cfg_offset[i]); |
|---|
| 138 | + val = R_REG(osh, &pcieregs->configdata); |
|---|
| 139 | + W_REG(osh, &pcieregs->configdata, val); |
|---|
| 89 | 140 | } |
|---|
| 90 | 141 | } |
|---|
| 91 | 142 | si_setcoreidx(sih, origidx); |
|---|
| 92 | 143 | } |
|---|
| 93 | | - |
|---|
| 94 | 144 | |
|---|
| 95 | 145 | /* CRWLPCIEGEN2-117 pcie_pipe_Iddq should be controlled |
|---|
| 96 | 146 | * by the L12 state from MAC to save power by putting the |
|---|
| .. | .. |
|---|
| 113 | 163 | |
|---|
| 114 | 164 | si_setcoreidx(sih, origidx); |
|---|
| 115 | 165 | } |
|---|
| 166 | + |
|---|
| 167 | +#define PCIE_PMCR_REFUP_MASK 0x3f0001e0 |
|---|
| 168 | +#define PCIE_PMCR_REFEXT_MASK 0x400000 |
|---|
| 169 | +#define PCIE_PMCR_REFUP_100US 0x38000080 |
|---|
| 170 | +#define PCIE_PMCR_REFEXT_100US 0x400000 |
|---|
| 171 | + |
|---|
| 172 | +/* Set PCIE TRefUp time to 100us */ |
|---|
| 173 | +void pcie_set_trefup_time_100us(si_t *sih) |
|---|
| 174 | +{ |
|---|
| 175 | + si_corereg(sih, sih->buscoreidx, |
|---|
| 176 | + OFFSETOF(sbpcieregs_t, configaddr), ~0, PCI_PMCR_REFUP); |
|---|
| 177 | + si_corereg(sih, sih->buscoreidx, |
|---|
| 178 | + OFFSETOF(sbpcieregs_t, configdata), PCIE_PMCR_REFUP_MASK, PCIE_PMCR_REFUP_100US); |
|---|
| 179 | + |
|---|
| 180 | + si_corereg(sih, sih->buscoreidx, |
|---|
| 181 | + OFFSETOF(sbpcieregs_t, configaddr), ~0, PCI_PMCR_REFUP_EXT); |
|---|
| 182 | + si_corereg(sih, sih->buscoreidx, |
|---|
| 183 | + OFFSETOF(sbpcieregs_t, configdata), PCIE_PMCR_REFEXT_MASK, PCIE_PMCR_REFEXT_100US); |
|---|
| 184 | +} |
|---|
| 185 | + |
|---|
| 116 | 186 | #endif /* BCMDRIVER */ |
|---|