blob: 9f9abfeca489d18ba232bd38b81594a4bb621511 [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);
Udit Kumar888f0572024-08-29 14:04:53 +0530158 if (result == (u32)0)
Dave Gerlachd712b362021-05-11 10:22:11 -0500159 result = lpddr4_enablepiinitiator(pd);
Udit Kumar888f0572024-08-29 14:04:53 +0530160 if (result == (u32)0)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530161 result = lpddr4_startsequencecontroller(pd);
Udit Kumar888f0572024-08-29 14:04:53 +0530162
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530163 return result;
164}
165
Dave Gerlachd712b362021-05-11 10:22:11 -0500166u32 lpddr4_readreg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 *regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530167{
Dave Gerlachd712b362021-05-11 10:22:11 -0500168 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530169
170 result = lpddr4_readregsf(pd, cpp, regvalue);
Dave Gerlachd712b362021-05-11 10:22:11 -0500171 if (result == (u32)0) {
172 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530173
174 if (cpp == LPDDR4_CTL_REGS) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500175 if (regoffset >= LPDDR4_INTR_CTL_REG_COUNT)
176 result = (u32)EINVAL;
177 else
178 *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_CTL_0), regoffset));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530179 } else if (cpp == LPDDR4_PHY_REGS) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500180 if (regoffset >= LPDDR4_INTR_PHY_REG_COUNT)
181 result = (u32)EINVAL;
182 else
183 *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_PHY_0), regoffset));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530184
185 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500186 if (regoffset >= LPDDR4_INTR_PHY_INDEP_REG_COUNT)
187 result = (u32)EINVAL;
188 else
189 *regvalue = CPS_REG_READ(lpddr4_addoffset(&(ctlregbase->DENALI_PI_0), regoffset));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530190 }
191 }
192 return result;
193}
194
Dave Gerlachd712b362021-05-11 10:22:11 -0500195static u32 lpddr4_getphyrwmask(u32 regoffset)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530196{
Dave Gerlachd712b362021-05-11 10:22:11 -0500197 u32 rwmask = 0U;
198 u32 arrayoffset = 0U;
199 u32 slicenum, sliceoffset = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530200
Dave Gerlachd712b362021-05-11 10:22:11 -0500201 for (slicenum = (u32)0U; slicenum <= (DSLICE_NUM + ASLICE_NUM); slicenum++) {
202 sliceoffset = sliceoffset + (u32)SLICE_WIDTH;
203 if (regoffset < sliceoffset)
204 break;
205 }
206 arrayoffset = regoffset - (sliceoffset - (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530207
Dave Gerlachd712b362021-05-11 10:22:11 -0500208 if (slicenum < DSLICE_NUM) {
209 rwmask = lpddr4_getdslicemask(slicenum, arrayoffset);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530210 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500211 if (slicenum == DSLICE_NUM) {
212 if (arrayoffset < ASLICE0_REG_COUNT)
213 rwmask = g_lpddr4_address_slice_0_rw_mask[arrayoffset];
214 } else {
215 if (arrayoffset < PHY_CORE_REG_COUNT)
216 rwmask = g_lpddr4_phy_core_rw_mask[arrayoffset];
217 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530218 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500219 return rwmask;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530220}
221
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500222u32 lpddr4_deferredregverify(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530223{
Dave Gerlachd712b362021-05-11 10:22:11 -0500224 u32 result = (u32)0;
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500225 u32 aindex;
Dave Gerlachd712b362021-05-11 10:22:11 -0500226 u32 regreadval = 0U;
227 u32 rwmask = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530228
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500229 result = lpddr4_deferredregverifysf(pd, cpp);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530230
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500231 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
232 result = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500233 if (result == (u32)0) {
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500234 for (aindex = 0; aindex < regcount; aindex++) {
235 result = lpddr4_readreg(pd, cpp, (u32)regnum[aindex], &regreadval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530236
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500237 if (result == (u32)0) {
238 switch (cpp) {
239 case LPDDR4_PHY_INDEP_REGS:
240 rwmask = g_lpddr4_pi_rw_mask[(u32)regnum[aindex]];
241 break;
242 case LPDDR4_PHY_REGS:
243 rwmask = lpddr4_getphyrwmask((u32)regnum[aindex]);
244 break;
245 default:
246 rwmask = g_lpddr4_ddr_controller_rw_mask[(u32)regnum[aindex]];
247 break;
248 }
249
250 if ((rwmask & regreadval) != ((u32)(regvalues[aindex]) & rwmask)) {
251 result = EIO;
252 break;
253 }
254 }
255 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530256 }
257 return result;
258}
259
Dave Gerlachd712b362021-05-11 10:22:11 -0500260u32 lpddr4_writereg(const lpddr4_privatedata *pd, lpddr4_regblock cpp, u32 regoffset, u32 regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530261{
Dave Gerlachd712b362021-05-11 10:22:11 -0500262 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530263
Dave Gerlachd712b362021-05-11 10:22:11 -0500264 result = lpddr4_writeregsf(pd, cpp);
265 if (result == (u32)0) {
266 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530267
Dave Gerlachd712b362021-05-11 10:22:11 -0500268 if (cpp == LPDDR4_CTL_REGS) {
269 if (regoffset >= LPDDR4_INTR_CTL_REG_COUNT)
270 result = (u32)EINVAL;
271 else
272 CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_CTL_0), regoffset), regvalue);
273 } else if (cpp == LPDDR4_PHY_REGS) {
274 if (regoffset >= LPDDR4_INTR_PHY_REG_COUNT)
275 result = (u32)EINVAL;
276 else
277 CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_PHY_0), regoffset), regvalue);
278 } else {
279 if (regoffset >= LPDDR4_INTR_PHY_INDEP_REG_COUNT)
280 result = (u32)EINVAL;
281 else
282 CPS_REG_WRITE(lpddr4_addoffset(&(ctlregbase->DENALI_PI_0), regoffset), regvalue);
283 }
284 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530285
286 return result;
287}
288
Dave Gerlachd712b362021-05-11 10:22:11 -0500289u32 lpddr4_getmmrregister(const lpddr4_privatedata *pd, u32 readmoderegval, u64 *mmrvalue, u8 *mmrstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530290{
Dave Gerlachd712b362021-05-11 10:22:11 -0500291 u32 result = 0U;
292 u32 tdelay = 1000U;
293 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530294
Dave Gerlachd712b362021-05-11 10:22:11 -0500295 result = lpddr4_getmmrregistersf(pd, mmrvalue, mmrstatus);
296 if (result == (u32)0) {
297 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530298
Dave Gerlachd712b362021-05-11 10:22:11 -0500299 regval = CPS_FLD_WRITE(LPDDR4__READ_MODEREG__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__READ_MODEREG__REG)), readmoderegval);
300 CPS_REG_WRITE(&(ctlregbase->LPDDR4__READ_MODEREG__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530301
Dave Gerlachd712b362021-05-11 10:22:11 -0500302 result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_READ_DONE, tdelay);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530303 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500304 if (result == (u32)0)
305 result = lpddr4_checkmmrreaderror(pd, mmrvalue, mmrstatus);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530306 return result;
307}
308
Dave Gerlachd712b362021-05-11 10:22:11 -0500309static u32 lpddr4_writemmrregister(const lpddr4_privatedata *pd, u32 writemoderegval)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530310{
Dave Gerlachd712b362021-05-11 10:22:11 -0500311 u32 result = (u32)0;
312 u32 tdelay = 1000U;
313 u32 regval = 0U;
314 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
315
316 regval = CPS_FLD_WRITE(LPDDR4__WRITE_MODEREG__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WRITE_MODEREG__REG)), writemoderegval);
317 CPS_REG_WRITE(&(ctlregbase->LPDDR4__WRITE_MODEREG__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530318
Dave Gerlachd712b362021-05-11 10:22:11 -0500319 result = lpddr4_pollctlirq(pd, LPDDR4_INTR_MR_WRITE_DONE, tdelay);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530320
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530321 return result;
322}
323
Dave Gerlachd712b362021-05-11 10:22:11 -0500324u32 lpddr4_setmmrregister(const lpddr4_privatedata *pd, u32 writemoderegval, u8 *mrwstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530325{
Dave Gerlachd712b362021-05-11 10:22:11 -0500326 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530327
Dave Gerlachd712b362021-05-11 10:22:11 -0500328 result = lpddr4_setmmrregistersf(pd, mrwstatus);
329 if (result == (u32)0) {
330 result = lpddr4_writemmrregister(pd, writemoderegval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530331
Dave Gerlachd712b362021-05-11 10:22:11 -0500332 if (result == (u32)0)
333 result = lpddr4_ackctlinterrupt(pd, LPDDR4_INTR_MR_WRITE_DONE);
334 if (result == (u32)0) {
335 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
336 *mrwstatus = (u8)CPS_FLD_READ(LPDDR4__MRW_STATUS__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__MRW_STATUS__REG)));
337 if ((*mrwstatus) != 0U)
338 result = (u32)EIO;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530339 }
340 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530341
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530342 return result;
343}
344
Dave Gerlachd712b362021-05-11 10:22:11 -0500345u32 lpddr4_writectlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530346{
Dave Gerlachd712b362021-05-11 10:22:11 -0500347 u32 result;
348 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530349
Dave Gerlachd712b362021-05-11 10:22:11 -0500350 result = lpddr4_writectlconfigsf(pd);
351 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
352 result = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530353
Dave Gerlachd712b362021-05-11 10:22:11 -0500354 if (result == (u32)0) {
355 for (aindex = 0; aindex < regcount; aindex++)
356 result = (u32)lpddr4_writereg(pd, LPDDR4_CTL_REGS, (u32)regnum[aindex],
357 (u32)regvalues[aindex]);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530358 }
359 return result;
360}
361
Dave Gerlachd712b362021-05-11 10:22:11 -0500362u32 lpddr4_writephyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530363{
Dave Gerlachd712b362021-05-11 10:22:11 -0500364 u32 result;
365 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530366
Dave Gerlachd712b362021-05-11 10:22:11 -0500367 result = lpddr4_writephyindepconfigsf(pd);
368 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
369 result = EINVAL;
370 if (result == (u32)0) {
371 for (aindex = 0; aindex < regcount; aindex++)
372 result = (u32)lpddr4_writereg(pd, LPDDR4_PHY_INDEP_REGS, (u32)regnum[aindex],
373 (u32)regvalues[aindex]);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530374 }
375 return result;
376}
377
Dave Gerlachd712b362021-05-11 10:22:11 -0500378u32 lpddr4_writephyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530379{
Dave Gerlachd712b362021-05-11 10:22:11 -0500380 u32 result;
381 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530382
Dave Gerlachd712b362021-05-11 10:22:11 -0500383 result = lpddr4_writephyconfigsf(pd);
384 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
385 result = EINVAL;
386 if (result == (u32)0) {
387 for (aindex = 0; aindex < regcount; aindex++)
388 result = (u32)lpddr4_writereg(pd, LPDDR4_PHY_REGS, (u32)regnum[aindex],
389 (u32)regvalues[aindex]);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530390 }
391 return result;
392}
393
Dave Gerlachd712b362021-05-11 10:22:11 -0500394u32 lpddr4_readctlconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530395{
Dave Gerlachd712b362021-05-11 10:22:11 -0500396 u32 result;
397 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530398
Dave Gerlachd712b362021-05-11 10:22:11 -0500399 result = lpddr4_readctlconfigsf(pd);
400 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
401 result = EINVAL;
402 if (result == (u32)0) {
403 for (aindex = 0; aindex < regcount; aindex++)
404 result = (u32)lpddr4_readreg(pd, LPDDR4_CTL_REGS, (u32)regnum[aindex],
405 (u32 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530406 }
407 return result;
408}
409
Dave Gerlachd712b362021-05-11 10:22:11 -0500410u32 lpddr4_readphyindepconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530411{
Dave Gerlachd712b362021-05-11 10:22:11 -0500412 u32 result;
413 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530414
Dave Gerlachd712b362021-05-11 10:22:11 -0500415 result = lpddr4_readphyindepconfigsf(pd);
416 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
417 result = EINVAL;
418 if (result == (u32)0) {
419 for (aindex = 0; aindex < regcount; aindex++)
420 result = (u32)lpddr4_readreg(pd, LPDDR4_PHY_INDEP_REGS, (u32)regnum[aindex],
421 (u32 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530422 }
423 return result;
424}
425
Dave Gerlachd712b362021-05-11 10:22:11 -0500426u32 lpddr4_readphyconfig(const lpddr4_privatedata *pd, u32 regvalues[], u16 regnum[], u16 regcount)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530427{
Dave Gerlachd712b362021-05-11 10:22:11 -0500428 u32 result;
429 u32 aindex;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530430
Dave Gerlachd712b362021-05-11 10:22:11 -0500431 result = lpddr4_readphyconfigsf(pd);
432 if ((regvalues == (u32 *)NULL) || (regnum == (u16 *)NULL))
433 result = EINVAL;
434 if (result == (u32)0) {
435 for (aindex = 0; aindex < regcount; aindex++)
436 result = (u32)lpddr4_readreg(pd, LPDDR4_PHY_REGS, (u32)regnum[aindex],
437 (u32 *)(&regvalues[aindex]));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530438 }
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530439 return result;
440}
441
Dave Gerlachd712b362021-05-11 10:22:11 -0500442u32 lpddr4_getphyindepinterruptmask(const lpddr4_privatedata *pd, u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530443{
Dave Gerlachd712b362021-05-11 10:22:11 -0500444 u32 result;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530445
446 result = lpddr4_getphyindepinterruptmsf(pd, mask);
Dave Gerlachd712b362021-05-11 10:22:11 -0500447 if (result == (u32)0) {
448 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
449 *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 +0530450 }
451 return result;
452}
453
Dave Gerlachd712b362021-05-11 10:22:11 -0500454u32 lpddr4_setphyindepinterruptmask(const lpddr4_privatedata *pd, const u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530455{
Dave Gerlachd712b362021-05-11 10:22:11 -0500456 u32 result;
457 u32 regval = 0;
458 const u32 ui32irqcount = (u32)LPDDR4_INTR_PHY_INDEP_DLL_LOCK_STATE_CHANGE_BIT + 1U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530459
460 result = lpddr4_setphyindepinterruptmsf(pd, mask);
Dave Gerlachd712b362021-05-11 10:22:11 -0500461 if ((result == (u32)0) && (ui32irqcount < WORD_SHIFT)) {
462 if (*mask >= (1U << ui32irqcount))
463 result = (u32)EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530464 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500465 if (result == (u32)0) {
466 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530467
Dave Gerlachd712b362021-05-11 10:22:11 -0500468 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 +0530469 CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_MASK__REG), regval);
470 }
471 return result;
472}
473
Dave Gerlachd712b362021-05-11 10:22:11 -0500474u32 lpddr4_checkphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr, bool *irqstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530475{
Dave Gerlachd712b362021-05-11 10:22:11 -0500476 u32 result = 0;
477 u32 phyindepirqstatus = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530478
Dave Gerlachd712b362021-05-11 10:22:11 -0500479 result = LPDDR4_INTR_CheckPhyIndepIntSF(pd, intr, irqstatus);
480 if ((result == (u32)0) && ((u32)intr < WORD_SHIFT)) {
481 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530482
Dave Gerlachd712b362021-05-11 10:22:11 -0500483 phyindepirqstatus = CPS_REG_READ(&(ctlregbase->LPDDR4__PI_INT_STATUS__REG));
484 *irqstatus = (bool)(((phyindepirqstatus >> (u32)intr) & LPDDR4_BIT_MASK) > 0U);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530485 }
486 return result;
487}
488
Dave Gerlachd712b362021-05-11 10:22:11 -0500489u32 lpddr4_ackphyindepinterrupt(const lpddr4_privatedata *pd, lpddr4_intr_phyindepinterrupt intr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530490{
Dave Gerlachd712b362021-05-11 10:22:11 -0500491 u32 result = 0U;
492 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530493
Dave Gerlachd712b362021-05-11 10:22:11 -0500494 result = LPDDR4_INTR_AckPhyIndepIntSF(pd, intr);
495 if ((result == (u32)0) && ((u32)intr < WORD_SHIFT)) {
496 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530497
Dave Gerlachd712b362021-05-11 10:22:11 -0500498 regval = ((u32)LPDDR4_BIT_MASK << (u32)intr);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530499 CPS_REG_WRITE(&(ctlregbase->LPDDR4__PI_INT_ACK__REG), regval);
500 }
501
502 return result;
503}
504
Dave Gerlachd712b362021-05-11 10:22:11 -0500505static void lpddr4_checkcatrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530506{
Dave Gerlachd712b362021-05-11 10:22:11 -0500507 u32 regval;
508 u32 errbitmask = 0U;
509 u32 snum;
510 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530511
Dave Gerlachd712b362021-05-11 10:22:11 -0500512 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_ADR_CALVL_OBS1_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530513 errbitmask = (CA_TRAIN_RL) | (NIBBLE_MASK);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530514 for (snum = 0U; snum < ASLICE_NUM; snum++) {
515 regval = CPS_REG_READ(regaddress);
516 if ((regval & errbitmask) != CA_TRAIN_RL) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500517 debuginfo->catraingerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530518 *errfoundptr = true;
519 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500520 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530521 }
522}
523
Dave Gerlachd712b362021-05-11 10:22:11 -0500524static void lpddr4_checkgatelvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530525{
Dave Gerlachd712b362021-05-11 10:22:11 -0500526 u32 regval;
527 u32 errbitmask = 0U;
528 u32 snum;
529 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530530
Dave Gerlachd712b362021-05-11 10:22:11 -0500531 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_GTLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530532 errbitmask = GATE_LVL_ERROR_FIELDS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500533 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530534 regval = CPS_REG_READ(regaddress);
535 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500536 debuginfo->gatelvlerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530537 *errfoundptr = true;
538 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500539 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530540 }
541}
542
Dave Gerlachd712b362021-05-11 10:22:11 -0500543static void lpddr4_checkreadlvlerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530544{
Dave Gerlachd712b362021-05-11 10:22:11 -0500545 u32 regval;
546 u32 errbitmask = 0U;
547 u32 snum;
548 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530549
Dave Gerlachd712b362021-05-11 10:22:11 -0500550 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_RDLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530551 errbitmask = READ_LVL_ERROR_FIELDS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500552 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530553 regval = CPS_REG_READ(regaddress);
554 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500555 debuginfo->readlvlerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530556 *errfoundptr = true;
557 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500558 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530559 }
560}
561
Dave Gerlachd712b362021-05-11 10:22:11 -0500562static void lpddr4_checkdqtrainingerror(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, bool *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530563{
Dave Gerlachd712b362021-05-11 10:22:11 -0500564 u32 regval;
565 u32 errbitmask = 0U;
566 u32 snum;
567 volatile u32 *regaddress;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530568
Dave Gerlachd712b362021-05-11 10:22:11 -0500569 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__PHY_WDQLVL_STATUS_OBS_0__REG));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530570 errbitmask = DQ_LVL_STATUS;
Dave Gerlachd712b362021-05-11 10:22:11 -0500571 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530572 regval = CPS_REG_READ(regaddress);
573 if ((regval & errbitmask) != 0U) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500574 debuginfo->dqtrainingerror = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530575 *errfoundptr = true;
576 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500577 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530578 }
579}
580
Dave Gerlachd712b362021-05-11 10:22:11 -0500581bool lpddr4_checklvlerrors(const lpddr4_privatedata *pd, lpddr4_debuginfo *debuginfo, bool errfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530582{
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530583 bool localerrfound = errfound;
584
Dave Gerlachd712b362021-05-11 10:22:11 -0500585 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530586
Dave Gerlachd712b362021-05-11 10:22:11 -0500587 if (localerrfound == (bool)false)
588 lpddr4_checkcatrainingerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530589
Dave Gerlachd712b362021-05-11 10:22:11 -0500590 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530591 lpddr4_checkwrlvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530592
Dave Gerlachd712b362021-05-11 10:22:11 -0500593 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530594 lpddr4_checkgatelvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530595
Dave Gerlachd712b362021-05-11 10:22:11 -0500596 if (localerrfound == (bool)false)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530597 lpddr4_checkreadlvlerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530598
Dave Gerlachd712b362021-05-11 10:22:11 -0500599 if (localerrfound == (bool)false)
600 lpddr4_checkdqtrainingerror(ctlregbase, debuginfo, &localerrfound);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530601 return localerrfound;
602}
603
Dave Gerlachd712b362021-05-11 10:22:11 -0500604static u8 lpddr4_seterror(volatile u32 *reg, u32 errbitmask, u8 *errfoundptr, const u32 errorinfobits)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530605{
Dave Gerlachd712b362021-05-11 10:22:11 -0500606 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530607
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530608 regval = CPS_REG_READ(reg);
Dave Gerlachd712b362021-05-11 10:22:11 -0500609 if ((regval & errbitmask) != errorinfobits)
610 *errfoundptr = CDN_TRUE;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530611 return *errfoundptr;
612}
613
Dave Gerlachd712b362021-05-11 10:22:11 -0500614void lpddr4_seterrors(lpddr4_ctlregs *ctlregbase, lpddr4_debuginfo *debuginfo, u8 *errfoundptr)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530615{
Dave Gerlachd712b362021-05-11 10:22:11 -0500616 u32 errbitmask = (LPDDR4_BIT_MASK << 0x1U) | (LPDDR4_BIT_MASK);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530617
Dave Gerlachd712b362021-05-11 10:22:11 -0500618 debuginfo->pllerror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_PLL_OBS_0__REG),
619 errbitmask, errfoundptr, PLL_READY);
620 if (*errfoundptr == CDN_FALSE)
621 debuginfo->pllerror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_PLL_OBS_1__REG),
622 errbitmask, errfoundptr, PLL_READY);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530623
Dave Gerlachd712b362021-05-11 10:22:11 -0500624 if (*errfoundptr == CDN_FALSE)
625 debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT_OBS_0__REG),
626 IO_CALIB_DONE, errfoundptr, IO_CALIB_DONE);
627 if (*errfoundptr == CDN_FALSE)
628 debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT2_OBS_0__REG),
629 IO_CALIB_DONE, errfoundptr, IO_CALIB_DONE);
630 if (*errfoundptr == CDN_FALSE)
631 debuginfo->iocaliberror = lpddr4_seterror(&(ctlregbase->LPDDR4__PHY_CAL_RESULT3_OBS_0__REG),
632 IO_CALIB_FIELD, errfoundptr, IO_CALIB_STATE);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530633}
634
Dave Gerlachd712b362021-05-11 10:22:11 -0500635static void lpddr4_setphysnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530636{
Dave Gerlachd712b362021-05-11 10:22:11 -0500637 u32 snum = 0U;
638 volatile u32 *regaddress;
639 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530640
Dave Gerlachd712b362021-05-11 10:22:11 -0500641 if (errorfound == (bool)false) {
642 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__SC_PHY_SNAP_OBS_REGS_0__REG));
643 for (snum = (u32)0U; snum < DSLICE_NUM; snum++) {
644 regval = CPS_FLD_SET(LPDDR4__SC_PHY_SNAP_OBS_REGS_0__FLD, CPS_REG_READ(regaddress));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530645 CPS_REG_WRITE(regaddress, regval);
Dave Gerlachd712b362021-05-11 10:22:11 -0500646 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530647 }
648 }
649}
650
Dave Gerlachd712b362021-05-11 10:22:11 -0500651static void lpddr4_setphyadrsnapsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530652{
Dave Gerlachd712b362021-05-11 10:22:11 -0500653 u32 snum = 0U;
654 volatile u32 *regaddress;
655 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530656
Dave Gerlachd712b362021-05-11 10:22:11 -0500657 if (errorfound == (bool)false) {
658 regaddress = (volatile u32 *)(&(ctlregbase->LPDDR4__SC_PHY_ADR_SNAP_OBS_REGS_0__REG));
659 for (snum = (u32)0U; snum < ASLICE_NUM; snum++) {
660 regval = CPS_FLD_SET(LPDDR4__SC_PHY_ADR_SNAP_OBS_REGS_0__FLD, CPS_REG_READ(regaddress));
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530661 CPS_REG_WRITE(regaddress, regval);
Dave Gerlachd712b362021-05-11 10:22:11 -0500662 regaddress = lpddr4_addoffset(regaddress, (u32)SLICE_WIDTH);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530663 }
664 }
665}
666
Dave Gerlachd712b362021-05-11 10:22:11 -0500667void lpddr4_setsettings(lpddr4_ctlregs *ctlregbase, const bool errorfound)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530668{
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530669 lpddr4_setphysnapsettings(ctlregbase, errorfound);
670 lpddr4_setphyadrsnapsettings(ctlregbase, errorfound);
671}
672
Dave Gerlachd712b362021-05-11 10:22:11 -0500673static void readpdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530674{
Dave Gerlachd712b362021-05-11 10:22:11 -0500675 if (*fspnum == LPDDR4_FSP_0)
676 *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG)));
677 else if (*fspnum == LPDDR4_FSP_1)
678 *cycles = CPS_FLD_READ(LPDDR4__LPI_PD_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG)));
679 else
680 *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 +0530681}
682
Dave Gerlachd712b362021-05-11 10:22:11 -0500683static void readsrshortwakeup(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_SR_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG)));
687 else if (*fspnum == LPDDR4_FSP_1)
688 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG)));
689 else
690 *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 +0530691}
692
Dave Gerlachd712b362021-05-11 10:22:11 -0500693static void readsrlongwakeup(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_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG)));
697 else if (*fspnum == LPDDR4_FSP_1)
698 *cycles = CPS_FLD_READ(LPDDR4__LPI_SR_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG)));
699 else
700 *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 +0530701}
702
Dave Gerlachd712b362021-05-11 10:22:11 -0500703static void readsrlonggatewakeup(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_MCCLK_GATE_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__REG)));
707 else if (*fspnum == LPDDR4_FSP_1)
708 *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)));
709 else
710 *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 +0530711}
712
Dave Gerlachd712b362021-05-11 10:22:11 -0500713static void readsrdpshortwakeup(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_SRPD_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG)));
717 else if (*fspnum == LPDDR4_FSP_1)
718 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG)));
719 else
720 *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 +0530721}
722
Dave Gerlachd712b362021-05-11 10:22:11 -0500723static void readsrdplongwakeup(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_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG)));
727 else if (*fspnum == LPDDR4_FSP_1)
728 *cycles = CPS_FLD_READ(LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG)));
729 else
730 *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 +0530731}
732
Dave Gerlachd712b362021-05-11 10:22:11 -0500733static void readsrdplonggatewakeup(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_MCCLK_GATE_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__REG)));
737 else if (*fspnum == LPDDR4_FSP_1)
738 *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)));
739 else
740 *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 +0530741
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530742}
743
Dave Gerlachd712b362021-05-11 10:22:11 -0500744static void lpddr4_readlpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530745{
Dave Gerlachd712b362021-05-11 10:22:11 -0500746 if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530747 readpdwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500748 else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530749 readsrshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500750 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530751 readsrlongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500752 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530753 readsrlonggatewakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500754 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530755 readsrdpshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500756 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530757 readsrdplongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500758 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530759 readsrdplonggatewakeup(fspnum, ctlregbase, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530760}
761
Dave Gerlachd712b362021-05-11 10:22:11 -0500762u32 lpddr4_getlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530763{
Dave Gerlachd712b362021-05-11 10:22:11 -0500764 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530765
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530766 result = lpddr4_getlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500767 if (result == (u32)0) {
768 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
769 lpddr4_readlpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530770 }
771 return result;
772}
773
Dave Gerlachd712b362021-05-11 10:22:11 -0500774static void writepdwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530775{
Dave Gerlachd712b362021-05-11 10:22:11 -0500776 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530777
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530778 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500779 regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG)), *cycles);
780 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530781 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500782 regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG)), *cycles);
783 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530784 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500785 regval = CPS_FLD_WRITE(LPDDR4__LPI_PD_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG)), *cycles);
786 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_PD_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530787 }
788}
789
Dave Gerlachd712b362021-05-11 10:22:11 -0500790static void writesrshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530791{
Dave Gerlachd712b362021-05-11 10:22:11 -0500792 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530793
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530794 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500795 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG)), *cycles);
796 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530797 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500798 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG)), *cycles);
799 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530800 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500801 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG)), *cycles);
802 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_SHORT_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530803 }
804}
805
Dave Gerlachd712b362021-05-11 10:22:11 -0500806static void writesrlongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530807{
Dave Gerlachd712b362021-05-11 10:22:11 -0500808 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530809
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530810 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500811 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG)), *cycles);
812 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530813 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500814 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG)), *cycles);
815 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530816 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500817 regval = CPS_FLD_WRITE(LPDDR4__LPI_SR_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG)), *cycles);
818 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530819 }
820}
821
Dave Gerlachd712b362021-05-11 10:22:11 -0500822static void writesrlonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530823{
Dave Gerlachd712b362021-05-11 10:22:11 -0500824 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530825
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530826 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500827 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);
828 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530829 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500830 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);
831 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530832 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500833 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);
834 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SR_LONG_MCCLK_GATE_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530835 }
836}
837
Dave Gerlachd712b362021-05-11 10:22:11 -0500838static void writesrdpshortwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530839{
Dave Gerlachd712b362021-05-11 10:22:11 -0500840 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530841
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530842 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500843 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG)), *cycles);
844 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530845 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500846 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG)), *cycles);
847 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530848 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500849 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG)), *cycles);
850 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_SHORT_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530851 }
852}
853
Dave Gerlachd712b362021-05-11 10:22:11 -0500854static void writesrdplongwakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530855{
Dave Gerlachd712b362021-05-11 10:22:11 -0500856 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530857
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530858 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500859 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG)), *cycles);
860 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530861 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500862 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG)), *cycles);
863 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530864 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500865 regval = CPS_FLD_WRITE(LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG)), *cycles);
866 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530867 }
868}
Dave Gerlachd712b362021-05-11 10:22:11 -0500869static void writesrdplonggatewakeup(const lpddr4_ctlfspnum *fspnum, lpddr4_ctlregs *ctlregbase, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530870{
Dave Gerlachd712b362021-05-11 10:22:11 -0500871 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530872
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530873 if (*fspnum == LPDDR4_FSP_0) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500874 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);
875 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F0__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530876 } else if (*fspnum == LPDDR4_FSP_1) {
Dave Gerlachd712b362021-05-11 10:22:11 -0500877 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);
878 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F1__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530879 } else {
Dave Gerlachd712b362021-05-11 10:22:11 -0500880 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);
881 CPS_REG_WRITE(&(ctlregbase->LPDDR4__LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_F2__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530882 }
883}
884
Dave Gerlachd712b362021-05-11 10:22:11 -0500885static void lpddr4_writelpiwakeuptime(lpddr4_ctlregs *ctlregbase, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530886{
Dave Gerlachd712b362021-05-11 10:22:11 -0500887 if (*lpiwakeupparam == LPDDR4_LPI_PD_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530888 writepdwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500889 else if (*lpiwakeupparam == LPDDR4_LPI_SR_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530890 writesrshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500891 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530892 writesrlongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500893 else if (*lpiwakeupparam == LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530894 writesrlonggatewakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500895 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530896 writesrdpshortwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500897 else if (*lpiwakeupparam == LPDDR4_LPI_SRPD_LONG_WAKEUP_FN)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530898 writesrdplongwakeup(fspnum, ctlregbase, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500899 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530900 writesrdplonggatewakeup(fspnum, ctlregbase, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530901}
902
Dave Gerlachd712b362021-05-11 10:22:11 -0500903u32 lpddr4_setlpiwakeuptime(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530904{
Dave Gerlachd712b362021-05-11 10:22:11 -0500905 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530906
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530907 result = lpddr4_setlpiwakeuptimesf(pd, lpiwakeupparam, fspnum, cycles);
Dave Gerlachd712b362021-05-11 10:22:11 -0500908 if (result == (u32)0) {
909 if (*cycles > NIBBLE_MASK)
910 result = (u32)EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530911 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500912 if (result == (u32)0) {
913 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
914 lpddr4_writelpiwakeuptime(ctlregbase, lpiwakeupparam, fspnum, cycles);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530915 }
916 return result;
917}
918
Dave Gerlachd712b362021-05-11 10:22:11 -0500919u32 lpddr4_getdbireadmode(const lpddr4_privatedata *pd, bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530920{
Dave Gerlachd712b362021-05-11 10:22:11 -0500921 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530922
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530923 result = lpddr4_getdbireadmodesf(pd, on_off);
924
Dave Gerlachd712b362021-05-11 10:22:11 -0500925 if (result == (u32)0) {
926 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
927 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 +0530928 *on_off = false;
Dave Gerlachd712b362021-05-11 10:22:11 -0500929 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530930 *on_off = true;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530931 }
932 return result;
933}
934
Dave Gerlachd712b362021-05-11 10:22:11 -0500935u32 lpddr4_getdbiwritemode(const lpddr4_privatedata *pd, bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530936{
Dave Gerlachd712b362021-05-11 10:22:11 -0500937 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530938
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530939 result = lpddr4_getdbireadmodesf(pd, on_off);
940
Dave Gerlachd712b362021-05-11 10:22:11 -0500941 if (result == (u32)0) {
942 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
943 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 +0530944 *on_off = false;
Dave Gerlachd712b362021-05-11 10:22:11 -0500945 else
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530946 *on_off = true;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530947 }
948 return result;
949}
950
Dave Gerlachd712b362021-05-11 10:22:11 -0500951u32 lpddr4_setdbimode(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530952{
Dave Gerlachd712b362021-05-11 10:22:11 -0500953 u32 result = 0U;
954 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530955
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530956 result = lpddr4_setdbimodesf(pd, mode);
957
Dave Gerlachd712b362021-05-11 10:22:11 -0500958 if (result == (u32)0) {
959 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530960
Dave Gerlachd712b362021-05-11 10:22:11 -0500961 if (*mode == LPDDR4_DBI_RD_ON)
962 regval = CPS_FLD_WRITE(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG)), 1U);
963 else if (*mode == LPDDR4_DBI_RD_OFF)
964 regval = CPS_FLD_WRITE(LPDDR4__RD_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__RD_DBI_EN__REG)), 0U);
965 else if (*mode == LPDDR4_DBI_WR_ON)
966 regval = CPS_FLD_WRITE(LPDDR4__WR_DBI_EN__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__WR_DBI_EN__REG)), 1U);
967 else
968 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 +0530969 CPS_REG_WRITE(&(ctlregbase->LPDDR4__RD_DBI_EN__REG), regval);
970 }
971 return result;
972}
973
Dave Gerlachd712b362021-05-11 10:22:11 -0500974u32 lpddr4_getrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, u32 *tref, u32 *tras_max)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530975{
Dave Gerlachd712b362021-05-11 10:22:11 -0500976 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530977
Dave Gerlachd712b362021-05-11 10:22:11 -0500978 result = lpddr4_getrefreshratesf(pd, fspnum, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530979
Dave Gerlachd712b362021-05-11 10:22:11 -0500980 if (result == (u32)0) {
981 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530982
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530983 switch (*fspnum) {
984 case LPDDR4_FSP_2:
Dave Gerlachd712b362021-05-11 10:22:11 -0500985 *tref = CPS_FLD_READ(LPDDR4__TREF_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F2__REG)));
986 *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 +0530987 break;
988 case LPDDR4_FSP_1:
Dave Gerlachd712b362021-05-11 10:22:11 -0500989 *tref = CPS_FLD_READ(LPDDR4__TREF_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F1__REG)));
990 *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 +0530991 break;
992 default:
Dave Gerlachd712b362021-05-11 10:22:11 -0500993 *tref = CPS_FLD_READ(LPDDR4__TREF_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F0__REG)));
994 *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 +0530995 break;
996 }
997 }
998 return result;
999}
1000
Dave Gerlachd712b362021-05-11 10:22:11 -05001001static void lpddr4_updatefsp2refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max)
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301002{
Dave Gerlachd712b362021-05-11 10:22:11 -05001003 u32 regval = 0U;
1004 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301005
Dave Gerlachd712b362021-05-11 10:22:11 -05001006 regval = CPS_FLD_WRITE(LPDDR4__TREF_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F2__REG)), *tref);
1007 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F2__REG), regval);
1008 regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F2__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG)), *tras_max);
1009 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F2__REG), regval);
1010}
1011
1012static void lpddr4_updatefsp1refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max)
1013{
1014 u32 regval = 0U;
1015 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
1016
1017 regval = CPS_FLD_WRITE(LPDDR4__TREF_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F1__REG)), *tref);
1018 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F1__REG), regval);
1019 regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F1__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG)), *tras_max);
1020 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F1__REG), regval);;
1021}
1022
1023static void lpddr4_updatefsp0refrateparams(const lpddr4_privatedata *pd, const u32 *tref, const u32 *tras_max)
1024{
1025 u32 regval = 0U;
1026 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
1027
1028 regval = CPS_FLD_WRITE(LPDDR4__TREF_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_F0__REG)), *tref);
1029 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_F0__REG), regval);
1030 regval = CPS_FLD_WRITE(LPDDR4__TRAS_MAX_F0__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG)), *tras_max);
1031 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TRAS_MAX_F0__REG), regval);
1032}
1033
1034u32 lpddr4_setrefreshrate(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max)
1035{
1036 u32 result = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301037
Dave Gerlachd712b362021-05-11 10:22:11 -05001038 result = lpddr4_setrefreshratesf(pd, fspnum, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301039
Dave Gerlachd712b362021-05-11 10:22:11 -05001040 if (result == (u32)0) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301041 switch (*fspnum) {
1042 case LPDDR4_FSP_2:
Dave Gerlachd712b362021-05-11 10:22:11 -05001043 lpddr4_updatefsp2refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301044 break;
1045 case LPDDR4_FSP_1:
Dave Gerlachd712b362021-05-11 10:22:11 -05001046 lpddr4_updatefsp1refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301047 break;
1048 default:
Dave Gerlachd712b362021-05-11 10:22:11 -05001049 lpddr4_updatefsp0refrateparams(pd, tref, tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301050 break;
1051 }
1052 }
1053 return result;
1054}
1055
Dave Gerlachd712b362021-05-11 10:22:11 -05001056u32 lpddr4_refreshperchipselect(const lpddr4_privatedata *pd, const u32 trefinterval)
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301057{
Dave Gerlachd712b362021-05-11 10:22:11 -05001058 u32 result = 0U;
1059 u32 regval = 0U;
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301060
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301061 result = lpddr4_refreshperchipselectsf(pd);
1062
Dave Gerlachd712b362021-05-11 10:22:11 -05001063 if (result == (u32)0) {
1064 lpddr4_ctlregs *ctlregbase = (lpddr4_ctlregs *)pd->ctlbase;
1065 regval = CPS_FLD_WRITE(LPDDR4__TREF_INTERVAL__FLD, CPS_REG_READ(&(ctlregbase->LPDDR4__TREF_INTERVAL__REG)), trefinterval);
1066 CPS_REG_WRITE(&(ctlregbase->LPDDR4__TREF_INTERVAL__REG), regval);
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301067 }
1068 return result;
1069}