blob: 11ef242a37bef90a6de78f964b0c26fe70b277c6 [file] [log] [blame]
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301// SPDX-License-Identifier: BSD-3-Clause
Dave Gerlachd712b362021-05-11 10:22:11 -05002/*
3 * Cadence DDR Driver
Kevin Scholz521a4ef2019-10-07 19:26:36 +05304 *
Bryan Brattlof85b5cc82022-10-24 16:53:28 -05005 * Copyright (C) 2012-2022 Cadence Design Systems, Inc.
6 * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
Kevin Scholz521a4ef2019-10-07 19:26:36 +05307 */
Dave Gerlachd712b362021-05-11 10:22:11 -05008
9#include <errno.h>
10
Kevin Scholz521a4ef2019-10-07 19:26:36 +053011#include "cps_drv_lpddr4.h"
Kevin Scholz521a4ef2019-10-07 19:26:36 +053012#include "lpddr4_if.h"
Dave Gerlachd712b362021-05-11 10:22:11 -050013#include "lpddr4.h"
Kevin Scholz521a4ef2019-10-07 19:26:36 +053014#include "lpddr4_structs_if.h"
15
Dave Gerlachd712b362021-05-11 10:22:11 -050016static u32 lpddr4_pollphyindepirq(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt irqbit, u32 delay);
17static u32 lpddr4_pollandackirq(const lpddr4_privatedata *pd);
18static u32 lpddr4_startsequencecontroller(const lpddr4_privatedata *pd);
19static u32 lpddr4_writemmrregister(const lpddr4_privatedata *pd, u32 writemoderegval);
20static void lpddr4_checkcatrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
21static void lpddr4_checkgatelvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
22static void lpddr4_checkreadlvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
23static void lpddr4_checkdqtrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
24static u8 lpddr4_seterror(volatile u32 *reg, u32 errbitmask, u8 *errfoundptr, const u32 errorinfobits);
25static void lpddr4_setphysnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound);
26static void lpddr4_setphyadrsnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound);
27static void readpdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
28static void readsrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
29static void readsrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
30static void readsrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
31static void readsrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
32static void readsrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
33static void readsrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
34static void lpddr4_readlpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles);
35static void writepdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
36static void writesrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
37static void writesrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
38static void writesrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
39static void writesrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
40static void writesrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
41static void writesrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
42static void lpddr4_writelpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles);
43static void lpddr4_updatefsp2refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max);
44static void lpddr4_updatefsp1refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max);
45static void lpddr4_updatefsp0refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max);
Dave Gerlachd712b362021-05-11 10:22:11 -050046static u32 lpddr4_getphyrwmask(u32 regoffset);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053047
Dave Gerlachd712b362021-05-11 10:22:11 -050048u32 lpddr4_pollctlirq(const lpddr4_privatedata *pd, lpddr4_intr_ctlinterrupt irqbit, u32 delay)
49{
50 u32 result = 0U;
51 u32 timeout = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053052 bool irqstatus = false;
53
Kevin Scholz521a4ef2019-10-07 19:26:36 +053054 do {
55 if (++timeout == delay) {
Dave Gerlachd712b362021-05-11 10:22:11 -050056 result = (u32)EIO;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053057 break;
58 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +053059 result = lpddr4_checkctlinterrupt(pd, irqbit, &irqstatus);
Dave Gerlachd712b362021-05-11 10:22:11 -050060 } while ((irqstatus == (bool)false) && (result == (u32)0));
Kevin Scholz521a4ef2019-10-07 19:26:36 +053061
62 return result;
63}
64
Dave Gerlachd712b362021-05-11 10:22:11 -050065static u32 lpddr4_pollphyindepirq(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt irqbit, u32 delay)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053066{
Dave Gerlachd712b362021-05-11 10:22:11 -050067 u32 result = 0U;
68 u32 timeout = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053069 bool irqstatus = false;
70
Kevin Scholz521a4ef2019-10-07 19:26:36 +053071 do {
72 if (++timeout == delay) {
Dave Gerlachd712b362021-05-11 10:22:11 -050073 result = (u32)EIO;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053074 break;
75 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +053076 result = lpddr4_checkphyindepinterrupt(pd, irqbit, &irqstatus);
Dave Gerlachd712b362021-05-11 10:22:11 -050077 } while ((irqstatus == (bool)false) && (result == (u32)0));
Kevin Scholz521a4ef2019-10-07 19:26:36 +053078
79 return result;
80}
81
Dave Gerlachd712b362021-05-11 10:22:11 -050082static u32 lpddr4_pollandackirq(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053083{
Dave Gerlachd712b362021-05-11 10:22:11 -050084 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053085
Dave Gerlachd712b362021-05-11 10:22:11 -050086 result = lpddr4_pollphyindepirq(pd, LPDDR4_INTR_PHY_INDEP_INIT_DONE_BIT, LPDDR4_CUSTOM_TIMEOUT_DELAY);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053087
Dave Gerlachd712b362021-05-11 10:22:11 -050088 if (result == (u32)0)
89 result = lpddr4_ackphyindepinterrupt(pd, LPDDR4_INTR_PHY_INDEP_INIT_DONE_BIT);
90 if (result == (u32)0)
91 result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MC_INIT_DONE, LPDDR4_CUSTOM_TIMEOUT_DELAY);
92 if (result == (u32)0)
93 result = lpddr4_ackctlinterrupt(pd, LPDDR4_INTR_MC_INIT_DONE);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053094 return result;
95}
96
Dave Gerlachd712b362021-05-11 10:22:11 -050097static u32 lpddr4_startsequencecontroller(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053098{
Dave Gerlachd712b362021-05-11 10:22:11 -050099 u32 result = 0U;
100 u32 regval = 0U;
101 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530102 lpddr4_infotype infotype;
103
Dave Gerlachd712b362021-05-11 10:22:11 -0500104 regval = CPS_FLD_SET(LPDDR4__PI_START__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__PI_START__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530105 CPS_REG_WRITE((&(ctlregbase->LPDDR4__PI_START__REG)), regval);
106
Dave Gerlachd712b362021-05-11 10:22:11 -0500107 regval = CPS_FLD_SET(LPDDR4__START__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__START__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530108 CPS_REG_WRITE(&(ctlregbase->LPDDR4__START__REG), regval);
109
Dave Gerlachd712b362021-05-11 10:22:11 -0500110 if (pd->infohandler != (lpddr4_infocallback)NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530111 infotype = LPDDR4_DRV_SOC_PLL_UPDATE;
112 pd->infohandler(pd, infotype);
113 }
114
115 result = lpddr4_pollandackirq(pd);
116
117 return result;
118}
119
Dave Gerlachd712b362021-05-11 10:22:11 -0500120volatile u32 *lpddr4_addoffset(volatile u32 *addr, u32 regoffset)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530121{
Dave Gerlachd712b362021-05-11 10:22:11 -0500122 volatile u32 *local_addr = addr;
123 volatile u32 *regaddr = &local_addr[regoffset];
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530124
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530125 return regaddr;
126}
127
Dave Gerlachd712b362021-05-11 10:22:11 -0500128u32 lpddr4_probe(const lpddr4_config *config, u16 *configsize)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530129{
Dave Gerlachd712b362021-05-11 10:22:11 -0500130 u32 result;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530131
Dave Gerlachd712b362021-05-11 10:22:11 -0500132 result = (u32)(lpddr4_probesf(config, configsize));
133 if (result == (u32)0)
134 *configsize = (u16)(sizeof(lpddr4_privatedata));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530135 return result;
136}
137
Dave Gerlachd712b362021-05-11 10:22:11 -0500138u32 lpddr4_init(lpddr4_privatedata *pd, const lpddr4_config *cfg)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530139{
Dave Gerlachd712b362021-05-11 10:22:11 -0500140 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530141
142 result = lpddr4_initsf(pd, cfg);
Dave Gerlachd712b362021-05-11 10:22:11 -0500143 if (result == (u32)0) {
144 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)cfg->ctlbase;
145 pd->ctlbase = ctlregbase;
146 pd->infohandler = (lpddr4_infocallback)cfg->infohandler;
147 pd->ctlinterrupthandler = (lpddr4_ctlcallback)cfg->ctlinterrupthandler;
148 pd->phyindepinterrupthandler = (lpddr4_phyindepcallback)cfg->phyindepinterrupthandler;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530149 }
150 return result;
151}
152
Dave Gerlachd712b362021-05-11 10:22:11 -0500153u32 lpddr4_start(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530154{
Dave Gerlachd712b362021-05-11 10:22:11 -0500155 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530156
157 result = lpddr4_startsf(pd);
Dave Gerlachd712b362021-05-11 10:22:11 -0500158 if (result == (u32)0) {
159 result = lpddr4_enablepiinitiator(pd);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530160 result = lpddr4_startsequencecontroller(pd);
161 }
162 return result;
163}
164
Dave Gerlachd712b362021-05-11 10:22:11 -0500165u32 lpddr4_readreg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 *regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530166{
Dave Gerlachd712b362021-05-11 10:22:11 -0500167 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530168
169 result = lpddr4_readregsf(pd, cpp, regvalue);
Dave Gerlachd712b362021-05-11 10:22:11 -0500170 if (result == (u32)0) {
171 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530172
173 if (cpp == LPDDR4_CTL_REGS) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500174 if (regoffset >= LPDDR4_INTR_CTL_REG_COUNT)
175 result = (u32)EINVAL;
176 else
177 *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_CTL_0), regoffset));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530178 } else if (cpp == LPDDR4_PHY_REGS) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500179 if (regoffset >= LPDDR4_INTR_PHY_REG_COUNT)
180 result = (u32)EINVAL;
181 else
182 *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_PHY_0), regoffset));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530183
184 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500185 if (regoffset >= LPDDR4_INTR_PHY_INDEP_REG_COUNT)
186 result = (u32)EINVAL;
187 else
188 *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_PI_0), regoffset));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530189 }
190 }
191 return result;
192}
193
Dave Gerlachd712b362021-05-11 10:22:11 -0500194static u32 lpddr4_getphyrwmask(u32 regoffset)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530195{
Dave Gerlachd712b362021-05-11 10:22:11 -0500196 u32 rwmask = 0U;
197 u32 arrayoffset = 0U;
198 u32 slicenum, sliceoffset = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530199
Dave Gerlachd712b362021-05-11 10:22:11 -0500200 for (slicenum = (u32)0U; slicenum <= (DSLICE_NUM + ASLICE_NUM); slicenum++) {
201 sliceoffset = sliceoffset + (u32)SLICE_WIDTH;
202 if (regoffset < sliceoffset)
203 break;
204 }
205 arrayoffset = regoffset - (sliceoffset - (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530206
Dave Gerlachd712b362021-05-11 10:22:11 -0500207 if (slicenum < DSLICE_NUM) {
208 rwmask = lpddr4_getdslicemask(slicenum, arrayoffset);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530209 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500210 if (slicenum == DSLICE_NUM) {
211 if (arrayoffset < ASLICE0_REG_COUNT)
212 rwmask = g_lpddr4_address_slice_0_rw_mask[arrayoffset];
213 } else {
214 if (arrayoffset < PHY_CORE_REG_COUNT)
215 rwmask = g_lpddr4_phy_core_rw_mask[arrayoffset];
216 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530217 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500218 return rwmask;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530219}
220
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500221u32 lpddr4_deferredregverify(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530222{
Dave Gerlachd712b362021-05-11 10:22:11 -0500223 u32 result = (u32)0;
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500224 u32 aindex;
Dave Gerlachd712b362021-05-11 10:22:11 -0500225 u32 regreadval = 0U;
226 u32 rwmask = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530227
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500228 result = lpddr4_deferredregverifysf(pd, cpp);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530229
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500230 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
231 result = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500232 if (result == (u32)0) {
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500233 for (aindex = 0; aindex < regcount; aindex++) {
234 result = lpddr4_readreg(pd, cpp, (u32)regnum[aindex], &regreadval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530235
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500236 if (result == (u32)0) {
237 switch (cpp) {
238 case LPDDR4_PHY_INDEP_REGS:
239 rwmask = g_lpddr4_pi_rw_mask[(u32)regnum[aindex]];
240 break;
241 case LPDDR4_PHY_REGS:
242 rwmask = lpddr4_getphyrwmask((u32)regnum[aindex]);
243 break;
244 default:
245 rwmask = g_lpddr4_ddr_controller_rw_mask[(u32)regnum[aindex]];
246 break;
247 }
248
249 if ((rwmask & regreadval) != ((u32)(regvalues[aindex]) & rwmask)) {
250 result = EIO;
251 break;
252 }
253 }
254 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530255 }
256 return result;
257}
258
Dave Gerlachd712b362021-05-11 10:22:11 -0500259u32 lpddr4_writereg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530260{
Dave Gerlachd712b362021-05-11 10:22:11 -0500261 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530262
Dave Gerlachd712b362021-05-11 10:22:11 -0500263 result = lpddr4_writeregsf(pd, cpp);
264 if (result == (u32)0) {
265 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530266
Dave Gerlachd712b362021-05-11 10:22:11 -0500267 if (cpp == LPDDR4_CTL_REGS) {
268 if (regoffset >= LPDDR4_INTR_CTL_REG_COUNT)
269 result = (u32)EINVAL;
270 else
271 CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_CTL_0), regoffset), regvalue);
272 } else if (cpp == LPDDR4_PHY_REGS) {
273 if (regoffset >= LPDDR4_INTR_PHY_REG_COUNT)
274 result = (u32)EINVAL;
275 else
276 CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_PHY_0), regoffset), regvalue);
277 } else {
278 if (regoffset >= LPDDR4_INTR_PHY_INDEP_REG_COUNT)
279 result = (u32)EINVAL;
280 else
281 CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_PI_0), regoffset), regvalue);
282 }
283 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530284
285 return result;
286}
287
Dave Gerlachd712b362021-05-11 10:22:11 -0500288u32 lpddr4_getmmrregister(const lpddr4_privatedata *pd, u32 readmoderegval, u64 *mmrvalue, u8 *mmrstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530289{
Dave Gerlachd712b362021-05-11 10:22:11 -0500290 u32 result = 0U;
291 u32 tdelay = 1000U;
292 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530293
Dave Gerlachd712b362021-05-11 10:22:11 -0500294 result = lpddr4_getmmrregistersf(pd, mmrvalue, mmrstatus);
295 if (result == (u32)0) {
296 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530297
Dave Gerlachd712b362021-05-11 10:22:11 -0500298 regval = CPS_FLD_WRITE(LPDDR4__READ_MODEREG__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__READ_MODEREG__REG)), readmoderegval);
299 CPS_REG_WRITE(&(ctlregbase->LPDDR4__READ_MODEREG__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530300
Dave Gerlachd712b362021-05-11 10:22:11 -0500301 result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_READ_DONE, tdelay);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530302 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500303 if (result == (u32)0)
304 result = lpddr4_checkmmrreaderror(pd, mmrvalue, mmrstatus);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530305 return result;
306}
307
Dave Gerlachd712b362021-05-11 10:22:11 -0500308static u32 lpddr4_writemmrregister(const lpddr4_privatedata *pd, u32 writemoderegval)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530309{
Dave Gerlachd712b362021-05-11 10:22:11 -0500310 u32 result = (u32)0;
311 u32 tdelay = 1000U;
312 u32 regval = 0U;
313 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
314
315 regval = CPS_FLD_WRITE(LPDDR4__WRITE_MODEREG__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WRITE_MODEREG__REG)), writemoderegval);
316 CPS_REG_WRITE(&(ctlregbase->LPDDR4__WRITE_MODEREG__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530317
Dave Gerlachd712b362021-05-11 10:22:11 -0500318 result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_WRITE_DONE, tdelay);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530319
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530320 return result;
321}
322
Dave Gerlachd712b362021-05-11 10:22:11 -0500323u32 lpddr4_setmmrregister(const lpddr4_privatedata *pd, u32 writemoderegval, u8 *mrwstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530324{
Dave Gerlachd712b362021-05-11 10:22:11 -0500325 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530326
Dave Gerlachd712b362021-05-11 10:22:11 -0500327 result = lpddr4_setmmrregistersf(pd, mrwstatus);
328 if (result == (u32)0) {
329 result = lpddr4_writemmrregister(pd, writemoderegval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530330
Dave Gerlachd712b362021-05-11 10:22:11 -0500331 if (result == (u32)0)
332 result = lpddr4_ackctlinterrupt(pd, LPDDR4_INTR_MR_WRITE_DONE);
333 if (result == (u32)0) {
334 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
335 *mrwstatus = (u8)CPS_FLD_READ(LPDDR4__MRW_STATUS__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__MRW_STATUS__REG)));
336 if ((*mrwstatus) != 0U)
337 result = (u32)EIO;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530338 }
339 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530340
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530341 return result;
342}
343
Dave Gerlachd712b362021-05-11 10:22:11 -0500344u32 lpddr4_writectlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530345{
Dave Gerlachd712b362021-05-11 10:22:11 -0500346 u32 result;
347 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530348
Dave Gerlachd712b362021-05-11 10:22:11 -0500349 result = lpddr4_writectlconfigsf(pd);
350 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
351 result = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530352
Dave Gerlachd712b362021-05-11 10:22:11 -0500353 if (result == (u32)0) {
354 for (aindex = 0; aindex < regcount; aindex++)
355 result = (u32)lpddr4_writereg(pd, LPDDR4_CTL_REGS, (u32)regnum[aindex],
356 (u32)regvalues[aindex]);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530357 }
358 return result;
359}
360
Dave Gerlachd712b362021-05-11 10:22:11 -0500361u32 lpddr4_writephyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530362{
Dave Gerlachd712b362021-05-11 10:22:11 -0500363 u32 result;
364 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530365
Dave Gerlachd712b362021-05-11 10:22:11 -0500366 result = lpddr4_writephyindepconfigsf(pd);
367 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
368 result = EINVAL;
369 if (result == (u32)0) {
370 for (aindex = 0; aindex < regcount; aindex++)
371 result = (u32)lpddr4_writereg(pd, LPDDR4_PHY_INDEP_REGS, (u32)regnum[aindex],
372 (u32)regvalues[aindex]);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530373 }
374 return result;
375}
376
Dave Gerlachd712b362021-05-11 10:22:11 -0500377u32 lpddr4_writephyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530378{
Dave Gerlachd712b362021-05-11 10:22:11 -0500379 u32 result;
380 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530381
Dave Gerlachd712b362021-05-11 10:22:11 -0500382 result = lpddr4_writephyconfigsf(pd);
383 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
384 result = EINVAL;
385 if (result == (u32)0) {
386 for (aindex = 0; aindex < regcount; aindex++)
387 result = (u32)lpddr4_writereg(pd, LPDDR4_PHY_REGS, (u32)regnum[aindex],
388 (u32)regvalues[aindex]);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530389 }
390 return result;
391}
392
Dave Gerlachd712b362021-05-11 10:22:11 -0500393u32 lpddr4_readctlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530394{
Dave Gerlachd712b362021-05-11 10:22:11 -0500395 u32 result;
396 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530397
Dave Gerlachd712b362021-05-11 10:22:11 -0500398 result = lpddr4_readctlconfigsf(pd);
399 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
400 result = EINVAL;
401 if (result == (u32)0) {
402 for (aindex = 0; aindex < regcount; aindex++)
403 result = (u32)lpddr4_readreg(pd, LPDDR4_CTL_REGS, (u32)regnum[aindex],
404 (u32 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530405 }
406 return result;
407}
408
Dave Gerlachd712b362021-05-11 10:22:11 -0500409u32 lpddr4_readphyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530410{
Dave Gerlachd712b362021-05-11 10:22:11 -0500411 u32 result;
412 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530413
Dave Gerlachd712b362021-05-11 10:22:11 -0500414 result = lpddr4_readphyindepconfigsf(pd);
415 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
416 result = EINVAL;
417 if (result == (u32)0) {
418 for (aindex = 0; aindex < regcount; aindex++)
419 result = (u32)lpddr4_readreg(pd, LPDDR4_PHY_INDEP_REGS, (u32)regnum[aindex],
420 (u32 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530421 }
422 return result;
423}
424
Dave Gerlachd712b362021-05-11 10:22:11 -0500425u32 lpddr4_readphyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530426{
Dave Gerlachd712b362021-05-11 10:22:11 -0500427 u32 result;
428 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530429
Dave Gerlachd712b362021-05-11 10:22:11 -0500430 result = lpddr4_readphyconfigsf(pd);
431 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
432 result = EINVAL;
433 if (result == (u32)0) {
434 for (aindex = 0; aindex < regcount; aindex++)
435 result = (u32)lpddr4_readreg(pd, LPDDR4_PHY_REGS, (u32)regnum[aindex],
436 (u32 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530437 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530438 return result;
439}
440
Dave Gerlachd712b362021-05-11 10:22:11 -0500441u32 lpddr4_getphyindepinterruptmask(const lpddr4_privatedata *pd, u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530442{
Dave Gerlachd712b362021-05-11 10:22:11 -0500443 u32 result;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530444
445 result = lpddr4_getphyindepinterruptmsf(pd, mask);
Dave Gerlachd712b362021-05-11 10:22:11 -0500446 if (result == (u32)0) {
447 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
448 *mask = CPS_FLD_READ(LPDDR4__PI_INT_MASK__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_MASK__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530449 }
450 return result;
451}
452
Dave Gerlachd712b362021-05-11 10:22:11 -0500453u32 lpddr4_setphyindepinterruptmask(const lpddr4_privatedata *pd, const u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530454{
Dave Gerlachd712b362021-05-11 10:22:11 -0500455 u32 result;
456 u32 regval = 0;
457 const u32 ui32irqcount = (u32)LPDDR4_INTR_PHY_INDEP_DLL_LOCK_STATE_CHANGE_BIT + 1U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530458
459 result = lpddr4_setphyindepinterruptmsf(pd, mask);
Dave Gerlachd712b362021-05-11 10:22:11 -0500460 if ((result == (u32)0) && (ui32irqcount < WORD_SHIFT)) {
461 if (*mask >= (1U << ui32irqcount))
462 result = (u32)EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530463 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500464 if (result == (u32)0) {
465 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530466
Dave Gerlachd712b362021-05-11 10:22:11 -0500467 regval = CPS_FLD_WRITE(LPDDR4__PI_INT_MASK__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_MASK__REG)), *mask);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530468 CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_MASK__REG), regval);
469 }
470 return result;
471}
472
Dave Gerlachd712b362021-05-11 10:22:11 -0500473u32 lpddr4_checkphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr, bool *irqstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530474{
Dave Gerlachd712b362021-05-11 10:22:11 -0500475 u32 result = 0;
476 u32 phyindepirqstatus = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530477
Dave Gerlachd712b362021-05-11 10:22:11 -0500478 result = LPDDR4_INTR_CheckPhyIndepIntSF(pd, intr, irqstatus);
479 if ((result == (u32)0) && ((u32)intr < WORD_SHIFT)) {
480 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530481
Dave Gerlachd712b362021-05-11 10:22:11 -0500482 phyindepirqstatus = CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_STATUS__REG));
483 *irqstatus = (bool)(((phyindepirqstatus >> (u32)intr) & LPDDR4_BIT_MASK) > 0U);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530484 }
485 return result;
486}
487
Dave Gerlachd712b362021-05-11 10:22:11 -0500488u32 lpddr4_ackphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530489{
Dave Gerlachd712b362021-05-11 10:22:11 -0500490 u32 result = 0U;
491 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530492
Dave Gerlachd712b362021-05-11 10:22:11 -0500493 result = LPDDR4_INTR_AckPhyIndepIntSF(pd, intr);
494 if ((result == (u32)0) && ((u32)intr < WORD_SHIFT)) {
495 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530496
Dave Gerlachd712b362021-05-11 10:22:11 -0500497 regval = ((u32)LPDDR4_BIT_MASK << (u32)intr);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530498 CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_ACK__REG), regval);
499 }
500
501 return result;
502}
503
Dave Gerlachd712b362021-05-11 10:22:11 -0500504static void lpddr4_checkcatrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530505{
Dave Gerlachd712b362021-05-11 10:22:11 -0500506 u32 regval;
507 u32 errbitmask = 0U;
508 u32 snum;
509 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530510
Dave Gerlachd712b362021-05-11 10:22:11 -0500511 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_ADR_CALVL_OBS1_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530512 errbitmask = (CA_TRAIN_RL) | (NIBBLE_MASK);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530513 for (snum = 0U; snum < ASLICE_NUM; snum++) {
514 regval = CPS_REG_READ(regaddress);
515 if ((regval & errbitmask) != CA_TRAIN_RL) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500516 debuginfo->catraingerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530517 *errfoundptr = true;
518 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500519 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530520 }
521}
522
Dave Gerlachd712b362021-05-11 10:22:11 -0500523static void lpddr4_checkgatelvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530524{
Dave Gerlachd712b362021-05-11 10:22:11 -0500525 u32 regval;
526 u32 errbitmask = 0U;
527 u32 snum;
528 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530529
Dave Gerlachd712b362021-05-11 10:22:11 -0500530 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_GTLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530531 errbitmask = GATE_LVL_ERROR_FIELDS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500532 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530533 regval = CPS_REG_READ(regaddress);
534 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500535 debuginfo->gatelvlerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530536 *errfoundptr = true;
537 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500538 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530539 }
540}
541
Dave Gerlachd712b362021-05-11 10:22:11 -0500542static void lpddr4_checkreadlvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530543{
Dave Gerlachd712b362021-05-11 10:22:11 -0500544 u32 regval;
545 u32 errbitmask = 0U;
546 u32 snum;
547 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530548
Dave Gerlachd712b362021-05-11 10:22:11 -0500549 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_RDLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530550 errbitmask = READ_LVL_ERROR_FIELDS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500551 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530552 regval = CPS_REG_READ(regaddress);
553 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500554 debuginfo->readlvlerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530555 *errfoundptr = true;
556 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500557 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530558 }
559}
560
Dave Gerlachd712b362021-05-11 10:22:11 -0500561static void lpddr4_checkdqtrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530562{
Dave Gerlachd712b362021-05-11 10:22:11 -0500563 u32 regval;
564 u32 errbitmask = 0U;
565 u32 snum;
566 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530567
Dave Gerlachd712b362021-05-11 10:22:11 -0500568 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_WDQLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530569 errbitmask = DQ_LVL_STATUS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500570 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530571 regval = CPS_REG_READ(regaddress);
572 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500573 debuginfo->dqtrainingerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530574 *errfoundptr = true;
575 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500576 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530577 }
578}
579
Dave Gerlachd712b362021-05-11 10:22:11 -0500580bool lpddr4_checklvlerrors(const lpddr4_privatedata *pd, lpddr4_debuginfo *debuginfo, bool errfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530581{
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530582 bool localerrfound = errfound;
583
Dave Gerlachd712b362021-05-11 10:22:11 -0500584 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530585
Dave Gerlachd712b362021-05-11 10:22:11 -0500586 if (localerrfound == (bool)false)
587 lpddr4_checkcatrainingerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530588
Dave Gerlachd712b362021-05-11 10:22:11 -0500589 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530590 lpddr4_checkwrlvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530591
Dave Gerlachd712b362021-05-11 10:22:11 -0500592 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530593 lpddr4_checkgatelvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530594
Dave Gerlachd712b362021-05-11 10:22:11 -0500595 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530596 lpddr4_checkreadlvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530597
Dave Gerlachd712b362021-05-11 10:22:11 -0500598 if (localerrfound == (bool)false)
599 lpddr4_checkdqtrainingerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530600 return localerrfound;
601}
602
Dave Gerlachd712b362021-05-11 10:22:11 -0500603static u8 lpddr4_seterror(volatile u32 *reg, u32 errbitmask, u8 *errfoundptr, const u32 errorinfobits)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530604{
Dave Gerlachd712b362021-05-11 10:22:11 -0500605 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530606
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530607 regval = CPS_REG_READ(reg);
Dave Gerlachd712b362021-05-11 10:22:11 -0500608 if ((regval & errbitmask) != errorinfobits)
609 *errfoundptr = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530610 return *errfoundptr;
611}
612
Dave Gerlachd712b362021-05-11 10:22:11 -0500613void lpddr4_seterrors(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, u8 *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530614{
Dave Gerlachd712b362021-05-11 10:22:11 -0500615 u32 errbitmask = (LPDDR4_BIT_MASK << 0x1U) | (LPDDR4_BIT_MASK);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530616
Dave Gerlachd712b362021-05-11 10:22:11 -0500617 debuginfo->pllerror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_PLL_OBS_0__REG),
618 errbitmask, errfoundptr, PLL_READY);
619 if (*errfoundptr == CDN_FALSE)
620 debuginfo->pllerror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_PLL_OBS_1__REG),
621 errbitmask, errfoundptr, PLL_READY);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530622
Dave Gerlachd712b362021-05-11 10:22:11 -0500623 if (*errfoundptr == CDN_FALSE)
624 debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT_OBS_0__REG),
625 IO_CALIB_DONE, errfoundptr, IO_CALIB_DONE);
626 if (*errfoundptr == CDN_FALSE)
627 debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT2_OBS_0__REG),
628 IO_CALIB_DONE, errfoundptr, IO_CALIB_DONE);
629 if (*errfoundptr == CDN_FALSE)
630 debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT3_OBS_0__REG),
631 IO_CALIB_FIELD, errfoundptr, IO_CALIB_STATE);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530632}
633
Dave Gerlachd712b362021-05-11 10:22:11 -0500634static void lpddr4_setphysnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530635{
Dave Gerlachd712b362021-05-11 10:22:11 -0500636 u32 snum = 0U;
637 volatile u32 *regaddress;
638 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530639
Dave Gerlachd712b362021-05-11 10:22:11 -0500640 if (errorfound == (bool)false) {
641 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__SC_PHY_SNAP_OBS_REGS_0__REG));
642 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
643 regval = CPS_FLD_SET(LPDDR4__SC_PHY_SNAP_OBS_REGS_0__FLD, CPS_REG_READ(regaddress));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530644 CPS_REG_WRITE(regaddress, regval);
Dave Gerlachd712b362021-05-11 10:22:11 -0500645 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530646 }
647 }
648}
649
Dave Gerlachd712b362021-05-11 10:22:11 -0500650static void lpddr4_setphyadrsnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530651{
Dave Gerlachd712b362021-05-11 10:22:11 -0500652 u32 snum = 0U;
653 volatile u32 *regaddress;
654 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530655
Dave Gerlachd712b362021-05-11 10:22:11 -0500656 if (errorfound == (bool)false) {
657 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__SC_PHY_ADR_SNAP_OBS_REGS_0__REG));
658 for (snum = (u32)0U; snum < ASLICE_NUM; snum++) {
659 regval = CPS_FLD_SET(LPDDR4__SC_PHY_ADR_SNAP_OBS_REGS_0__FLD, CPS_REG_READ(regaddress));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530660 CPS_REG_WRITE(regaddress, regval);
Dave Gerlachd712b362021-05-11 10:22:11 -0500661 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530662 }
663 }
664}
665
Dave Gerlachd712b362021-05-11 10:22:11 -0500666void lpddr4_setsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530667{
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530668 lpddr4_setphysnapsettings(ctlregbase, errorfound);
669 lpddr4_setphyadrsnapsettings(ctlregbase, errorfound);
670}
671
Dave Gerlachd712b362021-05-11 10:22:11 -0500672static void readpdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530673{
Dave Gerlachd712b362021-05-11 10:22:11 -0500674 if (*fspnum == LPDDR4_FSP_0)
675 *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG)));
676 else if (*fspnum == LPDDR4_FSP_1)
677 *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG)));
678 else
679 *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530680}
681
Dave Gerlachd712b362021-05-11 10:22:11 -0500682static void readsrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530683{
Dave Gerlachd712b362021-05-11 10:22:11 -0500684 if (*fspnum == LPDDR4_FSP_0)
685 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG)));
686 else if (*fspnum == LPDDR4_FSP_1)
687 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG)));
688 else
689 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530690}
691
Dave Gerlachd712b362021-05-11 10:22:11 -0500692static void readsrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530693{
Dave Gerlachd712b362021-05-11 10:22:11 -0500694 if (*fspnum == LPDDR4_FSP_0)
695 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG)));
696 else if (*fspnum == LPDDR4_FSP_1)
697 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG)));
698 else
699 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530700}
701
Dave Gerlachd712b362021-05-11 10:22:11 -0500702static void readsrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530703{
Dave Gerlachd712b362021-05-11 10:22:11 -0500704 if (*fspnum == LPDDR4_FSP_0)
705 *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)));
706 else if (*fspnum == LPDDR4_FSP_1)
707 *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)));
708 else
709 *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 Scholz521a4ef2019-10-07 19:26:36 +0530710}
711
Dave Gerlachd712b362021-05-11 10:22:11 -0500712static void readsrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530713{
Dave Gerlachd712b362021-05-11 10:22:11 -0500714 if (*fspnum == LPDDR4_FSP_0)
715 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG)));
716 else if (*fspnum == LPDDR4_FSP_1)
717 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG)));
718 else
719 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530720}
721
Dave Gerlachd712b362021-05-11 10:22:11 -0500722static void readsrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530723{
Dave Gerlachd712b362021-05-11 10:22:11 -0500724 if (*fspnum == LPDDR4_FSP_0)
725 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG)));
726 else if (*fspnum == LPDDR4_FSP_1)
727 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG)));
728 else
729 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530730}
731
Dave Gerlachd712b362021-05-11 10:22:11 -0500732static void readsrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530733{
Dave Gerlachd712b362021-05-11 10:22:11 -0500734 if (*fspnum == LPDDR4_FSP_0)
735 *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)));
736 else if (*fspnum == LPDDR4_FSP_1)
737 *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)));
738 else
739 *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 Scholz521a4ef2019-10-07 19:26:36 +0530740
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530741}
742
Dave Gerlachd712b362021-05-11 10:22:11 -0500743static void lpddr4_readlpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530744{
Dave Gerlachd712b362021-05-11 10:22:11 -0500745 if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530746 readpdwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500747 else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530748 readsrshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500749 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530750 readsrlongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500751 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530752 readsrlonggatewakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500753 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530754 readsrdpshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500755 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530756 readsrdplongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500757 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530758 readsrdplonggatewakeup(fspnum, ctlregbase, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530759}
760
Dave Gerlachd712b362021-05-11 10:22:11 -0500761u32 lpddr4_getlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530762{
Dave Gerlachd712b362021-05-11 10:22:11 -0500763 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530764
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530765 result = lpddr4_getlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500766 if (result == (u32)0) {
767 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
768 lpddr4_readlpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530769 }
770 return result;
771}
772
Dave Gerlachd712b362021-05-11 10:22:11 -0500773static void writepdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530774{
Dave Gerlachd712b362021-05-11 10:22:11 -0500775 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530776
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530777 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500778 regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG)), *cycles);
779 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530780 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500781 regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG)), *cycles);
782 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530783 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500784 regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG)), *cycles);
785 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530786 }
787}
788
Dave Gerlachd712b362021-05-11 10:22:11 -0500789static void writesrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530790{
Dave Gerlachd712b362021-05-11 10:22:11 -0500791 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530792
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530793 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500794 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG)), *cycles);
795 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530796 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500797 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG)), *cycles);
798 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530799 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500800 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG)), *cycles);
801 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530802 }
803}
804
Dave Gerlachd712b362021-05-11 10:22:11 -0500805static void writesrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530806{
Dave Gerlachd712b362021-05-11 10:22:11 -0500807 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530808
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530809 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500810 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG)), *cycles);
811 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530812 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500813 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG)), *cycles);
814 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530815 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500816 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG)), *cycles);
817 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530818 }
819}
820
Dave Gerlachd712b362021-05-11 10:22:11 -0500821static void writesrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530822{
Dave Gerlachd712b362021-05-11 10:22:11 -0500823 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530824
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530825 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500826 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);
827 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530828 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500829 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);
830 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530831 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500832 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);
833 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530834 }
835}
836
Dave Gerlachd712b362021-05-11 10:22:11 -0500837static void writesrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530838{
Dave Gerlachd712b362021-05-11 10:22:11 -0500839 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530840
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530841 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500842 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG)), *cycles);
843 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530844 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500845 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG)), *cycles);
846 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530847 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500848 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG)), *cycles);
849 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530850 }
851}
852
Dave Gerlachd712b362021-05-11 10:22:11 -0500853static void writesrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530854{
Dave Gerlachd712b362021-05-11 10:22:11 -0500855 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530856
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530857 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500858 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG)), *cycles);
859 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530860 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500861 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG)), *cycles);
862 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530863 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500864 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG)), *cycles);
865 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530866 }
867}
Dave Gerlachd712b362021-05-11 10:22:11 -0500868static void writesrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530869{
Dave Gerlachd712b362021-05-11 10:22:11 -0500870 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530871
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530872 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500873 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);
874 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530875 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500876 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);
877 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530878 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500879 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);
880 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530881 }
882}
883
Dave Gerlachd712b362021-05-11 10:22:11 -0500884static void lpddr4_writelpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530885{
Dave Gerlachd712b362021-05-11 10:22:11 -0500886 if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530887 writepdwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500888 else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530889 writesrshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500890 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530891 writesrlongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500892 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530893 writesrlonggatewakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500894 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530895 writesrdpshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500896 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530897 writesrdplongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500898 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530899 writesrdplonggatewakeup(fspnum, ctlregbase, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530900}
901
Dave Gerlachd712b362021-05-11 10:22:11 -0500902u32 lpddr4_setlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530903{
Dave Gerlachd712b362021-05-11 10:22:11 -0500904 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530905
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530906 result = lpddr4_setlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500907 if (result == (u32)0) {
908 if (*cycles > NIBBLE_MASK)
909 result = (u32)EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530910 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500911 if (result == (u32)0) {
912 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
913 lpddr4_writelpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530914 }
915 return result;
916}
917
Dave Gerlachd712b362021-05-11 10:22:11 -0500918u32 lpddr4_getdbireadmode(const lpddr4_privatedata *pd, bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530919{
Dave Gerlachd712b362021-05-11 10:22:11 -0500920 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530921
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530922 result = lpddr4_getdbireadmodesf(pd, on_off);
923
Dave Gerlachd712b362021-05-11 10:22:11 -0500924 if (result == (u32)0) {
925 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
926 if (CPS_FLD_READ(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG))) == 0U)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530927 *on_off = false;
Dave Gerlachd712b362021-05-11 10:22:11 -0500928 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530929 *on_off = true;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530930 }
931 return result;
932}
933
Dave Gerlachd712b362021-05-11 10:22:11 -0500934u32 lpddr4_getdbiwritemode(const lpddr4_privatedata *pd, bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530935{
Dave Gerlachd712b362021-05-11 10:22:11 -0500936 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530937
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530938 result = lpddr4_getdbireadmodesf(pd, on_off);
939
Dave Gerlachd712b362021-05-11 10:22:11 -0500940 if (result == (u32)0) {
941 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
942 if (CPS_FLD_READ(LPDDR4__WR_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WR_DBI_EN__REG))) == 0U)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530943 *on_off = false;
Dave Gerlachd712b362021-05-11 10:22:11 -0500944 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530945 *on_off = true;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530946 }
947 return result;
948}
949
Dave Gerlachd712b362021-05-11 10:22:11 -0500950u32 lpddr4_setdbimode(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530951{
Dave Gerlachd712b362021-05-11 10:22:11 -0500952 u32 result = 0U;
953 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530954
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530955 result = lpddr4_setdbimodesf(pd, mode);
956
Dave Gerlachd712b362021-05-11 10:22:11 -0500957 if (result == (u32)0) {
958 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530959
Dave Gerlachd712b362021-05-11 10:22:11 -0500960 if (*mode == LPDDR4_DBI_RD_ON)
961 regval = CPS_FLD_WRITE(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG)), 1U);
962 else if (*mode == LPDDR4_DBI_RD_OFF)
963 regval = CPS_FLD_WRITE(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG)), 0U);
964 else if (*mode == LPDDR4_DBI_WR_ON)
965 regval = CPS_FLD_WRITE(LPDDR4__WR_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WR_DBI_EN__REG)), 1U);
966 else
967 regval = CPS_FLD_WRITE(LPDDR4__WR_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WR_DBI_EN__REG)), 0U);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530968 CPS_REG_WRITE(&(ctlregbase->LPDDR4__RD_DBI_EN__REG), regval);
969 }
970 return result;
971}
972
Dave Gerlachd712b362021-05-11 10:22:11 -0500973u32 lpddr4_getrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, u32 *tref, u32 *tras_max)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530974{
Dave Gerlachd712b362021-05-11 10:22:11 -0500975 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530976
Dave Gerlachd712b362021-05-11 10:22:11 -0500977 result = lpddr4_getrefreshratesf(pd, fspnum, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530978
Dave Gerlachd712b362021-05-11 10:22:11 -0500979 if (result == (u32)0) {
980 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530981
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530982 switch (*fspnum) {
983 case LPDDR4_FSP_2:
Dave Gerlachd712b362021-05-11 10:22:11 -0500984 *tref = CPS_FLD_READ(LPDDR4__TREF_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F2__REG)));
985 *tras_max = CPS_FLD_READ(LPDDR4__TRAS_MAX_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530986 break;
987 case LPDDR4_FSP_1:
Dave Gerlachd712b362021-05-11 10:22:11 -0500988 *tref = CPS_FLD_READ(LPDDR4__TREF_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F1__REG)));
989 *tras_max = CPS_FLD_READ(LPDDR4__TRAS_MAX_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530990 break;
991 default:
Dave Gerlachd712b362021-05-11 10:22:11 -0500992 *tref = CPS_FLD_READ(LPDDR4__TREF_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F0__REG)));
993 *tras_max = CPS_FLD_READ(LPDDR4__TRAS_MAX_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530994 break;
995 }
996 }
997 return result;
998}
999
Dave Gerlachd712b362021-05-11 10:22:11 -05001000static void lpddr4_updatefsp2refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max)
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301001{
Dave Gerlachd712b362021-05-11 10:22:11 -05001002 u32 regval = 0U;
1003 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301004
Dave Gerlachd712b362021-05-11 10:22:11 -05001005 regval = CPS_FLD_WRITE(LPDDR4__TREF_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F2__REG)), *tref);
1006 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F2__REG), regval);
1007 regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG)), *tras_max);
1008 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG), regval);
1009}
1010
1011static void lpddr4_updatefsp1refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max)
1012{
1013 u32 regval = 0U;
1014 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
1015
1016 regval = CPS_FLD_WRITE(LPDDR4__TREF_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F1__REG)), *tref);
1017 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F1__REG), regval);
1018 regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG)), *tras_max);
1019 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG), regval);;
1020}
1021
1022static void lpddr4_updatefsp0refrateparams(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_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F0__REG)), *tref);
1028 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F0__REG), regval);
1029 regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG)), *tras_max);
1030 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG), regval);
1031}
1032
1033u32 lpddr4_setrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max)
1034{
1035 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301036
Dave Gerlachd712b362021-05-11 10:22:11 -05001037 result = lpddr4_setrefreshratesf(pd, fspnum, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301038
Dave Gerlachd712b362021-05-11 10:22:11 -05001039 if (result == (u32)0) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301040 switch (*fspnum) {
1041 case LPDDR4_FSP_2:
Dave Gerlachd712b362021-05-11 10:22:11 -05001042 lpddr4_updatefsp2refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301043 break;
1044 case LPDDR4_FSP_1:
Dave Gerlachd712b362021-05-11 10:22:11 -05001045 lpddr4_updatefsp1refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301046 break;
1047 default:
Dave Gerlachd712b362021-05-11 10:22:11 -05001048 lpddr4_updatefsp0refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301049 break;
1050 }
1051 }
1052 return result;
1053}
1054
Dave Gerlachd712b362021-05-11 10:22:11 -05001055u32 lpddr4_refreshperchipselect(const lpddr4_privatedata *pd, const u32 trefinterval)
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301056{
Dave Gerlachd712b362021-05-11 10:22:11 -05001057 u32 result = 0U;
1058 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301059
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301060 result = lpddr4_refreshperchipselectsf(pd);
1061
Dave Gerlachd712b362021-05-11 10:22:11 -05001062 if (result == (u32)0) {
1063 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
1064 regval = CPS_FLD_WRITE(LPDDR4__TREF_INTERVAL__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_INTERVAL__REG)), trefinterval);
1065 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_INTERVAL__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301066 }
1067 return result;
1068}