blob: 750e00d3f5cedcebf74bff7c1c24fcdda49bdcea [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 *
5 * 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 */
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"
Dave Gerlachd712b362021-05-11 10:22:11 -050015#ifdef __cplusplus
16extern "C" {
17#endif
Kevin Scholz521a4ef2019-10-07 19:26:36 +053018
Dave Gerlachd712b362021-05-11 10:22:11 -050019static inline u32 lpddr4_configsf(const lpddr4_config *obj);
20static inline u32 lpddr4_privatedatasf(const lpddr4_privatedata *obj);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053021
Dave Gerlachd712b362021-05-11 10:22:11 -050022static inline u32 lpddr4_sanityfunction1(const lpddr4_config *config, const u16 *configsize);
23static inline u32 lpddr4_sanityfunction2(const lpddr4_privatedata *pd, const lpddr4_config *cfg);
24static inline u32 lpddr4_sanityfunction3(const lpddr4_privatedata *pd);
25static inline u32 lpddr4_sanityfunction4(const lpddr4_privatedata *pd, const lpddr4_regblock cpp, const u32 *regvalue);
26static inline u32 lpddr4_sanityfunction5(const lpddr4_privatedata *pd, const lpddr4_regblock cpp);
27static inline u32 lpddr4_sanityfunction6(const lpddr4_privatedata *pd, const u64 *mmrvalue, const u8 *mmrstatus);
28static inline u32 lpddr4_sanityfunction7(const lpddr4_privatedata *pd, const u8 *mrwstatus);
29static inline u32 lpddr4_sanityfunction14(const lpddr4_privatedata *pd, const u64 *mask);
30static inline u32 lpddr4_sanityfunction15(const lpddr4_privatedata *pd, const u64 *mask);
31static inline u32 lpddr4_sanityfunction16(const lpddr4_privatedata *pd, const u32 *mask);
32static inline u32 lpddr4_sanityfunction18(const lpddr4_privatedata *pd, const lpddr4_debuginfo *debuginfo);
33static inline u32 lpddr4_sanityfunction19(const lpddr4_privatedata *pd, const lpddr4_lpiwakeupparam *lpiwakeupparam, const lpddr4_ctlfspnum *fspnum, const u32 *cycles);
34static inline u32 lpddr4_sanityfunction21(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam);
35static inline u32 lpddr4_sanityfunction22(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam);
36static inline u32 lpddr4_sanityfunction23(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode);
37static inline u32 lpddr4_sanityfunction24(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode);
38static inline u32 lpddr4_sanityfunction25(const lpddr4_privatedata *pd, const bool *on_off);
39static inline u32 lpddr4_sanityfunction27(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode);
40static inline u32 lpddr4_sanityfunction28(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max);
41static 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 +053042
43#define lpddr4_probesf lpddr4_sanityfunction1
44#define lpddr4_initsf lpddr4_sanityfunction2
45#define lpddr4_startsf lpddr4_sanityfunction3
46#define lpddr4_readregsf lpddr4_sanityfunction4
47#define lpddr4_writeregsf lpddr4_sanityfunction5
48#define lpddr4_getmmrregistersf lpddr4_sanityfunction6
49#define lpddr4_setmmrregistersf lpddr4_sanityfunction7
Dave Gerlachd712b362021-05-11 10:22:11 -050050#define lpddr4_writectlconfigsf lpddr4_sanityfunction3
51#define lpddr4_writephyconfigsf lpddr4_sanityfunction3
52#define lpddr4_writephyindepconfigsf lpddr4_sanityfunction3
53#define lpddr4_readctlconfigsf lpddr4_sanityfunction3
54#define lpddr4_readphyconfigsf lpddr4_sanityfunction3
55#define lpddr4_readphyindepconfigsf lpddr4_sanityfunction3
Kevin Scholz521a4ef2019-10-07 19:26:36 +053056#define lpddr4_getctlinterruptmasksf lpddr4_sanityfunction14
57#define lpddr4_setctlinterruptmasksf lpddr4_sanityfunction15
Dave Gerlachd712b362021-05-11 10:22:11 -050058#define lpddr4_getphyindepinterruptmsf lpddr4_sanityfunction16
59#define lpddr4_setphyindepinterruptmsf lpddr4_sanityfunction16
60#define lpddr4_getdebuginitinfosf lpddr4_sanityfunction18
61#define lpddr4_getlpiwakeuptimesf lpddr4_sanityfunction19
62#define lpddr4_setlpiwakeuptimesf lpddr4_sanityfunction19
63#define lpddr4_geteccenablesf lpddr4_sanityfunction21
64#define lpddr4_seteccenablesf lpddr4_sanityfunction22
65#define lpddr4_getreducmodesf lpddr4_sanityfunction23
66#define lpddr4_setreducmodesf lpddr4_sanityfunction24
67#define lpddr4_getdbireadmodesf lpddr4_sanityfunction25
68#define lpddr4_getdbiwritemodesf lpddr4_sanityfunction25
69#define lpddr4_setdbimodesf lpddr4_sanityfunction27
70#define lpddr4_getrefreshratesf lpddr4_sanityfunction28
71#define lpddr4_setrefreshratesf lpddr4_sanityfunction29
Kevin Scholz521a4ef2019-10-07 19:26:36 +053072#define lpddr4_refreshperchipselectsf lpddr4_sanityfunction3
73
Dave Gerlachd712b362021-05-11 10:22:11 -050074static inline u32 lpddr4_configsf(const lpddr4_config *obj)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053075{
Dave Gerlachd712b362021-05-11 10:22:11 -050076 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053077
78 if (obj == NULL)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053079 ret = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053080
81 return ret;
82}
83
Dave Gerlachd712b362021-05-11 10:22:11 -050084static inline u32 lpddr4_privatedatasf(const lpddr4_privatedata *obj)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053085{
Dave Gerlachd712b362021-05-11 10:22:11 -050086 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053087
88 if (obj == NULL)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053089 ret = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053090
91 return ret;
92}
93
Dave Gerlachd712b362021-05-11 10:22:11 -050094static inline u32 lpddr4_sanityfunction1(const lpddr4_config *config, const u16 *configsize)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053095{
Dave Gerlachd712b362021-05-11 10:22:11 -050096 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053097
Dave Gerlachd712b362021-05-11 10:22:11 -050098 if (configsize == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +053099 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500100 } else if (lpddr4_configsf(config) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530101 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500102 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530103 }
104
105 return ret;
106}
107
Dave Gerlachd712b362021-05-11 10:22:11 -0500108static inline u32 lpddr4_sanityfunction2(const lpddr4_privatedata *pd, const lpddr4_config *cfg)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530109{
Dave Gerlachd712b362021-05-11 10:22:11 -0500110 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530111
Dave Gerlachd712b362021-05-11 10:22:11 -0500112 if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530113 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500114 } else if (lpddr4_configsf(cfg) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530115 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500116 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530117 }
118
119 return ret;
120}
121
Dave Gerlachd712b362021-05-11 10:22:11 -0500122static inline u32 lpddr4_sanityfunction3(const lpddr4_privatedata *pd)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530123{
Dave Gerlachd712b362021-05-11 10:22:11 -0500124 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530125
126 if (lpddr4_privatedatasf(pd) == EINVAL)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530127 ret = EINVAL;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530128
129 return ret;
130}
131
Dave Gerlachd712b362021-05-11 10:22:11 -0500132static inline u32 lpddr4_sanityfunction4(const lpddr4_privatedata *pd, const lpddr4_regblock cpp, const u32 *regvalue)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530133{
Dave Gerlachd712b362021-05-11 10:22:11 -0500134 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530135
Dave Gerlachd712b362021-05-11 10:22:11 -0500136 if (regvalue == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530137 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500138 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530139 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500140 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530141 (cpp != LPDDR4_CTL_REGS) &&
142 (cpp != LPDDR4_PHY_REGS) &&
143 (cpp != LPDDR4_PHY_INDEP_REGS)
Dave Gerlachd712b362021-05-11 10:22:11 -0500144 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530145 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500146 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530147 }
148
149 return ret;
150}
151
Dave Gerlachd712b362021-05-11 10:22:11 -0500152static inline u32 lpddr4_sanityfunction5(const lpddr4_privatedata *pd, const lpddr4_regblock cpp)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530153{
Dave Gerlachd712b362021-05-11 10:22:11 -0500154 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530155
Dave Gerlachd712b362021-05-11 10:22:11 -0500156 if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530157 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500158 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530159 (cpp != LPDDR4_CTL_REGS) &&
160 (cpp != LPDDR4_PHY_REGS) &&
161 (cpp != LPDDR4_PHY_INDEP_REGS)
Dave Gerlachd712b362021-05-11 10:22:11 -0500162 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530163 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500164 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530165 }
166
167 return ret;
168}
169
Dave Gerlachd712b362021-05-11 10:22:11 -0500170static inline u32 lpddr4_sanityfunction6(const lpddr4_privatedata *pd, const u64 *mmrvalue, const u8 *mmrstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530171{
Dave Gerlachd712b362021-05-11 10:22:11 -0500172 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530173
Dave Gerlachd712b362021-05-11 10:22:11 -0500174 if (mmrvalue == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530175 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500176 } else if (mmrstatus == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530177 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500178 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530179 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500180 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530181 }
182
183 return ret;
184}
185
Dave Gerlachd712b362021-05-11 10:22:11 -0500186static inline u32 lpddr4_sanityfunction7(const lpddr4_privatedata *pd, const u8 *mrwstatus)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530187{
Dave Gerlachd712b362021-05-11 10:22:11 -0500188 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530189
Dave Gerlachd712b362021-05-11 10:22:11 -0500190 if (mrwstatus == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530191 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500192 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530193 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500194 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530195 }
196
197 return ret;
198}
199
Dave Gerlachd712b362021-05-11 10:22:11 -0500200static inline u32 lpddr4_sanityfunction14(const lpddr4_privatedata *pd, const u64 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530201{
Dave Gerlachd712b362021-05-11 10:22:11 -0500202 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530203
Dave Gerlachd712b362021-05-11 10:22:11 -0500204 if (mask == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530205 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500206 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530207 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500208 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530209 }
210
211 return ret;
212}
213
Dave Gerlachd712b362021-05-11 10:22:11 -0500214static inline u32 lpddr4_sanityfunction15(const lpddr4_privatedata *pd, const u64 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530215{
Dave Gerlachd712b362021-05-11 10:22:11 -0500216 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530217
Dave Gerlachd712b362021-05-11 10:22:11 -0500218 if (mask == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530219 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500220 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530221 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500222 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530223 }
224
225 return ret;
226}
227
Dave Gerlachd712b362021-05-11 10:22:11 -0500228static inline u32 lpddr4_sanityfunction16(const lpddr4_privatedata *pd, const u32 *mask)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530229{
Dave Gerlachd712b362021-05-11 10:22:11 -0500230 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530231
Dave Gerlachd712b362021-05-11 10:22:11 -0500232 if (mask == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530233 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500234 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530235 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500236 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530237 }
238
239 return ret;
240}
241
Dave Gerlachd712b362021-05-11 10:22:11 -0500242static inline u32 lpddr4_sanityfunction18(const lpddr4_privatedata *pd, const lpddr4_debuginfo *debuginfo)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530243{
Dave Gerlachd712b362021-05-11 10:22:11 -0500244 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530245
Dave Gerlachd712b362021-05-11 10:22:11 -0500246 if (debuginfo == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530247 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500248 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530249 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500250 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530251 }
252
253 return ret;
254}
255
Dave Gerlachd712b362021-05-11 10:22:11 -0500256static 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 +0530257{
Dave Gerlachd712b362021-05-11 10:22:11 -0500258 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530259
Dave Gerlachd712b362021-05-11 10:22:11 -0500260 if (lpiwakeupparam == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530261 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500262 } else if (fspnum == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530263 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500264 } else if (cycles == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530265 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500266 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530267 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500268 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530269 (*lpiwakeupparam != LPDDR4_LPI_PD_WAKEUP_FN) &&
270 (*lpiwakeupparam != LPDDR4_LPI_SR_SHORT_WAKEUP_FN) &&
271 (*lpiwakeupparam != LPDDR4_LPI_SR_LONG_WAKEUP_FN) &&
272 (*lpiwakeupparam != LPDDR4_LPI_SR_LONG_MCCLK_GATE_WAKEUP_FN) &&
273 (*lpiwakeupparam != LPDDR4_LPI_SRPD_SHORT_WAKEUP_FN) &&
274 (*lpiwakeupparam != LPDDR4_LPI_SRPD_LONG_WAKEUP_FN) &&
275 (*lpiwakeupparam != LPDDR4_LPI_SRPD_LONG_MCCLK_GATE_WAKEUP_FN)
Dave Gerlachd712b362021-05-11 10:22:11 -0500276 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530277 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500278 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530279 (*fspnum != LPDDR4_FSP_0) &&
280 (*fspnum != LPDDR4_FSP_1) &&
281 (*fspnum != LPDDR4_FSP_2)
Dave Gerlachd712b362021-05-11 10:22:11 -0500282 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530283 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500284 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530285 }
286
287 return ret;
288}
289
Dave Gerlachd712b362021-05-11 10:22:11 -0500290static inline u32 lpddr4_sanityfunction21(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530291{
Dave Gerlachd712b362021-05-11 10:22:11 -0500292 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530293
Dave Gerlachd712b362021-05-11 10:22:11 -0500294 if (eccparam == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530295 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500296 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530297 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500298 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530299 }
300
301 return ret;
302}
303
Dave Gerlachd712b362021-05-11 10:22:11 -0500304static inline u32 lpddr4_sanityfunction22(const lpddr4_privatedata *pd, const lpddr4_eccenable *eccparam)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530305{
Dave Gerlachd712b362021-05-11 10:22:11 -0500306 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530307
Dave Gerlachd712b362021-05-11 10:22:11 -0500308 if (eccparam == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530309 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500310 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530311 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500312 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530313 (*eccparam != LPDDR4_ECC_DISABLED) &&
314 (*eccparam != LPDDR4_ECC_ENABLED) &&
315 (*eccparam != LPDDR4_ECC_ERR_DETECT) &&
316 (*eccparam != LPDDR4_ECC_ERR_DETECT_CORRECT)
Dave Gerlachd712b362021-05-11 10:22:11 -0500317 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530318 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500319 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530320 }
321
322 return ret;
323}
324
Dave Gerlachd712b362021-05-11 10:22:11 -0500325static inline u32 lpddr4_sanityfunction23(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530326{
Dave Gerlachd712b362021-05-11 10:22:11 -0500327 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530328
Dave Gerlachd712b362021-05-11 10:22:11 -0500329 if (mode == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530330 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500331 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530332 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500333 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530334 }
335
336 return ret;
337}
338
Dave Gerlachd712b362021-05-11 10:22:11 -0500339static inline u32 lpddr4_sanityfunction24(const lpddr4_privatedata *pd, const lpddr4_reducmode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530340{
Dave Gerlachd712b362021-05-11 10:22:11 -0500341 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530342
Dave Gerlachd712b362021-05-11 10:22:11 -0500343 if (mode == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530344 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500345 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530346 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500347 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530348 (*mode != LPDDR4_REDUC_ON) &&
349 (*mode != LPDDR4_REDUC_OFF)
Dave Gerlachd712b362021-05-11 10:22:11 -0500350 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530351 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500352 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530353 }
354
355 return ret;
356}
357
Dave Gerlachd712b362021-05-11 10:22:11 -0500358static inline u32 lpddr4_sanityfunction25(const lpddr4_privatedata *pd, const bool *on_off)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530359{
Dave Gerlachd712b362021-05-11 10:22:11 -0500360 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530361
Dave Gerlachd712b362021-05-11 10:22:11 -0500362 if (on_off == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530363 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500364 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530365 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500366 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530367 }
368
369 return ret;
370}
371
Dave Gerlachd712b362021-05-11 10:22:11 -0500372static inline u32 lpddr4_sanityfunction27(const lpddr4_privatedata *pd, const lpddr4_dbimode *mode)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530373{
Dave Gerlachd712b362021-05-11 10:22:11 -0500374 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530375
Dave Gerlachd712b362021-05-11 10:22:11 -0500376 if (mode == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530377 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500378 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530379 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500380 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530381 (*mode != LPDDR4_DBI_RD_ON) &&
382 (*mode != LPDDR4_DBI_RD_OFF) &&
383 (*mode != LPDDR4_DBI_WR_ON) &&
384 (*mode != LPDDR4_DBI_WR_OFF)
Dave Gerlachd712b362021-05-11 10:22:11 -0500385 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530386 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500387 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530388 }
389
390 return ret;
391}
392
Dave Gerlachd712b362021-05-11 10:22:11 -0500393static inline u32 lpddr4_sanityfunction28(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max)
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530394{
Dave Gerlachd712b362021-05-11 10:22:11 -0500395 u32 ret = 0;
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530396
Dave Gerlachd712b362021-05-11 10:22:11 -0500397 if (fspnum == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530398 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500399 } else if (tref == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530400 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500401 } else if (tras_max == NULL) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530402 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500403 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
404 ret = EINVAL;
405 } else if (
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530406 (*fspnum != LPDDR4_FSP_0) &&
407 (*fspnum != LPDDR4_FSP_1) &&
408 (*fspnum != LPDDR4_FSP_2)
Dave Gerlachd712b362021-05-11 10:22:11 -0500409 ) {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530410 ret = EINVAL;
Dave Gerlachd712b362021-05-11 10:22:11 -0500411 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530412 }
Dave Gerlachd712b362021-05-11 10:22:11 -0500413
414 return ret;
415}
416
417static inline u32 lpddr4_sanityfunction29(const lpddr4_privatedata *pd, const lpddr4_ctlfspnum *fspnum, const u32 *tref, const u32 *tras_max)
418{
419 u32 ret = 0;
420
421 if (fspnum == NULL) {
422 ret = EINVAL;
423 } else if (tref == NULL) {
424 ret = EINVAL;
425 } else if (tras_max == NULL) {
426 ret = EINVAL;
427 } else if (lpddr4_privatedatasf(pd) == EINVAL) {
428 ret = EINVAL;
429 } else if (
430 (*fspnum != LPDDR4_FSP_0) &&
431 (*fspnum != LPDDR4_FSP_1) &&
432 (*fspnum != LPDDR4_FSP_2)
433 ) {
434 ret = EINVAL;
435 } else {
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530436 }
437
438 return ret;
439}
440
Dave Gerlachd712b362021-05-11 10:22:11 -0500441#ifdef __cplusplus
442}
443#endif
444
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530445#endif /* LPDDR4_SANITY_H */