blob: d5e61ff5ea84cf4a2e939e01b1a26ab07980e0bb [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
4 *
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 */
8
9#ifndef LPDDR4_SANITY_H
10#define LPDDR4_SANITY_H
11
12#include <errno.h>
13#include <linux/types.h>
14#include "lpddr4_if.h"
15
Dave Gerlachd712b362021-05-11 10:22:11 -050016static inline u32 lpddr4_configsf(const lpddr4_config *obj);
17static inline u32 lpddr4_privatedatasf(const lpddr4_privatedata *obj);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053018
Dave Gerlachd712b362021-05-11 10:22:11 -050019static inline u32 lpddr4_sanityfunction1(const lpddr4_config *config, const u16 *configsize);
20static inline u32 lpddr4_sanityfunction2(const lpddr4_privatedata *pd, const lpddr4_config *cfg);
21static inline u32 lpddr4_sanityfunction3(const lpddr4_privatedata *pd);
22static inline u32 lpddr4_sanityfunction4(const lpddr4_privatedata *pd, const lpddr4_regblock cpp, const u32 *regvalue);
23static inline u32 lpddr4_sanityfunction5(const lpddr4_privatedata *pd, const lpddr4_regblock cpp);
24static inline u32 lpddr4_sanityfunction6(const lpddr4_privatedata *pd, const u64 *mmrvalue, const u8 *mmrstatus);
25static inline u32 lpddr4_sanityfunction7(const lpddr4_privatedata *pd, const u8 *mrwstatus);
26static inline u32 lpddr4_sanityfunction14(const lpddr4_privatedata *pd, const u64 *mask);
27static inline u32 lpddr4_sanityfunction15(const lpddr4_privatedata *pd, const u64 *mask);
28static inline u32 lpddr4_sanityfunction16(const lpddr4_privatedata *pd, const u32 *mask);
29static inline u32 lpddr4_sanityfunction18(const lpddr4_privatedata *pd, const lpddr4_debuginfo *debuginfo);
30static inline u32 lpddr4_sanityfunction19(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles);
31static inline u32 lpddr4_sanityfunction21(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam);
32static inline u32 lpddr4_sanityfunction22(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam);
33static inline u32 lpddr4_sanityfunction23(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode);
34static inline u32 lpddr4_sanityfunction24(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode);
35static inline u32 lpddr4_sanityfunction25(const lpddr4_privatedata *pd, const bool *on_off);
36static inline u32 lpddr4_sanityfunction27(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode);
Bryan Brattlof85b5cc82022-10-24 16:53:28 -050037static inline u32 lpddr4_sanityfunction28(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref_val, const u32 *tras_max_val);
Dave Gerlachd712b362021-05-11 10:22:11 -050038static inline u32 lpddr4_sanityfunction29(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053039
40#define lpddr4_probesf lpddr4_sanityfunction1
41#define lpddr4_initsf lpddr4_sanityfunction2
42#define lpddr4_startsf lpddr4_sanityfunction3
43#define lpddr4_readregsf lpddr4_sanityfunction4
44#define lpddr4_writeregsf lpddr4_sanityfunction5
45#define lpddr4_getmmrregistersf lpddr4_sanityfunction6
46#define lpddr4_setmmrregistersf lpddr4_sanityfunction7
Dave Gerlachd712b362021-05-11 10:22:11 -050047#define lpddr4_writectlconfigsf lpddr4_sanityfunction3
48#define lpddr4_writephyconfigsf lpddr4_sanityfunction3
49#define lpddr4_writephyindepconfigsf lpddr4_sanityfunction3
50#define lpddr4_readctlconfigsf lpddr4_sanityfunction3
51#define lpddr4_readphyconfigsf lpddr4_sanityfunction3
52#define lpddr4_readphyindepconfigsf lpddr4_sanityfunction3
Kevin Scholz521a4ef2019-10-07 19:26:36 +053053#define lpddr4_getctlinterruptmasksf lpddr4_sanityfunction14
54#define lpddr4_setctlinterruptmasksf lpddr4_sanityfunction15
Dave Gerlachd712b362021-05-11 10:22:11 -050055#define lpddr4_getphyindepinterruptmsf lpddr4_sanityfunction16
56#define lpddr4_setphyindepinterruptmsf lpddr4_sanityfunction16
57#define lpddr4_getdebuginitinfosf lpddr4_sanityfunction18
58#define lpddr4_getlpiwakeuptimesf lpddr4_sanityfunction19
59#define lpddr4_setlpiwakeuptimesf lpddr4_sanityfunction19
60#define lpddr4_geteccenablesf lpddr4_sanityfunction21
61#define lpddr4_seteccenablesf lpddr4_sanityfunction22
62#define lpddr4_getreducmodesf lpddr4_sanityfunction23
63#define lpddr4_setreducmodesf lpddr4_sanityfunction24
64#define lpddr4_getdbireadmodesf lpddr4_sanityfunction25
65#define lpddr4_getdbiwritemodesf lpddr4_sanityfunction25
66#define lpddr4_setdbimodesf lpddr4_sanityfunction27
67#define lpddr4_getrefreshratesf lpddr4_sanityfunction28
68#define lpddr4_setrefreshratesf lpddr4_sanityfunction29
Kevin Scholz521a4ef2019-10-07 19:26:36 +053069#define lpddr4_refreshperchipselectsf lpddr4_sanityfunction3
Bryan Brattlof85b5cc82022-10-24 16:53:28 -050070#define lpddr4_deferredregverifysf lpddr4_sanityfunction5
Kevin Scholz521a4ef2019-10-07 19:26:36 +053071
Dave Gerlachd712b362021-05-11 10:22:11 -050072static inline u32 lpddr4_configsf(const lpddr4_config *obj)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053073{
Dave Gerlachd712b362021-05-11 10:22:11 -050074 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053075
76 if (obj == NULL)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053077 ret = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053078
79 return ret;
80}
81
Dave Gerlachd712b362021-05-11 10:22:11 -050082static inline u32 lpddr4_privatedatasf(const lpddr4_privatedata *obj)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053083{
Dave Gerlachd712b362021-05-11 10:22:11 -050084 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053085
86 if (obj == NULL)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053087 ret = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053088
89 return ret;
90}
91
Dave Gerlachd712b362021-05-11 10:22:11 -050092static inline u32 lpddr4_sanityfunction1(const lpddr4_config *config, const u16 *configsize)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053093{
Dave Gerlachd712b362021-05-11 10:22:11 -050094 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053095
Dave Gerlachd712b362021-05-11 10:22:11 -050096 if (configsize == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +053097 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -050098 } else if (lpddr4_configsf(config) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +053099 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500100 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530101 }
102
103 return ret;
104}
105
Dave Gerlachd712b362021-05-11 10:22:11 -0500106static inline u32 lpddr4_sanityfunction2(const lpddr4_privatedata *pd, const lpddr4_config *cfg)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530107{
Dave Gerlachd712b362021-05-11 10:22:11 -0500108 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530109
Dave Gerlachd712b362021-05-11 10:22:11 -0500110 if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530111 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500112 } else if (lpddr4_configsf(cfg) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530113 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500114 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530115 }
116
117 return ret;
118}
119
Dave Gerlachd712b362021-05-11 10:22:11 -0500120static inline u32 lpddr4_sanityfunction3(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530121{
Dave Gerlachd712b362021-05-11 10:22:11 -0500122 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530123
124 if (lpddr4_privatedatasf(pd) == EINVAL)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530125 ret = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530126
127 return ret;
128}
129
Dave Gerlachd712b362021-05-11 10:22:11 -0500130static inline u32 lpddr4_sanityfunction4(const lpddr4_privatedata *pd, const lpddr4_regblock cpp, const u32 *regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530131{
Dave Gerlachd712b362021-05-11 10:22:11 -0500132 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530133
Dave Gerlachd712b362021-05-11 10:22:11 -0500134 if (regvalue == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530135 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500136 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530137 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500138 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530139 (cpp != LPDDR4_CTL_REGS) &&
140 (cpp != LPDDR4_PHY_REGS) &&
141 (cpp != LPDDR4_PHY_INDEP_REGS)
Dave Gerlachd712b362021-05-11 10:22:11 -0500142 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530143 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500144 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530145 }
146
147 return ret;
148}
149
Dave Gerlachd712b362021-05-11 10:22:11 -0500150static inline u32 lpddr4_sanityfunction5(const lpddr4_privatedata *pd, const lpddr4_regblock cpp)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530151{
Dave Gerlachd712b362021-05-11 10:22:11 -0500152 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530153
Dave Gerlachd712b362021-05-11 10:22:11 -0500154 if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530155 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500156 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530157 (cpp != LPDDR4_CTL_REGS) &&
158 (cpp != LPDDR4_PHY_REGS) &&
159 (cpp != LPDDR4_PHY_INDEP_REGS)
Dave Gerlachd712b362021-05-11 10:22:11 -0500160 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530161 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500162 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530163 }
164
165 return ret;
166}
167
Dave Gerlachd712b362021-05-11 10:22:11 -0500168static inline u32 lpddr4_sanityfunction6(const lpddr4_privatedata *pd, const u64 *mmrvalue, const u8 *mmrstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530169{
Dave Gerlachd712b362021-05-11 10:22:11 -0500170 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530171
Dave Gerlachd712b362021-05-11 10:22:11 -0500172 if (mmrvalue == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530173 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500174 } else if (mmrstatus == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530175 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500176 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530177 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500178 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530179 }
180
181 return ret;
182}
183
Dave Gerlachd712b362021-05-11 10:22:11 -0500184static inline u32 lpddr4_sanityfunction7(const lpddr4_privatedata *pd, const u8 *mrwstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530185{
Dave Gerlachd712b362021-05-11 10:22:11 -0500186 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530187
Dave Gerlachd712b362021-05-11 10:22:11 -0500188 if (mrwstatus == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530189 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500190 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530191 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500192 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530193 }
194
195 return ret;
196}
197
Dave Gerlachd712b362021-05-11 10:22:11 -0500198static inline u32 lpddr4_sanityfunction14(const lpddr4_privatedata *pd, const u64 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530199{
Dave Gerlachd712b362021-05-11 10:22:11 -0500200 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530201
Dave Gerlachd712b362021-05-11 10:22:11 -0500202 if (mask == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530203 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500204 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530205 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500206 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530207 }
208
209 return ret;
210}
211
Dave Gerlachd712b362021-05-11 10:22:11 -0500212static inline u32 lpddr4_sanityfunction15(const lpddr4_privatedata *pd, const u64 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530213{
Dave Gerlachd712b362021-05-11 10:22:11 -0500214 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530215
Dave Gerlachd712b362021-05-11 10:22:11 -0500216 if (mask == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530217 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500218 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530219 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500220 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530221 }
222
223 return ret;
224}
225
Dave Gerlachd712b362021-05-11 10:22:11 -0500226static inline u32 lpddr4_sanityfunction16(const lpddr4_privatedata *pd, const u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530227{
Dave Gerlachd712b362021-05-11 10:22:11 -0500228 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530229
Dave Gerlachd712b362021-05-11 10:22:11 -0500230 if (mask == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530231 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500232 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530233 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500234 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530235 }
236
237 return ret;
238}
239
Dave Gerlachd712b362021-05-11 10:22:11 -0500240static inline u32 lpddr4_sanityfunction18(const lpddr4_privatedata *pd, const lpddr4_debuginfo *debuginfo)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530241{
Dave Gerlachd712b362021-05-11 10:22:11 -0500242 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530243
Dave Gerlachd712b362021-05-11 10:22:11 -0500244 if (debuginfo == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530245 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500246 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530247 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500248 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530249 }
250
251 return ret;
252}
253
Dave Gerlachd712b362021-05-11 10:22:11 -0500254static inline u32 lpddr4_sanityfunction19(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530255{
Dave Gerlachd712b362021-05-11 10:22:11 -0500256 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530257
Dave Gerlachd712b362021-05-11 10:22:11 -0500258 if (lpiwakeupparam == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530259 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500260 } else if (fspnum == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530261 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500262 } else if (cycles == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530263 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500264 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530265 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500266 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530267 (*lpiwakeupparam != LPDDR4_LPI_PD_WAKEUP_FN) &&
268 (*lpiwakeupparam != LPDDR4_LPI_SR_SHORT_WAKEUP_FN) &&
269 (*lpiwakeupparam != LPDDR4_LPI_SR_LONG_WAKEUP_FN) &&
270 (*lpiwakeupparam != LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN) &&
271 (*lpiwakeupparam != LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN) &&
272 (*lpiwakeupparam != LPDDR4_LPI_SRPD_LONG_WAKEUP_FN) &&
273 (*lpiwakeupparam != LPDDR4_LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_FN)
Dave Gerlachd712b362021-05-11 10:22:11 -0500274 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530275 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500276 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530277 (*fspnum != LPDDR4_FSP_0) &&
278 (*fspnum != LPDDR4_FSP_1) &&
279 (*fspnum != LPDDR4_FSP_2)
Dave Gerlachd712b362021-05-11 10:22:11 -0500280 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530281 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500282 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530283 }
284
285 return ret;
286}
287
Dave Gerlachd712b362021-05-11 10:22:11 -0500288static inline u32 lpddr4_sanityfunction21(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530289{
Dave Gerlachd712b362021-05-11 10:22:11 -0500290 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530291
Dave Gerlachd712b362021-05-11 10:22:11 -0500292 if (eccparam == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530293 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500294 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530295 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500296 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530297 }
298
299 return ret;
300}
301
Dave Gerlachd712b362021-05-11 10:22:11 -0500302static inline u32 lpddr4_sanityfunction22(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530303{
Dave Gerlachd712b362021-05-11 10:22:11 -0500304 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530305
Dave Gerlachd712b362021-05-11 10:22:11 -0500306 if (eccparam == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530307 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500308 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530309 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500310 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530311 (*eccparam != LPDDR4_ECC_DISABLED) &&
312 (*eccparam != LPDDR4_ECC_ENABLED) &&
313 (*eccparam != LPDDR4_ECC_ERR_DETECT) &&
314 (*eccparam != LPDDR4_ECC_ERR_DETECT_CORRECT)
Dave Gerlachd712b362021-05-11 10:22:11 -0500315 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530316 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500317 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530318 }
319
320 return ret;
321}
322
Dave Gerlachd712b362021-05-11 10:22:11 -0500323static inline u32 lpddr4_sanityfunction23(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530324{
Dave Gerlachd712b362021-05-11 10:22:11 -0500325 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530326
Dave Gerlachd712b362021-05-11 10:22:11 -0500327 if (mode == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530328 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500329 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530330 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500331 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530332 }
333
334 return ret;
335}
336
Dave Gerlachd712b362021-05-11 10:22:11 -0500337static inline u32 lpddr4_sanityfunction24(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530338{
Dave Gerlachd712b362021-05-11 10:22:11 -0500339 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530340
Dave Gerlachd712b362021-05-11 10:22:11 -0500341 if (mode == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530342 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500343 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530344 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500345 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530346 (*mode != LPDDR4_REDUC_ON) &&
347 (*mode != LPDDR4_REDUC_OFF)
Dave Gerlachd712b362021-05-11 10:22:11 -0500348 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530349 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500350 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530351 }
352
353 return ret;
354}
355
Dave Gerlachd712b362021-05-11 10:22:11 -0500356static inline u32 lpddr4_sanityfunction25(const lpddr4_privatedata *pd, const bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530357{
Dave Gerlachd712b362021-05-11 10:22:11 -0500358 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530359
Dave Gerlachd712b362021-05-11 10:22:11 -0500360 if (on_off == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530361 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500362 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530363 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500364 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530365 }
366
367 return ret;
368}
369
Dave Gerlachd712b362021-05-11 10:22:11 -0500370static inline u32 lpddr4_sanityfunction27(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530371{
Dave Gerlachd712b362021-05-11 10:22:11 -0500372 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530373
Dave Gerlachd712b362021-05-11 10:22:11 -0500374 if (mode == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530375 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500376 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530377 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500378 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530379 (*mode != LPDDR4_DBI_RD_ON) &&
380 (*mode != LPDDR4_DBI_RD_OFF) &&
381 (*mode != LPDDR4_DBI_WR_ON) &&
382 (*mode != LPDDR4_DBI_WR_OFF)
Dave Gerlachd712b362021-05-11 10:22:11 -0500383 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530384 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500385 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530386 }
387
388 return ret;
389}
390
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500391static inline u32 lpddr4_sanityfunction28(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref_val, const u32 *tras_max_val)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530392{
Dave Gerlachd712b362021-05-11 10:22:11 -0500393 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530394
Dave Gerlachd712b362021-05-11 10:22:11 -0500395 if (fspnum == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530396 ret = EINVAL;
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500397 } else if (tref_val == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530398 ret = EINVAL;
Bryan Brattlof85b5cc82022-10-24 16:53:28 -0500399 } else if (tras_max_val == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530400 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500401 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
402 ret = EINVAL;
403 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530404 (*fspnum != LPDDR4_FSP_0) &&
405 (*fspnum != LPDDR4_FSP_1) &&
406 (*fspnum != LPDDR4_FSP_2)
Dave Gerlachd712b362021-05-11 10:22:11 -0500407 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530408 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500409 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530410 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500411
412 return ret;
413}
414
415static inline u32 lpddr4_sanityfunction29(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max)
416{
417 u32 ret = 0;
418
419 if (fspnum == NULL) {
420 ret = EINVAL;
421 } else if (tref == NULL) {
422 ret = EINVAL;
423 } else if (tras_max == NULL) {
424 ret = EINVAL;
425 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
426 ret = EINVAL;
427 } else if (
428 (*fspnum != LPDDR4_FSP_0) &&
429 (*fspnum != LPDDR4_FSP_1) &&
430 (*fspnum != LPDDR4_FSP_2)
431 ) {
432 ret = EINVAL;
433 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530434 }
435
436 return ret;
437}
438
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530439#endif /* LPDDR4_SANITY_H */