blob: 78ad966a175e9df12cfc4019a0e202673e2a4c77 [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 *
Dave Gerlachd712b362021-05-11 10:22:11 -05005 * Copyright (C) 2012-2021 Cadence Design Systems, Inc.
6 * Copyright (C) 2018-2021 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 -050016#ifndef LPDDR4_CUSTOM_TIMEOUT_DELAY
Kevin Scholz521a4ef2019-10-07 19:26:36 +053017#define LPDDR4_CUSTOM_TIMEOUT_DELAY 100000000U
Dave Gerlachd712b362021-05-11 10:22:11 -050018#endif
Kevin Scholz521a4ef2019-10-07 19:26:36 +053019
Dave Gerlachd712b362021-05-11 10:22:11 -050020#ifndef LPDDR4_CPS_NS_DELAY_TIME
21#define LPDDR4_CPS_NS_DELAY_TIME 10000000U
22#endif
23
24static u32 lpddr4_pollphyindepirq(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt irqbit, u32 delay);
25static u32 lpddr4_pollandackirq(const lpddr4_privatedata *pd);
26static u32 lpddr4_startsequencecontroller(const lpddr4_privatedata *pd);
27static u32 lpddr4_writemmrregister(const lpddr4_privatedata *pd, u32 writemoderegval);
28static void lpddr4_checkcatrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
29static void lpddr4_checkgatelvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
30static void lpddr4_checkreadlvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
31static void lpddr4_checkdqtrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr);
32static u8 lpddr4_seterror(volatile u32 *reg, u32 errbitmask, u8 *errfoundptr, const u32 errorinfobits);
33static void lpddr4_setphysnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound);
34static void lpddr4_setphyadrsnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound);
35static void readpdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
36static void readsrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
37static void readsrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
38static void readsrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
39static void readsrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
40static void readsrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
41static void readsrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles);
42static void lpddr4_readlpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles);
43static void writepdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
44static void writesrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
45static void writesrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
46static void writesrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
47static void writesrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
48static void writesrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
49static void writesrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles);
50static void lpddr4_writelpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles);
51static void lpddr4_updatefsp2refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max);
52static void lpddr4_updatefsp1refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max);
53static void lpddr4_updatefsp0refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max);
54#ifdef REG_WRITE_VERIF
55static u32 lpddr4_getphyrwmask(u32 regoffset);
56static u32 lpddr4_verifyregwrite(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue);
57#endif
Kevin Scholz521a4ef2019-10-07 19:26:36 +053058
Dave Gerlachd712b362021-05-11 10:22:11 -050059u32 lpddr4_pollctlirq(const lpddr4_privatedata *pd, lpddr4_intr_ctlinterrupt irqbit, u32 delay)
60{
61 u32 result = 0U;
62 u32 timeout = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053063 bool irqstatus = false;
64
Kevin Scholz521a4ef2019-10-07 19:26:36 +053065 do {
66 if (++timeout == delay) {
Dave Gerlachd712b362021-05-11 10:22:11 -050067 result = (u32)EIO;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053068 break;
69 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +053070 result = lpddr4_checkctlinterrupt(pd, irqbit, &irqstatus);
Dave Gerlachd712b362021-05-11 10:22:11 -050071 } while ((irqstatus == (bool)false) && (result == (u32)0));
Kevin Scholz521a4ef2019-10-07 19:26:36 +053072
73 return result;
74}
75
Dave Gerlachd712b362021-05-11 10:22:11 -050076static u32 lpddr4_pollphyindepirq(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt irqbit, u32 delay)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053077{
Dave Gerlachd712b362021-05-11 10:22:11 -050078 u32 result = 0U;
79 u32 timeout = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053080 bool irqstatus = false;
81
Kevin Scholz521a4ef2019-10-07 19:26:36 +053082 do {
83 if (++timeout == delay) {
Dave Gerlachd712b362021-05-11 10:22:11 -050084 result = (u32)EIO;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053085 break;
86 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +053087 result = lpddr4_checkphyindepinterrupt(pd, irqbit, &irqstatus);
Dave Gerlachd712b362021-05-11 10:22:11 -050088 } while ((irqstatus == (bool)false) && (result == (u32)0));
Kevin Scholz521a4ef2019-10-07 19:26:36 +053089
90 return result;
91}
92
Dave Gerlachd712b362021-05-11 10:22:11 -050093static u32 lpddr4_pollandackirq(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053094{
Dave Gerlachd712b362021-05-11 10:22:11 -050095 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053096
Dave Gerlachd712b362021-05-11 10:22:11 -050097 result = lpddr4_pollphyindepirq(pd, LPDDR4_INTR_PHY_INDEP_INIT_DONE_BIT, LPDDR4_CUSTOM_TIMEOUT_DELAY);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053098
Dave Gerlachd712b362021-05-11 10:22:11 -050099 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 Scholz521a4ef2019-10-07 19:26:36 +0530105 return result;
106}
107
Dave Gerlachd712b362021-05-11 10:22:11 -0500108static u32 lpddr4_startsequencecontroller(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530109{
Dave Gerlachd712b362021-05-11 10:22:11 -0500110 u32 result = 0U;
111 u32 regval = 0U;
112 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530113 lpddr4_infotype infotype;
114
Dave Gerlachd712b362021-05-11 10:22:11 -0500115 regval = CPS_FLD_SET(LPDDR4__PI_START__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__PI_START__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530116 CPS_REG_WRITE((&(ctlregbase->LPDDR4__PI_START__REG)), regval);
117
Dave Gerlachd712b362021-05-11 10:22:11 -0500118 regval = CPS_FLD_SET(LPDDR4__START__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__START__REG)));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530119 CPS_REG_WRITE(&(ctlregbase->LPDDR4__START__REG), regval);
120
Dave Gerlachd712b362021-05-11 10:22:11 -0500121 if (pd->infohandler != (lpddr4_infocallback)NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530122 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 Gerlachd712b362021-05-11 10:22:11 -0500131volatile u32 *lpddr4_addoffset(volatile u32 *addr, u32 regoffset)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530132{
Dave Gerlachd712b362021-05-11 10:22:11 -0500133 volatile u32 *local_addr = addr;
134 volatile u32 *regaddr = &local_addr[regoffset];
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530135
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530136 return regaddr;
137}
138
Dave Gerlachd712b362021-05-11 10:22:11 -0500139u32 lpddr4_probe(const lpddr4_config *config, u16 *configsize)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530140{
Dave Gerlachd712b362021-05-11 10:22:11 -0500141 u32 result;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530142
Dave Gerlachd712b362021-05-11 10:22:11 -0500143 result = (u32)(lpddr4_probesf(config, configsize));
144 if (result == (u32)0)
145 *configsize = (u16)(sizeof(lpddr4_privatedata));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530146 return result;
147}
148
Dave Gerlachd712b362021-05-11 10:22:11 -0500149u32 lpddr4_init(lpddr4_privatedata *pd, const lpddr4_config *cfg)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530150{
Dave Gerlachd712b362021-05-11 10:22:11 -0500151 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530152
153 result = lpddr4_initsf(pd, cfg);
Dave Gerlachd712b362021-05-11 10:22:11 -0500154 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 Scholz521a4ef2019-10-07 19:26:36 +0530160 }
161 return result;
162}
163
Dave Gerlachd712b362021-05-11 10:22:11 -0500164u32 lpddr4_start(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530165{
Dave Gerlachd712b362021-05-11 10:22:11 -0500166 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530167
168 result = lpddr4_startsf(pd);
Dave Gerlachd712b362021-05-11 10:22:11 -0500169 if (result == (u32)0) {
170 result = lpddr4_enablepiinitiator(pd);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530171 result = lpddr4_startsequencecontroller(pd);
172 }
173 return result;
174}
175
Dave Gerlachd712b362021-05-11 10:22:11 -0500176u32 lpddr4_readreg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 *regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530177{
Dave Gerlachd712b362021-05-11 10:22:11 -0500178 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530179
180 result = lpddr4_readregsf(pd, cpp, regvalue);
Dave Gerlachd712b362021-05-11 10:22:11 -0500181 if (result == (u32)0) {
182 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530183
184 if (cpp == LPDDR4_CTL_REGS) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500185 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 Scholz521a4ef2019-10-07 19:26:36 +0530189 } else if (cpp == LPDDR4_PHY_REGS) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500190 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 Scholz521a4ef2019-10-07 19:26:36 +0530194
195 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500196 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 Scholz521a4ef2019-10-07 19:26:36 +0530200 }
201 }
202 return result;
203}
204
Dave Gerlachd712b362021-05-11 10:22:11 -0500205#ifdef REG_WRITE_VERIF
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530206
Dave Gerlachd712b362021-05-11 10:22:11 -0500207static u32 lpddr4_getphyrwmask(u32 regoffset)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530208{
Dave Gerlachd712b362021-05-11 10:22:11 -0500209 u32 rwmask = 0U;
210 u32 arrayoffset = 0U;
211 u32 slicenum, sliceoffset = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530212
Dave Gerlachd712b362021-05-11 10:22:11 -0500213 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 Scholz521a4ef2019-10-07 19:26:36 +0530219
Dave Gerlachd712b362021-05-11 10:22:11 -0500220 if (slicenum < DSLICE_NUM) {
221 rwmask = lpddr4_getdslicemask(slicenum, arrayoffset);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530222 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500223 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 Scholz521a4ef2019-10-07 19:26:36 +0530230 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500231 return rwmask;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530232}
233
Dave Gerlachd712b362021-05-11 10:22:11 -0500234static u32 lpddr4_verifyregwrite(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530235{
Dave Gerlachd712b362021-05-11 10:22:11 -0500236 u32 result = (u32)0;
237 u32 regreadval = 0U;
238 u32 rwmask = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530239
Dave Gerlachd712b362021-05-11 10:22:11 -0500240 result = lpddr4_readreg(pd, cpp, regoffset, &regreadval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530241
Dave Gerlachd712b362021-05-11 10:22:11 -0500242 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 Scholz521a4ef2019-10-07 19:26:36 +0530254
Dave Gerlachd712b362021-05-11 10:22:11 -0500255 if ((rwmask & regreadval) != (regvalue & rwmask))
256 result = EIO;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530257 }
258 return result;
259}
Dave Gerlachd712b362021-05-11 10:22:11 -0500260#endif
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530261
Dave Gerlachd712b362021-05-11 10:22:11 -0500262u32 lpddr4_writereg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530263{
Dave Gerlachd712b362021-05-11 10:22:11 -0500264 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530265
Dave Gerlachd712b362021-05-11 10:22:11 -0500266 result = lpddr4_writeregsf(pd, cpp);
267 if (result == (u32)0) {
268 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530269
Dave Gerlachd712b362021-05-11 10:22:11 -0500270 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 Scholz521a4ef2019-10-07 19:26:36 +0530290
Dave Gerlachd712b362021-05-11 10:22:11 -0500291#endif
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530292
293 return result;
294}
295
Dave Gerlachd712b362021-05-11 10:22:11 -0500296u32 lpddr4_getmmrregister(const lpddr4_privatedata *pd, u32 readmoderegval, u64 *mmrvalue, u8 *mmrstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530297{
Dave Gerlachd712b362021-05-11 10:22:11 -0500298 u32 result = 0U;
299 u32 tdelay = 1000U;
300 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530301
Dave Gerlachd712b362021-05-11 10:22:11 -0500302 result = lpddr4_getmmrregistersf(pd, mmrvalue, mmrstatus);
303 if (result == (u32)0) {
304 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530305
Dave Gerlachd712b362021-05-11 10:22:11 -0500306 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 Scholz521a4ef2019-10-07 19:26:36 +0530308
Dave Gerlachd712b362021-05-11 10:22:11 -0500309 result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_READ_DONE, tdelay);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530310 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500311 if (result == (u32)0)
312 result = lpddr4_checkmmrreaderror(pd, mmrvalue, mmrstatus);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530313 return result;
314}
315
Dave Gerlachd712b362021-05-11 10:22:11 -0500316static u32 lpddr4_writemmrregister(const lpddr4_privatedata *pd, u32 writemoderegval)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530317{
Dave Gerlachd712b362021-05-11 10:22:11 -0500318 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 Scholz521a4ef2019-10-07 19:26:36 +0530325
Dave Gerlachd712b362021-05-11 10:22:11 -0500326 result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_WRITE_DONE, tdelay);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530327
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530328 return result;
329}
330
Dave Gerlachd712b362021-05-11 10:22:11 -0500331u32 lpddr4_setmmrregister(const lpddr4_privatedata *pd, u32 writemoderegval, u8 *mrwstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530332{
Dave Gerlachd712b362021-05-11 10:22:11 -0500333 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530334
Dave Gerlachd712b362021-05-11 10:22:11 -0500335 result = lpddr4_setmmrregistersf(pd, mrwstatus);
336 if (result == (u32)0) {
337 result = lpddr4_writemmrregister(pd, writemoderegval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530338
Dave Gerlachd712b362021-05-11 10:22:11 -0500339 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 Scholz521a4ef2019-10-07 19:26:36 +0530346 }
347 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530348
Dave Gerlachd712b362021-05-11 10:22:11 -0500349#ifdef ASILC
350#endif
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530351
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530352 return result;
353}
354
Dave Gerlachd712b362021-05-11 10:22:11 -0500355u32 lpddr4_writectlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530356{
Dave Gerlachd712b362021-05-11 10:22:11 -0500357 u32 result;
358 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530359
Dave Gerlachd712b362021-05-11 10:22:11 -0500360 result = lpddr4_writectlconfigsf(pd);
361 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
362 result = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530363
Dave Gerlachd712b362021-05-11 10:22:11 -0500364 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 Scholz521a4ef2019-10-07 19:26:36 +0530368 }
369 return result;
370}
371
Dave Gerlachd712b362021-05-11 10:22:11 -0500372u32 lpddr4_writephyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530373{
Dave Gerlachd712b362021-05-11 10:22:11 -0500374 u32 result;
375 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530376
Dave Gerlachd712b362021-05-11 10:22:11 -0500377 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 Scholz521a4ef2019-10-07 19:26:36 +0530384 }
385 return result;
386}
387
Dave Gerlachd712b362021-05-11 10:22:11 -0500388u32 lpddr4_writephyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530389{
Dave Gerlachd712b362021-05-11 10:22:11 -0500390 u32 result;
391 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530392
Dave Gerlachd712b362021-05-11 10:22:11 -0500393 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 Scholz521a4ef2019-10-07 19:26:36 +0530400 }
401 return result;
402}
403
Dave Gerlachd712b362021-05-11 10:22:11 -0500404u32 lpddr4_readctlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530405{
Dave Gerlachd712b362021-05-11 10:22:11 -0500406 u32 result;
407 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530408
Dave Gerlachd712b362021-05-11 10:22:11 -0500409 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 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530416 }
417 return result;
418}
419
Dave Gerlachd712b362021-05-11 10:22:11 -0500420u32 lpddr4_readphyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530421{
Dave Gerlachd712b362021-05-11 10:22:11 -0500422 u32 result;
423 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530424
Dave Gerlachd712b362021-05-11 10:22:11 -0500425 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 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530432 }
433 return result;
434}
435
Dave Gerlachd712b362021-05-11 10:22:11 -0500436u32 lpddr4_readphyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530437{
Dave Gerlachd712b362021-05-11 10:22:11 -0500438 u32 result;
439 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530440
Dave Gerlachd712b362021-05-11 10:22:11 -0500441 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 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530448 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530449 return result;
450}
451
Dave Gerlachd712b362021-05-11 10:22:11 -0500452u32 lpddr4_getphyindepinterruptmask(const lpddr4_privatedata *pd, u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530453{
Dave Gerlachd712b362021-05-11 10:22:11 -0500454 u32 result;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530455
456 result = lpddr4_getphyindepinterruptmsf(pd, mask);
Dave Gerlachd712b362021-05-11 10:22:11 -0500457 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 Scholz521a4ef2019-10-07 19:26:36 +0530460 }
461 return result;
462}
463
Dave Gerlachd712b362021-05-11 10:22:11 -0500464u32 lpddr4_setphyindepinterruptmask(const lpddr4_privatedata *pd, const u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530465{
Dave Gerlachd712b362021-05-11 10:22:11 -0500466 u32 result;
467 u32 regval = 0;
468 const u32 ui32irqcount = (u32)LPDDR4_INTR_PHY_INDEP_DLL_LOCK_STATE_CHANGE_BIT + 1U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530469
470 result = lpddr4_setphyindepinterruptmsf(pd, mask);
Dave Gerlachd712b362021-05-11 10:22:11 -0500471 if ((result == (u32)0) && (ui32irqcount < WORD_SHIFT)) {
472 if (*mask >= (1U << ui32irqcount))
473 result = (u32)EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530474 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500475 if (result == (u32)0) {
476 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530477
Dave Gerlachd712b362021-05-11 10:22:11 -0500478 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 +0530479 CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_MASK__REG), regval);
480 }
481 return result;
482}
483
Dave Gerlachd712b362021-05-11 10:22:11 -0500484u32 lpddr4_checkphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr, bool *irqstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530485{
Dave Gerlachd712b362021-05-11 10:22:11 -0500486 u32 result = 0;
487 u32 phyindepirqstatus = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530488
Dave Gerlachd712b362021-05-11 10:22:11 -0500489 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 Scholz521a4ef2019-10-07 19:26:36 +0530492
Dave Gerlachd712b362021-05-11 10:22:11 -0500493 phyindepirqstatus = CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_STATUS__REG));
494 *irqstatus = (bool)(((phyindepirqstatus >> (u32)intr) & LPDDR4_BIT_MASK) > 0U);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530495 }
496 return result;
497}
498
Dave Gerlachd712b362021-05-11 10:22:11 -0500499u32 lpddr4_ackphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530500{
Dave Gerlachd712b362021-05-11 10:22:11 -0500501 u32 result = 0U;
502 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530503
Dave Gerlachd712b362021-05-11 10:22:11 -0500504 result = LPDDR4_INTR_AckPhyIndepIntSF(pd, intr);
505 if ((result == (u32)0) && ((u32)intr < WORD_SHIFT)) {
506 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530507
Dave Gerlachd712b362021-05-11 10:22:11 -0500508 regval = ((u32)LPDDR4_BIT_MASK << (u32)intr);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530509 CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_ACK__REG), regval);
510 }
511
512 return result;
513}
514
Dave Gerlachd712b362021-05-11 10:22:11 -0500515static void lpddr4_checkcatrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530516{
Dave Gerlachd712b362021-05-11 10:22:11 -0500517 u32 regval;
518 u32 errbitmask = 0U;
519 u32 snum;
520 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530521
Dave Gerlachd712b362021-05-11 10:22:11 -0500522 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_ADR_CALVL_OBS1_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530523 errbitmask = (CA_TRAIN_RL) | (NIBBLE_MASK);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530524 for (snum = 0U; snum < ASLICE_NUM; snum++) {
525 regval = CPS_REG_READ(regaddress);
526 if ((regval & errbitmask) != CA_TRAIN_RL) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500527 debuginfo->catraingerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530528 *errfoundptr = true;
529 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500530 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530531 }
532}
533
Dave Gerlachd712b362021-05-11 10:22:11 -0500534static void lpddr4_checkgatelvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530535{
Dave Gerlachd712b362021-05-11 10:22:11 -0500536 u32 regval;
537 u32 errbitmask = 0U;
538 u32 snum;
539 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530540
Dave Gerlachd712b362021-05-11 10:22:11 -0500541 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_GTLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530542 errbitmask = GATE_LVL_ERROR_FIELDS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500543 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530544 regval = CPS_REG_READ(regaddress);
545 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500546 debuginfo->gatelvlerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530547 *errfoundptr = true;
548 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500549 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530550 }
551}
552
Dave Gerlachd712b362021-05-11 10:22:11 -0500553static void lpddr4_checkreadlvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530554{
Dave Gerlachd712b362021-05-11 10:22:11 -0500555 u32 regval;
556 u32 errbitmask = 0U;
557 u32 snum;
558 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530559
Dave Gerlachd712b362021-05-11 10:22:11 -0500560 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_RDLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530561 errbitmask = READ_LVL_ERROR_FIELDS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500562 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530563 regval = CPS_REG_READ(regaddress);
564 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500565 debuginfo->readlvlerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530566 *errfoundptr = true;
567 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500568 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530569 }
570}
571
Dave Gerlachd712b362021-05-11 10:22:11 -0500572static void lpddr4_checkdqtrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530573{
Dave Gerlachd712b362021-05-11 10:22:11 -0500574 u32 regval;
575 u32 errbitmask = 0U;
576 u32 snum;
577 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530578
Dave Gerlachd712b362021-05-11 10:22:11 -0500579 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_WDQLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530580 errbitmask = DQ_LVL_STATUS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500581 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530582 regval = CPS_REG_READ(regaddress);
583 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500584 debuginfo->dqtrainingerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530585 *errfoundptr = true;
586 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500587 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530588 }
589}
590
Dave Gerlachd712b362021-05-11 10:22:11 -0500591bool lpddr4_checklvlerrors(const lpddr4_privatedata *pd, lpddr4_debuginfo *debuginfo, bool errfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530592{
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530593 bool localerrfound = errfound;
594
Dave Gerlachd712b362021-05-11 10:22:11 -0500595 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530596
Dave Gerlachd712b362021-05-11 10:22:11 -0500597 if (localerrfound == (bool)false)
598 lpddr4_checkcatrainingerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530599
Dave Gerlachd712b362021-05-11 10:22:11 -0500600 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530601 lpddr4_checkwrlvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530602
Dave Gerlachd712b362021-05-11 10:22:11 -0500603 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530604 lpddr4_checkgatelvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530605
Dave Gerlachd712b362021-05-11 10:22:11 -0500606 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530607 lpddr4_checkreadlvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530608
Dave Gerlachd712b362021-05-11 10:22:11 -0500609 if (localerrfound == (bool)false)
610 lpddr4_checkdqtrainingerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530611 return localerrfound;
612}
613
Dave Gerlachd712b362021-05-11 10:22:11 -0500614static u8 lpddr4_seterror(volatile u32 *reg, u32 errbitmask, u8 *errfoundptr, const u32 errorinfobits)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530615{
Dave Gerlachd712b362021-05-11 10:22:11 -0500616 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530617
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530618 regval = CPS_REG_READ(reg);
Dave Gerlachd712b362021-05-11 10:22:11 -0500619 if ((regval & errbitmask) != errorinfobits)
620 *errfoundptr = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530621 return *errfoundptr;
622}
623
Dave Gerlachd712b362021-05-11 10:22:11 -0500624void lpddr4_seterrors(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, u8 *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530625{
Dave Gerlachd712b362021-05-11 10:22:11 -0500626 u32 errbitmask = (LPDDR4_BIT_MASK << 0x1U) | (LPDDR4_BIT_MASK);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530627
Dave Gerlachd712b362021-05-11 10:22:11 -0500628 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 Scholz521a4ef2019-10-07 19:26:36 +0530633
Dave Gerlachd712b362021-05-11 10:22:11 -0500634 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 Scholz521a4ef2019-10-07 19:26:36 +0530643}
644
Dave Gerlachd712b362021-05-11 10:22:11 -0500645static void lpddr4_setphysnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530646{
Dave Gerlachd712b362021-05-11 10:22:11 -0500647 u32 snum = 0U;
648 volatile u32 *regaddress;
649 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530650
Dave Gerlachd712b362021-05-11 10:22:11 -0500651 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 Scholz521a4ef2019-10-07 19:26:36 +0530655 CPS_REG_WRITE(regaddress, regval);
Dave Gerlachd712b362021-05-11 10:22:11 -0500656 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530657 }
658 }
659}
660
Dave Gerlachd712b362021-05-11 10:22:11 -0500661static void lpddr4_setphyadrsnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530662{
Dave Gerlachd712b362021-05-11 10:22:11 -0500663 u32 snum = 0U;
664 volatile u32 *regaddress;
665 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530666
Dave Gerlachd712b362021-05-11 10:22:11 -0500667 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 Scholz521a4ef2019-10-07 19:26:36 +0530671 CPS_REG_WRITE(regaddress, regval);
Dave Gerlachd712b362021-05-11 10:22:11 -0500672 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530673 }
674 }
675}
676
Dave Gerlachd712b362021-05-11 10:22:11 -0500677void lpddr4_setsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530678{
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530679 lpddr4_setphysnapsettings(ctlregbase, errorfound);
680 lpddr4_setphyadrsnapsettings(ctlregbase, errorfound);
681}
682
Dave Gerlachd712b362021-05-11 10:22:11 -0500683static void readpdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530684{
Dave Gerlachd712b362021-05-11 10:22:11 -0500685 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 Scholz521a4ef2019-10-07 19:26:36 +0530691}
692
Dave Gerlachd712b362021-05-11 10:22:11 -0500693static void readsrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530694{
Dave Gerlachd712b362021-05-11 10:22:11 -0500695 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 Scholz521a4ef2019-10-07 19:26:36 +0530701}
702
Dave Gerlachd712b362021-05-11 10:22:11 -0500703static void readsrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530704{
Dave Gerlachd712b362021-05-11 10:22:11 -0500705 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 Scholz521a4ef2019-10-07 19:26:36 +0530711}
712
Dave Gerlachd712b362021-05-11 10:22:11 -0500713static void readsrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530714{
Dave Gerlachd712b362021-05-11 10:22:11 -0500715 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 Scholz521a4ef2019-10-07 19:26:36 +0530721}
722
Dave Gerlachd712b362021-05-11 10:22:11 -0500723static void readsrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530724{
Dave Gerlachd712b362021-05-11 10:22:11 -0500725 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 Scholz521a4ef2019-10-07 19:26:36 +0530731}
732
Dave Gerlachd712b362021-05-11 10:22:11 -0500733static void readsrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530734{
Dave Gerlachd712b362021-05-11 10:22:11 -0500735 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 Scholz521a4ef2019-10-07 19:26:36 +0530741}
742
Dave Gerlachd712b362021-05-11 10:22:11 -0500743static void readsrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530744{
Dave Gerlachd712b362021-05-11 10:22:11 -0500745 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 Scholz521a4ef2019-10-07 19:26:36 +0530751
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530752}
753
Dave Gerlachd712b362021-05-11 10:22:11 -0500754static void lpddr4_readlpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530755{
Dave Gerlachd712b362021-05-11 10:22:11 -0500756 if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530757 readpdwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500758 else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530759 readsrshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500760 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530761 readsrlongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500762 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530763 readsrlonggatewakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500764 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530765 readsrdpshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500766 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530767 readsrdplongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500768 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530769 readsrdplonggatewakeup(fspnum, ctlregbase, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530770}
771
Dave Gerlachd712b362021-05-11 10:22:11 -0500772u32 lpddr4_getlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530773{
Dave Gerlachd712b362021-05-11 10:22:11 -0500774 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530775
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530776 result = lpddr4_getlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500777 if (result == (u32)0) {
778 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
779 lpddr4_readlpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530780 }
781 return result;
782}
783
Dave Gerlachd712b362021-05-11 10:22:11 -0500784static void writepdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530785{
Dave Gerlachd712b362021-05-11 10:22:11 -0500786 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530787
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530788 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500789 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 Scholz521a4ef2019-10-07 19:26:36 +0530791 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500792 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 Scholz521a4ef2019-10-07 19:26:36 +0530794 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500795 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 Scholz521a4ef2019-10-07 19:26:36 +0530797 }
798}
799
Dave Gerlachd712b362021-05-11 10:22:11 -0500800static void writesrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530801{
Dave Gerlachd712b362021-05-11 10:22:11 -0500802 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530803
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530804 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500805 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 Scholz521a4ef2019-10-07 19:26:36 +0530807 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500808 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 Scholz521a4ef2019-10-07 19:26:36 +0530810 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500811 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 Scholz521a4ef2019-10-07 19:26:36 +0530813 }
814}
815
Dave Gerlachd712b362021-05-11 10:22:11 -0500816static void writesrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530817{
Dave Gerlachd712b362021-05-11 10:22:11 -0500818 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530819
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530820 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500821 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 Scholz521a4ef2019-10-07 19:26:36 +0530823 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500824 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 Scholz521a4ef2019-10-07 19:26:36 +0530826 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500827 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 Scholz521a4ef2019-10-07 19:26:36 +0530829 }
830}
831
Dave Gerlachd712b362021-05-11 10:22:11 -0500832static void writesrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530833{
Dave Gerlachd712b362021-05-11 10:22:11 -0500834 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530835
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530836 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500837 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 Scholz521a4ef2019-10-07 19:26:36 +0530839 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500840 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 Scholz521a4ef2019-10-07 19:26:36 +0530842 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500843 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 Scholz521a4ef2019-10-07 19:26:36 +0530845 }
846}
847
Dave Gerlachd712b362021-05-11 10:22:11 -0500848static void writesrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530849{
Dave Gerlachd712b362021-05-11 10:22:11 -0500850 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530851
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530852 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500853 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 Scholz521a4ef2019-10-07 19:26:36 +0530855 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500856 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 Scholz521a4ef2019-10-07 19:26:36 +0530858 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500859 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 Scholz521a4ef2019-10-07 19:26:36 +0530861 }
862}
863
Dave Gerlachd712b362021-05-11 10:22:11 -0500864static void writesrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530865{
Dave Gerlachd712b362021-05-11 10:22:11 -0500866 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530867
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530868 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500869 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 Scholz521a4ef2019-10-07 19:26:36 +0530871 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500872 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 Scholz521a4ef2019-10-07 19:26:36 +0530874 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500875 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 Scholz521a4ef2019-10-07 19:26:36 +0530877 }
878}
Dave Gerlachd712b362021-05-11 10:22:11 -0500879static void writesrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530880{
Dave Gerlachd712b362021-05-11 10:22:11 -0500881 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530882
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530883 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500884 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 Scholz521a4ef2019-10-07 19:26:36 +0530886 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500887 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 Scholz521a4ef2019-10-07 19:26:36 +0530889 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500890 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 Scholz521a4ef2019-10-07 19:26:36 +0530892 }
893}
894
Dave Gerlachd712b362021-05-11 10:22:11 -0500895static void lpddr4_writelpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530896{
Dave Gerlachd712b362021-05-11 10:22:11 -0500897 if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530898 writepdwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500899 else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530900 writesrshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500901 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530902 writesrlongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500903 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530904 writesrlonggatewakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500905 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530906 writesrdpshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500907 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530908 writesrdplongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500909 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530910 writesrdplonggatewakeup(fspnum, ctlregbase, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530911}
912
Dave Gerlachd712b362021-05-11 10:22:11 -0500913u32 lpddr4_setlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530914{
Dave Gerlachd712b362021-05-11 10:22:11 -0500915 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530916
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530917 result = lpddr4_setlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500918 if (result == (u32)0) {
919 if (*cycles > NIBBLE_MASK)
920 result = (u32)EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530921 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500922 if (result == (u32)0) {
923 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
924 lpddr4_writelpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530925 }
926 return result;
927}
928
Dave Gerlachd712b362021-05-11 10:22:11 -0500929u32 lpddr4_getdbireadmode(const lpddr4_privatedata *pd, bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530930{
Dave Gerlachd712b362021-05-11 10:22:11 -0500931 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530932
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530933 result = lpddr4_getdbireadmodesf(pd, on_off);
934
Dave Gerlachd712b362021-05-11 10:22:11 -0500935 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 Scholz521a4ef2019-10-07 19:26:36 +0530938 *on_off = false;
Dave Gerlachd712b362021-05-11 10:22:11 -0500939 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530940 *on_off = true;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530941 }
942 return result;
943}
944
Dave Gerlachd712b362021-05-11 10:22:11 -0500945u32 lpddr4_getdbiwritemode(const lpddr4_privatedata *pd, bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530946{
Dave Gerlachd712b362021-05-11 10:22:11 -0500947 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530948
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530949 result = lpddr4_getdbireadmodesf(pd, on_off);
950
Dave Gerlachd712b362021-05-11 10:22:11 -0500951 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 Scholz521a4ef2019-10-07 19:26:36 +0530954 *on_off = false;
Dave Gerlachd712b362021-05-11 10:22:11 -0500955 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530956 *on_off = true;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530957 }
958 return result;
959}
960
Dave Gerlachd712b362021-05-11 10:22:11 -0500961u32 lpddr4_setdbimode(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530962{
Dave Gerlachd712b362021-05-11 10:22:11 -0500963 u32 result = 0U;
964 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530965
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530966 result = lpddr4_setdbimodesf(pd, mode);
967
Dave Gerlachd712b362021-05-11 10:22:11 -0500968 if (result == (u32)0) {
969 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530970
Dave Gerlachd712b362021-05-11 10:22:11 -0500971 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 Scholz521a4ef2019-10-07 19:26:36 +0530979 CPS_REG_WRITE(&(ctlregbase->LPDDR4__RD_DBI_EN__REG), regval);
980 }
981 return result;
982}
983
Dave Gerlachd712b362021-05-11 10:22:11 -0500984u32 lpddr4_getrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, u32 *tref, u32 *tras_max)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530985{
Dave Gerlachd712b362021-05-11 10:22:11 -0500986 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530987
Dave Gerlachd712b362021-05-11 10:22:11 -0500988 result = lpddr4_getrefreshratesf(pd, fspnum, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530989
Dave Gerlachd712b362021-05-11 10:22:11 -0500990 if (result == (u32)0) {
991 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530992
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530993 switch (*fspnum) {
994 case LPDDR4_FSP_2:
Dave Gerlachd712b362021-05-11 10:22:11 -0500995 *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 Scholz521a4ef2019-10-07 19:26:36 +0530997 break;
998 case LPDDR4_FSP_1:
Dave Gerlachd712b362021-05-11 10:22:11 -0500999 *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 Scholz521a4ef2019-10-07 19:26:36 +05301001 break;
1002 default:
Dave Gerlachd712b362021-05-11 10:22:11 -05001003 *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 Scholz521a4ef2019-10-07 19:26:36 +05301005 break;
1006 }
1007 }
1008 return result;
1009}
1010
Dave Gerlachd712b362021-05-11 10:22:11 -05001011static void lpddr4_updatefsp2refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max)
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301012{
Dave Gerlachd712b362021-05-11 10:22:11 -05001013 u32 regval = 0U;
1014 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301015
Dave Gerlachd712b362021-05-11 10:22:11 -05001016 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
1022static 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
1033static 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
1044u32 lpddr4_setrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max)
1045{
1046 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301047
Dave Gerlachd712b362021-05-11 10:22:11 -05001048 result = lpddr4_setrefreshratesf(pd, fspnum, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301049
Dave Gerlachd712b362021-05-11 10:22:11 -05001050 if (result == (u32)0) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301051 switch (*fspnum) {
1052 case LPDDR4_FSP_2:
Dave Gerlachd712b362021-05-11 10:22:11 -05001053 lpddr4_updatefsp2refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301054 break;
1055 case LPDDR4_FSP_1:
Dave Gerlachd712b362021-05-11 10:22:11 -05001056 lpddr4_updatefsp1refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301057 break;
1058 default:
Dave Gerlachd712b362021-05-11 10:22:11 -05001059 lpddr4_updatefsp0refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301060 break;
1061 }
1062 }
1063 return result;
1064}
1065
Dave Gerlachd712b362021-05-11 10:22:11 -05001066u32 lpddr4_refreshperchipselect(const lpddr4_privatedata *pd, const u32 trefinterval)
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301067{
Dave Gerlachd712b362021-05-11 10:22:11 -05001068 u32 result = 0U;
1069 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301070
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301071 result = lpddr4_refreshperchipselectsf(pd);
1072
Dave Gerlachd712b362021-05-11 10:22:11 -05001073 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 Scholz521a4ef2019-10-07 19:26:36 +05301077 }
1078 return result;
1079}