Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Cadence DDR Driver |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 4 | * |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 5 | * Copyright (C) 2012-2021 Cadence Design Systems, Inc. |
| 6 | * Copyright (C) 2018-2021 Texas Instruments Incorporated - https://www.ti.com/ |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 7 | */ |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 8 | |
| 9 | #include <errno.h> |
| 10 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 11 | #include "cps_drv_lpddr4.h" |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 12 | #include "lpddr4_if.h" |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 13 | #include "lpddr4.h" |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 14 | #include "lpddr4_structs_if.h" |
| 15 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 16 | #ifndef LPDDR4_CUSTOM_TIMEOUT_DELAY |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 17 | #define LPDDR4_CUSTOM_TIMEOUT_DELAY 100000000U |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 18 | #endif |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 19 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 20 | #ifndef LPDDR4_CPS_NS_DELAY_TIME |
| 21 | #define LPDDR4_CPS_NS_DELAY_TIME 10000000U |
| 22 | #endif |
| 23 | |
| 24 | static u32 lpddr4_pollphyindepirq(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt irqbit, u32 delay); |
| 25 | static u32 lpddr4_pollandackirq(const lpddr4_privatedata *pd); |
| 26 | static u32 lpddr4_startsequencecontroller(const lpddr4_privatedata *pd); |
| 27 | static u32 lpddr4_writemmrregister(const lpddr4_privatedata *pd, u32 writemoderegval); |
| 28 | static void lpddr4_checkcatrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr); |
| 29 | static void lpddr4_checkgatelvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr); |
| 30 | static void lpddr4_checkreadlvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr); |
| 31 | static void lpddr4_checkdqtrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr); |
| 32 | static u8 lpddr4_seterror(volatile u32 *reg, u32 errbitmask, u8 *errfoundptr, const u32 errorinfobits); |
| 33 | static void lpddr4_setphysnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound); |
| 34 | static void lpddr4_setphyadrsnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound); |
| 35 | static void readpdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles); |
| 36 | static void readsrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles); |
| 37 | static void readsrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles); |
| 38 | static void readsrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles); |
| 39 | static void readsrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles); |
| 40 | static void readsrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles); |
| 41 | static void readsrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles); |
| 42 | static void lpddr4_readlpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles); |
| 43 | static void writepdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles); |
| 44 | static void writesrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles); |
| 45 | static void writesrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles); |
| 46 | static void writesrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles); |
| 47 | static void writesrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles); |
| 48 | static void writesrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles); |
| 49 | static void writesrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles); |
| 50 | static void lpddr4_writelpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles); |
| 51 | static void lpddr4_updatefsp2refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max); |
| 52 | static void lpddr4_updatefsp1refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max); |
| 53 | static void lpddr4_updatefsp0refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max); |
| 54 | #ifdef REG_WRITE_VERIF |
| 55 | static u32 lpddr4_getphyrwmask(u32 regoffset); |
| 56 | static u32 lpddr4_verifyregwrite(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue); |
| 57 | #endif |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 58 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 59 | u32 lpddr4_pollctlirq(const lpddr4_privatedata *pd, lpddr4_intr_ctlinterrupt irqbit, u32 delay) |
| 60 | { |
| 61 | u32 result = 0U; |
| 62 | u32 timeout = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 63 | bool irqstatus = false; |
| 64 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 65 | do { |
| 66 | if (++timeout == delay) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 67 | result = (u32)EIO; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 68 | break; |
| 69 | } |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 70 | result = lpddr4_checkctlinterrupt(pd, irqbit, &irqstatus); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 71 | } while ((irqstatus == (bool)false) && (result == (u32)0)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 72 | |
| 73 | return result; |
| 74 | } |
| 75 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 76 | static u32 lpddr4_pollphyindepirq(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt irqbit, u32 delay) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 77 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 78 | u32 result = 0U; |
| 79 | u32 timeout = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 80 | bool irqstatus = false; |
| 81 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 82 | do { |
| 83 | if (++timeout == delay) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 84 | result = (u32)EIO; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 85 | break; |
| 86 | } |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 87 | result = lpddr4_checkphyindepinterrupt(pd, irqbit, &irqstatus); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 88 | } while ((irqstatus == (bool)false) && (result == (u32)0)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 89 | |
| 90 | return result; |
| 91 | } |
| 92 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 93 | static u32 lpddr4_pollandackirq(const lpddr4_privatedata *pd) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 94 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 95 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 96 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 97 | result = lpddr4_pollphyindepirq(pd, LPDDR4_INTR_PHY_INDEP_INIT_DONE_BIT, LPDDR4_CUSTOM_TIMEOUT_DELAY); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 98 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 99 | if (result == (u32)0) |
| 100 | result = lpddr4_ackphyindepinterrupt(pd, LPDDR4_INTR_PHY_INDEP_INIT_DONE_BIT); |
| 101 | if (result == (u32)0) |
| 102 | result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MC_INIT_DONE, LPDDR4_CUSTOM_TIMEOUT_DELAY); |
| 103 | if (result == (u32)0) |
| 104 | result = lpddr4_ackctlinterrupt(pd, LPDDR4_INTR_MC_INIT_DONE); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 105 | return result; |
| 106 | } |
| 107 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 108 | static u32 lpddr4_startsequencecontroller(const lpddr4_privatedata *pd) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 109 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 110 | u32 result = 0U; |
| 111 | u32 regval = 0U; |
| 112 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 113 | lpddr4_infotype infotype; |
| 114 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 115 | regval = CPS_FLD_SET(LPDDR4__PI_START__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__PI_START__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 116 | CPS_REG_WRITE((&(ctlregbase->LPDDR4__PI_START__REG)), regval); |
| 117 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 118 | regval = CPS_FLD_SET(LPDDR4__START__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__START__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 119 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__START__REG), regval); |
| 120 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 121 | if (pd->infohandler != (lpddr4_infocallback)NULL) { |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 122 | infotype = LPDDR4_DRV_SOC_PLL_UPDATE; |
| 123 | pd->infohandler(pd, infotype); |
| 124 | } |
| 125 | |
| 126 | result = lpddr4_pollandackirq(pd); |
| 127 | |
| 128 | return result; |
| 129 | } |
| 130 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 131 | volatile u32 *lpddr4_addoffset(volatile u32 *addr, u32 regoffset) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 132 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 133 | volatile u32 *local_addr = addr; |
| 134 | volatile u32 *regaddr = &local_addr[regoffset]; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 135 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 136 | return regaddr; |
| 137 | } |
| 138 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 139 | u32 lpddr4_probe(const lpddr4_config *config, u16 *configsize) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 140 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 141 | u32 result; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 142 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 143 | result = (u32)(lpddr4_probesf(config, configsize)); |
| 144 | if (result == (u32)0) |
| 145 | *configsize = (u16)(sizeof(lpddr4_privatedata)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 146 | return result; |
| 147 | } |
| 148 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 149 | u32 lpddr4_init(lpddr4_privatedata *pd, const lpddr4_config *cfg) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 150 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 151 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 152 | |
| 153 | result = lpddr4_initsf(pd, cfg); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 154 | if (result == (u32)0) { |
| 155 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)cfg->ctlbase; |
| 156 | pd->ctlbase = ctlregbase; |
| 157 | pd->infohandler = (lpddr4_infocallback)cfg->infohandler; |
| 158 | pd->ctlinterrupthandler = (lpddr4_ctlcallback)cfg->ctlinterrupthandler; |
| 159 | pd->phyindepinterrupthandler = (lpddr4_phyindepcallback)cfg->phyindepinterrupthandler; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 160 | } |
| 161 | return result; |
| 162 | } |
| 163 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 164 | u32 lpddr4_start(const lpddr4_privatedata *pd) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 165 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 166 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 167 | |
| 168 | result = lpddr4_startsf(pd); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 169 | if (result == (u32)0) { |
| 170 | result = lpddr4_enablepiinitiator(pd); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 171 | result = lpddr4_startsequencecontroller(pd); |
| 172 | } |
| 173 | return result; |
| 174 | } |
| 175 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 176 | u32 lpddr4_readreg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 *regvalue) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 177 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 178 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 179 | |
| 180 | result = lpddr4_readregsf(pd, cpp, regvalue); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 181 | if (result == (u32)0) { |
| 182 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 183 | |
| 184 | if (cpp == LPDDR4_CTL_REGS) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 185 | if (regoffset >= LPDDR4_INTR_CTL_REG_COUNT) |
| 186 | result = (u32)EINVAL; |
| 187 | else |
| 188 | *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_CTL_0), regoffset)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 189 | } else if (cpp == LPDDR4_PHY_REGS) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 190 | if (regoffset >= LPDDR4_INTR_PHY_REG_COUNT) |
| 191 | result = (u32)EINVAL; |
| 192 | else |
| 193 | *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_PHY_0), regoffset)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 194 | |
| 195 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 196 | if (regoffset >= LPDDR4_INTR_PHY_INDEP_REG_COUNT) |
| 197 | result = (u32)EINVAL; |
| 198 | else |
| 199 | *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_PI_0), regoffset)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | return result; |
| 203 | } |
| 204 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 205 | #ifdef REG_WRITE_VERIF |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 206 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 207 | static u32 lpddr4_getphyrwmask(u32 regoffset) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 208 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 209 | u32 rwmask = 0U; |
| 210 | u32 arrayoffset = 0U; |
| 211 | u32 slicenum, sliceoffset = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 212 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 213 | for (slicenum = (u32)0U; slicenum <= (DSLICE_NUM + ASLICE_NUM); slicenum++) { |
| 214 | sliceoffset = sliceoffset + (u32)SLICE_WIDTH; |
| 215 | if (regoffset < sliceoffset) |
| 216 | break; |
| 217 | } |
| 218 | arrayoffset = regoffset - (sliceoffset - (u32)SLICE_WIDTH); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 219 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 220 | if (slicenum < DSLICE_NUM) { |
| 221 | rwmask = lpddr4_getdslicemask(slicenum, arrayoffset); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 222 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 223 | if (slicenum == DSLICE_NUM) { |
| 224 | if (arrayoffset < ASLICE0_REG_COUNT) |
| 225 | rwmask = g_lpddr4_address_slice_0_rw_mask[arrayoffset]; |
| 226 | } else { |
| 227 | if (arrayoffset < PHY_CORE_REG_COUNT) |
| 228 | rwmask = g_lpddr4_phy_core_rw_mask[arrayoffset]; |
| 229 | } |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 230 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 231 | return rwmask; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 232 | } |
| 233 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 234 | static u32 lpddr4_verifyregwrite(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 235 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 236 | u32 result = (u32)0; |
| 237 | u32 regreadval = 0U; |
| 238 | u32 rwmask = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 239 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 240 | result = lpddr4_readreg(pd, cpp, regoffset, ®readval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 241 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 242 | if (result == (u32)0) { |
| 243 | switch (cpp) { |
| 244 | case LPDDR4_PHY_INDEP_REGS: |
| 245 | rwmask = g_lpddr4_pi_rw_mask[regoffset]; |
| 246 | break; |
| 247 | case LPDDR4_PHY_REGS: |
| 248 | rwmask = lpddr4_getphyrwmask(regoffset); |
| 249 | break; |
| 250 | default: |
| 251 | rwmask = g_lpddr4_ddr_controller_rw_mask[regoffset]; |
| 252 | break; |
| 253 | } |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 254 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 255 | if ((rwmask & regreadval) != (regvalue & rwmask)) |
| 256 | result = EIO; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 257 | } |
| 258 | return result; |
| 259 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 260 | #endif |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 261 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 262 | u32 lpddr4_writereg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 263 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 264 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 265 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 266 | result = lpddr4_writeregsf(pd, cpp); |
| 267 | if (result == (u32)0) { |
| 268 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 269 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 270 | if (cpp == LPDDR4_CTL_REGS) { |
| 271 | if (regoffset >= LPDDR4_INTR_CTL_REG_COUNT) |
| 272 | result = (u32)EINVAL; |
| 273 | else |
| 274 | CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_CTL_0), regoffset), regvalue); |
| 275 | } else if (cpp == LPDDR4_PHY_REGS) { |
| 276 | if (regoffset >= LPDDR4_INTR_PHY_REG_COUNT) |
| 277 | result = (u32)EINVAL; |
| 278 | else |
| 279 | CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_PHY_0), regoffset), regvalue); |
| 280 | } else { |
| 281 | if (regoffset >= LPDDR4_INTR_PHY_INDEP_REG_COUNT) |
| 282 | result = (u32)EINVAL; |
| 283 | else |
| 284 | CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_PI_0), regoffset), regvalue); |
| 285 | } |
| 286 | } |
| 287 | #ifdef REG_WRITE_VERIF |
| 288 | if (result == (u32)0) |
| 289 | result = lpddr4_verifyregwrite(pd, cpp, regoffset, regvalue); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 290 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 291 | #endif |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 292 | |
| 293 | return result; |
| 294 | } |
| 295 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 296 | u32 lpddr4_getmmrregister(const lpddr4_privatedata *pd, u32 readmoderegval, u64 *mmrvalue, u8 *mmrstatus) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 297 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 298 | u32 result = 0U; |
| 299 | u32 tdelay = 1000U; |
| 300 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 301 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 302 | result = lpddr4_getmmrregistersf(pd, mmrvalue, mmrstatus); |
| 303 | if (result == (u32)0) { |
| 304 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 305 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 306 | regval = CPS_FLD_WRITE(LPDDR4__READ_MODEREG__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__READ_MODEREG__REG)), readmoderegval); |
| 307 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__READ_MODEREG__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 308 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 309 | result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_READ_DONE, tdelay); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 310 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 311 | if (result == (u32)0) |
| 312 | result = lpddr4_checkmmrreaderror(pd, mmrvalue, mmrstatus); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 313 | return result; |
| 314 | } |
| 315 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 316 | static u32 lpddr4_writemmrregister(const lpddr4_privatedata *pd, u32 writemoderegval) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 317 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 318 | u32 result = (u32)0; |
| 319 | u32 tdelay = 1000U; |
| 320 | u32 regval = 0U; |
| 321 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 322 | |
| 323 | regval = CPS_FLD_WRITE(LPDDR4__WRITE_MODEREG__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WRITE_MODEREG__REG)), writemoderegval); |
| 324 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__WRITE_MODEREG__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 325 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 326 | result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_WRITE_DONE, tdelay); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 327 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 328 | return result; |
| 329 | } |
| 330 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 331 | u32 lpddr4_setmmrregister(const lpddr4_privatedata *pd, u32 writemoderegval, u8 *mrwstatus) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 332 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 333 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 334 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 335 | result = lpddr4_setmmrregistersf(pd, mrwstatus); |
| 336 | if (result == (u32)0) { |
| 337 | result = lpddr4_writemmrregister(pd, writemoderegval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 338 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 339 | if (result == (u32)0) |
| 340 | result = lpddr4_ackctlinterrupt(pd, LPDDR4_INTR_MR_WRITE_DONE); |
| 341 | if (result == (u32)0) { |
| 342 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 343 | *mrwstatus = (u8)CPS_FLD_READ(LPDDR4__MRW_STATUS__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__MRW_STATUS__REG))); |
| 344 | if ((*mrwstatus) != 0U) |
| 345 | result = (u32)EIO; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 346 | } |
| 347 | } |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 348 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 349 | #ifdef ASILC |
| 350 | #endif |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 351 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 352 | return result; |
| 353 | } |
| 354 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 355 | u32 lpddr4_writectlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 356 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 357 | u32 result; |
| 358 | u32 aindex; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 359 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 360 | result = lpddr4_writectlconfigsf(pd); |
| 361 | if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL)) |
| 362 | result = EINVAL; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 363 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 364 | if (result == (u32)0) { |
| 365 | for (aindex = 0; aindex < regcount; aindex++) |
| 366 | result = (u32)lpddr4_writereg(pd, LPDDR4_CTL_REGS, (u32)regnum[aindex], |
| 367 | (u32)regvalues[aindex]); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 368 | } |
| 369 | return result; |
| 370 | } |
| 371 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 372 | u32 lpddr4_writephyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 373 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 374 | u32 result; |
| 375 | u32 aindex; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 376 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 377 | result = lpddr4_writephyindepconfigsf(pd); |
| 378 | if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL)) |
| 379 | result = EINVAL; |
| 380 | if (result == (u32)0) { |
| 381 | for (aindex = 0; aindex < regcount; aindex++) |
| 382 | result = (u32)lpddr4_writereg(pd, LPDDR4_PHY_INDEP_REGS, (u32)regnum[aindex], |
| 383 | (u32)regvalues[aindex]); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 384 | } |
| 385 | return result; |
| 386 | } |
| 387 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 388 | u32 lpddr4_writephyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 389 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 390 | u32 result; |
| 391 | u32 aindex; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 392 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 393 | result = lpddr4_writephyconfigsf(pd); |
| 394 | if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL)) |
| 395 | result = EINVAL; |
| 396 | if (result == (u32)0) { |
| 397 | for (aindex = 0; aindex < regcount; aindex++) |
| 398 | result = (u32)lpddr4_writereg(pd, LPDDR4_PHY_REGS, (u32)regnum[aindex], |
| 399 | (u32)regvalues[aindex]); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 400 | } |
| 401 | return result; |
| 402 | } |
| 403 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 404 | u32 lpddr4_readctlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 405 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 406 | u32 result; |
| 407 | u32 aindex; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 408 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 409 | result = lpddr4_readctlconfigsf(pd); |
| 410 | if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL)) |
| 411 | result = EINVAL; |
| 412 | if (result == (u32)0) { |
| 413 | for (aindex = 0; aindex < regcount; aindex++) |
| 414 | result = (u32)lpddr4_readreg(pd, LPDDR4_CTL_REGS, (u32)regnum[aindex], |
| 415 | (u32 *)(®values[aindex])); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 416 | } |
| 417 | return result; |
| 418 | } |
| 419 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 420 | u32 lpddr4_readphyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 421 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 422 | u32 result; |
| 423 | u32 aindex; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 424 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 425 | result = lpddr4_readphyindepconfigsf(pd); |
| 426 | if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL)) |
| 427 | result = EINVAL; |
| 428 | if (result == (u32)0) { |
| 429 | for (aindex = 0; aindex < regcount; aindex++) |
| 430 | result = (u32)lpddr4_readreg(pd, LPDDR4_PHY_INDEP_REGS, (u32)regnum[aindex], |
| 431 | (u32 *)(®values[aindex])); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 432 | } |
| 433 | return result; |
| 434 | } |
| 435 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 436 | u32 lpddr4_readphyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 437 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 438 | u32 result; |
| 439 | u32 aindex; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 440 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 441 | result = lpddr4_readphyconfigsf(pd); |
| 442 | if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL)) |
| 443 | result = EINVAL; |
| 444 | if (result == (u32)0) { |
| 445 | for (aindex = 0; aindex < regcount; aindex++) |
| 446 | result = (u32)lpddr4_readreg(pd, LPDDR4_PHY_REGS, (u32)regnum[aindex], |
| 447 | (u32 *)(®values[aindex])); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 448 | } |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 449 | return result; |
| 450 | } |
| 451 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 452 | u32 lpddr4_getphyindepinterruptmask(const lpddr4_privatedata *pd, u32 *mask) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 453 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 454 | u32 result; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 455 | |
| 456 | result = lpddr4_getphyindepinterruptmsf(pd, mask); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 457 | if (result == (u32)0) { |
| 458 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 459 | *mask = CPS_FLD_READ(LPDDR4__PI_INT_MASK__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_MASK__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 460 | } |
| 461 | return result; |
| 462 | } |
| 463 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 464 | u32 lpddr4_setphyindepinterruptmask(const lpddr4_privatedata *pd, const u32 *mask) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 465 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 466 | u32 result; |
| 467 | u32 regval = 0; |
| 468 | const u32 ui32irqcount = (u32)LPDDR4_INTR_PHY_INDEP_DLL_LOCK_STATE_CHANGE_BIT + 1U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 469 | |
| 470 | result = lpddr4_setphyindepinterruptmsf(pd, mask); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 471 | if ((result == (u32)0) && (ui32irqcount < WORD_SHIFT)) { |
| 472 | if (*mask >= (1U << ui32irqcount)) |
| 473 | result = (u32)EINVAL; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 474 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 475 | if (result == (u32)0) { |
| 476 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 477 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 478 | regval = CPS_FLD_WRITE(LPDDR4__PI_INT_MASK__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_MASK__REG)), *mask); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 479 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_MASK__REG), regval); |
| 480 | } |
| 481 | return result; |
| 482 | } |
| 483 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 484 | u32 lpddr4_checkphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr, bool *irqstatus) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 485 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 486 | u32 result = 0; |
| 487 | u32 phyindepirqstatus = 0; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 488 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 489 | result = LPDDR4_INTR_CheckPhyIndepIntSF(pd, intr, irqstatus); |
| 490 | if ((result == (u32)0) && ((u32)intr < WORD_SHIFT)) { |
| 491 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 492 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 493 | phyindepirqstatus = CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_STATUS__REG)); |
| 494 | *irqstatus = (bool)(((phyindepirqstatus >> (u32)intr) & LPDDR4_BIT_MASK) > 0U); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 495 | } |
| 496 | return result; |
| 497 | } |
| 498 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 499 | u32 lpddr4_ackphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 500 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 501 | u32 result = 0U; |
| 502 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 503 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 504 | result = LPDDR4_INTR_AckPhyIndepIntSF(pd, intr); |
| 505 | if ((result == (u32)0) && ((u32)intr < WORD_SHIFT)) { |
| 506 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 507 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 508 | regval = ((u32)LPDDR4_BIT_MASK << (u32)intr); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 509 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_ACK__REG), regval); |
| 510 | } |
| 511 | |
| 512 | return result; |
| 513 | } |
| 514 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 515 | static void lpddr4_checkcatrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 516 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 517 | u32 regval; |
| 518 | u32 errbitmask = 0U; |
| 519 | u32 snum; |
| 520 | volatile u32 *regaddress; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 521 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 522 | regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_ADR_CALVL_OBS1_0__REG)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 523 | errbitmask = (CA_TRAIN_RL) | (NIBBLE_MASK); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 524 | for (snum = 0U; snum < ASLICE_NUM; snum++) { |
| 525 | regval = CPS_REG_READ(regaddress); |
| 526 | if ((regval & errbitmask) != CA_TRAIN_RL) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 527 | debuginfo->catraingerror = CDN_TRUE; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 528 | *errfoundptr = true; |
| 529 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 530 | regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 534 | static void lpddr4_checkgatelvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 535 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 536 | u32 regval; |
| 537 | u32 errbitmask = 0U; |
| 538 | u32 snum; |
| 539 | volatile u32 *regaddress; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 540 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 541 | regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_GTLVL_STATUS_OBS_0__REG)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 542 | errbitmask = GATE_LVL_ERROR_FIELDS; |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 543 | for (snum = (u32)0U; snum < DSLICE_NUM; snum++) { |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 544 | regval = CPS_REG_READ(regaddress); |
| 545 | if ((regval & errbitmask) != 0U) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 546 | debuginfo->gatelvlerror = CDN_TRUE; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 547 | *errfoundptr = true; |
| 548 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 549 | regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 553 | static void lpddr4_checkreadlvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 554 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 555 | u32 regval; |
| 556 | u32 errbitmask = 0U; |
| 557 | u32 snum; |
| 558 | volatile u32 *regaddress; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 559 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 560 | regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_RDLVL_STATUS_OBS_0__REG)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 561 | errbitmask = READ_LVL_ERROR_FIELDS; |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 562 | for (snum = (u32)0U; snum < DSLICE_NUM; snum++) { |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 563 | regval = CPS_REG_READ(regaddress); |
| 564 | if ((regval & errbitmask) != 0U) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 565 | debuginfo->readlvlerror = CDN_TRUE; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 566 | *errfoundptr = true; |
| 567 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 568 | regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 572 | static void lpddr4_checkdqtrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 573 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 574 | u32 regval; |
| 575 | u32 errbitmask = 0U; |
| 576 | u32 snum; |
| 577 | volatile u32 *regaddress; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 578 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 579 | regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_WDQLVL_STATUS_OBS_0__REG)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 580 | errbitmask = DQ_LVL_STATUS; |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 581 | for (snum = (u32)0U; snum < DSLICE_NUM; snum++) { |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 582 | regval = CPS_REG_READ(regaddress); |
| 583 | if ((regval & errbitmask) != 0U) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 584 | debuginfo->dqtrainingerror = CDN_TRUE; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 585 | *errfoundptr = true; |
| 586 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 587 | regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 591 | bool lpddr4_checklvlerrors(const lpddr4_privatedata *pd, lpddr4_debuginfo *debuginfo, bool errfound) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 592 | { |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 593 | bool localerrfound = errfound; |
| 594 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 595 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 596 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 597 | if (localerrfound == (bool)false) |
| 598 | lpddr4_checkcatrainingerror(ctlregbase, debuginfo, &localerrfound); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 599 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 600 | if (localerrfound == (bool)false) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 601 | lpddr4_checkwrlvlerror(ctlregbase, debuginfo, &localerrfound); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 602 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 603 | if (localerrfound == (bool)false) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 604 | lpddr4_checkgatelvlerror(ctlregbase, debuginfo, &localerrfound); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 605 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 606 | if (localerrfound == (bool)false) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 607 | lpddr4_checkreadlvlerror(ctlregbase, debuginfo, &localerrfound); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 608 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 609 | if (localerrfound == (bool)false) |
| 610 | lpddr4_checkdqtrainingerror(ctlregbase, debuginfo, &localerrfound); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 611 | return localerrfound; |
| 612 | } |
| 613 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 614 | static u8 lpddr4_seterror(volatile u32 *reg, u32 errbitmask, u8 *errfoundptr, const u32 errorinfobits) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 615 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 616 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 617 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 618 | regval = CPS_REG_READ(reg); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 619 | if ((regval & errbitmask) != errorinfobits) |
| 620 | *errfoundptr = CDN_TRUE; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 621 | return *errfoundptr; |
| 622 | } |
| 623 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 624 | void lpddr4_seterrors(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, u8 *errfoundptr) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 625 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 626 | u32 errbitmask = (LPDDR4_BIT_MASK << 0x1U) | (LPDDR4_BIT_MASK); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 627 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 628 | debuginfo->pllerror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_PLL_OBS_0__REG), |
| 629 | errbitmask, errfoundptr, PLL_READY); |
| 630 | if (*errfoundptr == CDN_FALSE) |
| 631 | debuginfo->pllerror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_PLL_OBS_1__REG), |
| 632 | errbitmask, errfoundptr, PLL_READY); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 633 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 634 | if (*errfoundptr == CDN_FALSE) |
| 635 | debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT_OBS_0__REG), |
| 636 | IO_CALIB_DONE, errfoundptr, IO_CALIB_DONE); |
| 637 | if (*errfoundptr == CDN_FALSE) |
| 638 | debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT2_OBS_0__REG), |
| 639 | IO_CALIB_DONE, errfoundptr, IO_CALIB_DONE); |
| 640 | if (*errfoundptr == CDN_FALSE) |
| 641 | debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT3_OBS_0__REG), |
| 642 | IO_CALIB_FIELD, errfoundptr, IO_CALIB_STATE); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 643 | } |
| 644 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 645 | static void lpddr4_setphysnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 646 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 647 | u32 snum = 0U; |
| 648 | volatile u32 *regaddress; |
| 649 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 650 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 651 | if (errorfound == (bool)false) { |
| 652 | regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__SC_PHY_SNAP_OBS_REGS_0__REG)); |
| 653 | for (snum = (u32)0U; snum < DSLICE_NUM; snum++) { |
| 654 | regval = CPS_FLD_SET(LPDDR4__SC_PHY_SNAP_OBS_REGS_0__FLD, CPS_REG_READ(regaddress)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 655 | CPS_REG_WRITE(regaddress, regval); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 656 | regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 661 | static void lpddr4_setphyadrsnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 662 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 663 | u32 snum = 0U; |
| 664 | volatile u32 *regaddress; |
| 665 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 666 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 667 | if (errorfound == (bool)false) { |
| 668 | regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__SC_PHY_ADR_SNAP_OBS_REGS_0__REG)); |
| 669 | for (snum = (u32)0U; snum < ASLICE_NUM; snum++) { |
| 670 | regval = CPS_FLD_SET(LPDDR4__SC_PHY_ADR_SNAP_OBS_REGS_0__FLD, CPS_REG_READ(regaddress)); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 671 | CPS_REG_WRITE(regaddress, regval); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 672 | regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 677 | void lpddr4_setsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 678 | { |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 679 | lpddr4_setphysnapsettings(ctlregbase, errorfound); |
| 680 | lpddr4_setphyadrsnapsettings(ctlregbase, errorfound); |
| 681 | } |
| 682 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 683 | static void readpdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 684 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 685 | if (*fspnum == LPDDR4_FSP_0) |
| 686 | *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG))); |
| 687 | else if (*fspnum == LPDDR4_FSP_1) |
| 688 | *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG))); |
| 689 | else |
| 690 | *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 691 | } |
| 692 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 693 | static void readsrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 694 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 695 | if (*fspnum == LPDDR4_FSP_0) |
| 696 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG))); |
| 697 | else if (*fspnum == LPDDR4_FSP_1) |
| 698 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG))); |
| 699 | else |
| 700 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 701 | } |
| 702 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 703 | static void readsrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 704 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 705 | if (*fspnum == LPDDR4_FSP_0) |
| 706 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG))); |
| 707 | else if (*fspnum == LPDDR4_FSP_1) |
| 708 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG))); |
| 709 | else |
| 710 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 711 | } |
| 712 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 713 | static void readsrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 714 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 715 | if (*fspnum == LPDDR4_FSP_0) |
| 716 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__REG))); |
| 717 | else if (*fspnum == LPDDR4_FSP_1) |
| 718 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F1__REG))); |
| 719 | else |
| 720 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 721 | } |
| 722 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 723 | static void readsrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 724 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 725 | if (*fspnum == LPDDR4_FSP_0) |
| 726 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG))); |
| 727 | else if (*fspnum == LPDDR4_FSP_1) |
| 728 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG))); |
| 729 | else |
| 730 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 731 | } |
| 732 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 733 | static void readsrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 734 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 735 | if (*fspnum == LPDDR4_FSP_0) |
| 736 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG))); |
| 737 | else if (*fspnum == LPDDR4_FSP_1) |
| 738 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG))); |
| 739 | else |
| 740 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 741 | } |
| 742 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 743 | static void readsrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 744 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 745 | if (*fspnum == LPDDR4_FSP_0) |
| 746 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__REG))); |
| 747 | else if (*fspnum == LPDDR4_FSP_1) |
| 748 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F1__REG))); |
| 749 | else |
| 750 | *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 751 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 752 | } |
| 753 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 754 | static void lpddr4_readlpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 755 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 756 | if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 757 | readpdwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 758 | else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 759 | readsrshortwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 760 | else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 761 | readsrlongwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 762 | else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 763 | readsrlonggatewakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 764 | else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 765 | readsrdpshortwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 766 | else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 767 | readsrdplongwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 768 | else |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 769 | readsrdplonggatewakeup(fspnum, ctlregbase, cycles); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 770 | } |
| 771 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 772 | u32 lpddr4_getlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 773 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 774 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 775 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 776 | result = lpddr4_getlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 777 | if (result == (u32)0) { |
| 778 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 779 | lpddr4_readlpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 780 | } |
| 781 | return result; |
| 782 | } |
| 783 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 784 | static void writepdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 785 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 786 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 787 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 788 | if (*fspnum == LPDDR4_FSP_0) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 789 | regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG)), *cycles); |
| 790 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 791 | } else if (*fspnum == LPDDR4_FSP_1) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 792 | regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG)), *cycles); |
| 793 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 794 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 795 | regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG)), *cycles); |
| 796 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 800 | static void writesrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 801 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 802 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 803 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 804 | if (*fspnum == LPDDR4_FSP_0) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 805 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG)), *cycles); |
| 806 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 807 | } else if (*fspnum == LPDDR4_FSP_1) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 808 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG)), *cycles); |
| 809 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 810 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 811 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG)), *cycles); |
| 812 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 816 | static void writesrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 817 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 818 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 819 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 820 | if (*fspnum == LPDDR4_FSP_0) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 821 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG)), *cycles); |
| 822 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 823 | } else if (*fspnum == LPDDR4_FSP_1) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 824 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG)), *cycles); |
| 825 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 826 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 827 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG)), *cycles); |
| 828 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 832 | static void writesrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 833 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 834 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 835 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 836 | if (*fspnum == LPDDR4_FSP_0) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 837 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__REG)), *cycles); |
| 838 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 839 | } else if (*fspnum == LPDDR4_FSP_1) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 840 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F1__REG)), *cycles); |
| 841 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F1__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 842 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 843 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F2__REG)), *cycles); |
| 844 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F2__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 848 | static void writesrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 849 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 850 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 851 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 852 | if (*fspnum == LPDDR4_FSP_0) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 853 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG)), *cycles); |
| 854 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 855 | } else if (*fspnum == LPDDR4_FSP_1) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 856 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG)), *cycles); |
| 857 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 858 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 859 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG)), *cycles); |
| 860 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 864 | static void writesrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 865 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 866 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 867 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 868 | if (*fspnum == LPDDR4_FSP_0) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 869 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG)), *cycles); |
| 870 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 871 | } else if (*fspnum == LPDDR4_FSP_1) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 872 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG)), *cycles); |
| 873 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 874 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 875 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG)), *cycles); |
| 876 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 877 | } |
| 878 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 879 | static void writesrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 880 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 881 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 882 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 883 | if (*fspnum == LPDDR4_FSP_0) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 884 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__REG)), *cycles); |
| 885 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 886 | } else if (*fspnum == LPDDR4_FSP_1) { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 887 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F1__REG)), *cycles); |
| 888 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F1__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 889 | } else { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 890 | regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F2__REG)), *cycles); |
| 891 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F2__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 895 | static void lpddr4_writelpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 896 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 897 | if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 898 | writepdwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 899 | else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 900 | writesrshortwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 901 | else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 902 | writesrlongwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 903 | else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 904 | writesrlonggatewakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 905 | else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 906 | writesrdpshortwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 907 | else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 908 | writesrdplongwakeup(fspnum, ctlregbase, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 909 | else |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 910 | writesrdplonggatewakeup(fspnum, ctlregbase, cycles); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 911 | } |
| 912 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 913 | u32 lpddr4_setlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 914 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 915 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 916 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 917 | result = lpddr4_setlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles); |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 918 | if (result == (u32)0) { |
| 919 | if (*cycles > NIBBLE_MASK) |
| 920 | result = (u32)EINVAL; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 921 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 922 | if (result == (u32)0) { |
| 923 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 924 | lpddr4_writelpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 925 | } |
| 926 | return result; |
| 927 | } |
| 928 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 929 | u32 lpddr4_getdbireadmode(const lpddr4_privatedata *pd, bool *on_off) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 930 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 931 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 932 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 933 | result = lpddr4_getdbireadmodesf(pd, on_off); |
| 934 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 935 | if (result == (u32)0) { |
| 936 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 937 | if (CPS_FLD_READ(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG))) == 0U) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 938 | *on_off = false; |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 939 | else |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 940 | *on_off = true; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 941 | } |
| 942 | return result; |
| 943 | } |
| 944 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 945 | u32 lpddr4_getdbiwritemode(const lpddr4_privatedata *pd, bool *on_off) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 946 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 947 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 948 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 949 | result = lpddr4_getdbireadmodesf(pd, on_off); |
| 950 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 951 | if (result == (u32)0) { |
| 952 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 953 | if (CPS_FLD_READ(LPDDR4__WR_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WR_DBI_EN__REG))) == 0U) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 954 | *on_off = false; |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 955 | else |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 956 | *on_off = true; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 957 | } |
| 958 | return result; |
| 959 | } |
| 960 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 961 | u32 lpddr4_setdbimode(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 962 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 963 | u32 result = 0U; |
| 964 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 965 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 966 | result = lpddr4_setdbimodesf(pd, mode); |
| 967 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 968 | if (result == (u32)0) { |
| 969 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 970 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 971 | if (*mode == LPDDR4_DBI_RD_ON) |
| 972 | regval = CPS_FLD_WRITE(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG)), 1U); |
| 973 | else if (*mode == LPDDR4_DBI_RD_OFF) |
| 974 | regval = CPS_FLD_WRITE(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG)), 0U); |
| 975 | else if (*mode == LPDDR4_DBI_WR_ON) |
| 976 | regval = CPS_FLD_WRITE(LPDDR4__WR_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WR_DBI_EN__REG)), 1U); |
| 977 | else |
| 978 | regval = CPS_FLD_WRITE(LPDDR4__WR_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WR_DBI_EN__REG)), 0U); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 979 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__RD_DBI_EN__REG), regval); |
| 980 | } |
| 981 | return result; |
| 982 | } |
| 983 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 984 | u32 lpddr4_getrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, u32 *tref, u32 *tras_max) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 985 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 986 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 987 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 988 | result = lpddr4_getrefreshratesf(pd, fspnum, tref, tras_max); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 989 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 990 | if (result == (u32)0) { |
| 991 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 992 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 993 | switch (*fspnum) { |
| 994 | case LPDDR4_FSP_2: |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 995 | *tref = CPS_FLD_READ(LPDDR4__TREF_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F2__REG))); |
| 996 | *tras_max = CPS_FLD_READ(LPDDR4__TRAS_MAX_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 997 | break; |
| 998 | case LPDDR4_FSP_1: |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 999 | *tref = CPS_FLD_READ(LPDDR4__TREF_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F1__REG))); |
| 1000 | *tras_max = CPS_FLD_READ(LPDDR4__TRAS_MAX_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1001 | break; |
| 1002 | default: |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1003 | *tref = CPS_FLD_READ(LPDDR4__TREF_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F0__REG))); |
| 1004 | *tras_max = CPS_FLD_READ(LPDDR4__TRAS_MAX_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG))); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | return result; |
| 1009 | } |
| 1010 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1011 | static void lpddr4_updatefsp2refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1012 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1013 | u32 regval = 0U; |
| 1014 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1015 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1016 | regval = CPS_FLD_WRITE(LPDDR4__TREF_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F2__REG)), *tref); |
| 1017 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F2__REG), regval); |
| 1018 | regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG)), *tras_max); |
| 1019 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG), regval); |
| 1020 | } |
| 1021 | |
| 1022 | static void lpddr4_updatefsp1refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max) |
| 1023 | { |
| 1024 | u32 regval = 0U; |
| 1025 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 1026 | |
| 1027 | regval = CPS_FLD_WRITE(LPDDR4__TREF_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F1__REG)), *tref); |
| 1028 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F1__REG), regval); |
| 1029 | regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG)), *tras_max); |
| 1030 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG), regval);; |
| 1031 | } |
| 1032 | |
| 1033 | static void lpddr4_updatefsp0refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max) |
| 1034 | { |
| 1035 | u32 regval = 0U; |
| 1036 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 1037 | |
| 1038 | regval = CPS_FLD_WRITE(LPDDR4__TREF_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F0__REG)), *tref); |
| 1039 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F0__REG), regval); |
| 1040 | regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG)), *tras_max); |
| 1041 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG), regval); |
| 1042 | } |
| 1043 | |
| 1044 | u32 lpddr4_setrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max) |
| 1045 | { |
| 1046 | u32 result = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1047 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1048 | result = lpddr4_setrefreshratesf(pd, fspnum, tref, tras_max); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1049 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1050 | if (result == (u32)0) { |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1051 | switch (*fspnum) { |
| 1052 | case LPDDR4_FSP_2: |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1053 | lpddr4_updatefsp2refrateparams(pd, tref, tras_max); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1054 | break; |
| 1055 | case LPDDR4_FSP_1: |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1056 | lpddr4_updatefsp1refrateparams(pd, tref, tras_max); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1057 | break; |
| 1058 | default: |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1059 | lpddr4_updatefsp0refrateparams(pd, tref, tras_max); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1060 | break; |
| 1061 | } |
| 1062 | } |
| 1063 | return result; |
| 1064 | } |
| 1065 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1066 | u32 lpddr4_refreshperchipselect(const lpddr4_privatedata *pd, const u32 trefinterval) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1067 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1068 | u32 result = 0U; |
| 1069 | u32 regval = 0U; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1070 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1071 | result = lpddr4_refreshperchipselectsf(pd); |
| 1072 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 1073 | if (result == (u32)0) { |
| 1074 | lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase; |
| 1075 | regval = CPS_FLD_WRITE(LPDDR4__TREF_INTERVAL__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_INTERVAL__REG)), trefinterval); |
| 1076 | CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_INTERVAL__REG), regval); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1077 | } |
| 1078 | return result; |
| 1079 | } |