blob: 298aa5e6cb8b2a6558e2d7c937a66684f08eaeac [file] [log] [blame]
Kevin Scholz521a4ef2019-10-07 19:26:36 +05301/* SPDX-License-Identifier: BSD-3-Clause */
Dave Gerlachd712b362021-05-11 10:22:11 -05002/*
3 * Cadence DDR Driver
Kevin Scholz521a4ef2019-10-07 19:26:36 +05304 *
Dave Gerlachd712b362021-05-11 10:22:11 -05005 * Copyright (C) 2012-2021 Cadence Design Systems, Inc.
6 * Copyright (C) 2018-2021 Texas Instruments Incorporated - https://www.ti.com/
Kevin Scholz521a4ef2019-10-07 19:26:36 +05307 */
8
9#ifndef CPS_DRV_H_
10#define CPS_DRV_H_
11
Dave Gerlachd712b362021-05-11 10:22:11 -050012#ifdef DEMO_TB
13#include <cdn_demo.h>
14#else
Kevin Scholz521a4ef2019-10-07 19:26:36 +053015#include <asm/io.h>
Dave Gerlachd712b362021-05-11 10:22:11 -050016#endif
Kevin Scholz521a4ef2019-10-07 19:26:36 +053017
Dave Gerlachd712b362021-05-11 10:22:11 -050018#define CPS_REG_READ(reg) (cps_regread((volatile u32 *)(reg)))
Kevin Scholz521a4ef2019-10-07 19:26:36 +053019
Dave Gerlachd712b362021-05-11 10:22:11 -050020#define CPS_REG_WRITE(reg, value) (cps_regwrite((volatile u32 *)(reg), (u32)(value)))
Kevin Scholz521a4ef2019-10-07 19:26:36 +053021
Kevin Scholz521a4ef2019-10-07 19:26:36 +053022#define CPS_FLD_MASK(fld) (fld ## _MASK)
23#define CPS_FLD_SHIFT(fld) (fld ## _SHIFT)
24#define CPS_FLD_WIDTH(fld) (fld ## _WIDTH)
25#define CPS_FLD_WOCLR(fld) (fld ## _WOCLR)
26#define CPS_FLD_WOSET(fld) (fld ## _WOSET)
27
Dave Gerlachd712b362021-05-11 10:22:11 -050028#define CPS_FLD_READ(fld, reg_value) (cps_fldread((u32)(CPS_FLD_MASK(fld)), \
29 (u32)(CPS_FLD_SHIFT(fld)), \
30 (u32)(reg_value)))
Kevin Scholz521a4ef2019-10-07 19:26:36 +053031
Dave Gerlachd712b362021-05-11 10:22:11 -050032#define CPS_FLD_WRITE(fld, reg_value, value) (cps_fldwrite((u32)(CPS_FLD_MASK(fld)), \
33 (u32)(CPS_FLD_SHIFT(fld)), \
34 (u32)(reg_value), (u32)(value)))
Kevin Scholz521a4ef2019-10-07 19:26:36 +053035
Dave Gerlachd712b362021-05-11 10:22:11 -050036#define CPS_FLD_SET(fld, reg_value) (cps_fldset((u32)(CPS_FLD_WIDTH(fld)), \
37 (u32)(CPS_FLD_MASK(fld)), \
38 (u32)(CPS_FLD_WOCLR(fld)), \
39 (u32)(reg_value)))
Kevin Scholz521a4ef2019-10-07 19:26:36 +053040
Dave Gerlachd712b362021-05-11 10:22:11 -050041#ifdef CLR_USED
42#define CPS_FLD_CLEAR(reg, fld, reg_value) (cps_fldclear((u32)(CPS_FLD_WIDTH(fld)), \
43 (u32)(CPS_FLD_MASK(fld)), \
44 (u32)(CPS_FLD_WOSET(fld)), \
45 (u32)(CPS_FLD_WOCLR(fld)), \
46 (u32)(reg_value)))
47
48#endif
49static inline u32 cps_regread(volatile u32 *reg);
50static inline u32 cps_regread(volatile u32 *reg)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053051{
Dave Gerlachd712b362021-05-11 10:22:11 -050052 return readl(reg);
53}
Kevin Scholz521a4ef2019-10-07 19:26:36 +053054
Dave Gerlachd712b362021-05-11 10:22:11 -050055static inline void cps_regwrite(volatile u32 *reg, u32 value);
56static inline void cps_regwrite(volatile u32 *reg, u32 value)
57{
58 writel(value, reg);
Kevin Scholz521a4ef2019-10-07 19:26:36 +053059}
60
Dave Gerlachd712b362021-05-11 10:22:11 -050061static inline u32 cps_fldread(u32 mask, u32 shift, u32 reg_value);
62static inline u32 cps_fldread(u32 mask, u32 shift, u32 reg_value)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053063{
Dave Gerlachd712b362021-05-11 10:22:11 -050064 u32 result = (reg_value & mask) >> shift;
65
66 return result;
67}
68
69static inline u32 cps_fldwrite(u32 mask, u32 shift, u32 reg_value, u32 value);
70static inline u32 cps_fldwrite(u32 mask, u32 shift, u32 reg_value, u32 value)
71{
72 u32 new_value = (value << shift) & mask;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053073
74 new_value = (reg_value & ~mask) | new_value;
Dave Gerlachd712b362021-05-11 10:22:11 -050075 return new_value;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053076}
77
Dave Gerlachd712b362021-05-11 10:22:11 -050078static inline u32 cps_fldset(u32 width, u32 mask, u32 is_woclr, u32 reg_value);
79static inline u32 cps_fldset(u32 width, u32 mask, u32 is_woclr, u32 reg_value)
Kevin Scholz521a4ef2019-10-07 19:26:36 +053080{
Dave Gerlachd712b362021-05-11 10:22:11 -050081 u32 new_value = reg_value;
82
83 if ((width == 1U) && (is_woclr == 0U))
Kevin Scholz521a4ef2019-10-07 19:26:36 +053084 new_value |= mask;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053085
Dave Gerlachd712b362021-05-11 10:22:11 -050086 return new_value;
Kevin Scholz521a4ef2019-10-07 19:26:36 +053087}
Dave Gerlachd712b362021-05-11 10:22:11 -050088
89#ifdef CLR_USED
90static inline u32 cps_fldclear(u32 width, u32 mask, u32 is_woset, u32 is_woclr, u32 reg_value);
91static inline u32 cps_fldclear(u32 width, u32 mask, u32 is_woset, u32 is_woclr, u32 reg_value)
92{
93 u32 new_value = reg_value;
94
95 if ((width == 1U) && (is_woset == 0U))
96 new_value = (new_value & ~mask) | ((is_woclr != 0U) ? mask : 0U);
97
98 return new_value;
99}
100#endif /* CLR_USED */
101
Kevin Scholz521a4ef2019-10-07 19:26:36 +0530102#endif /* CPS_DRV_H_ */