2019-10-07 13:56:36 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
2021-05-11 15:22:11 +00:00
|
|
|
/*
|
|
|
|
* Cadence DDR Driver
|
2019-10-07 13:56:36 +00:00
|
|
|
*
|
2022-10-24 21:53:28 +00:00
|
|
|
* Copyright (C) 2012-2022 Cadence Design Systems, Inc.
|
|
|
|
* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
|
2019-10-07 13:56:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CPS_DRV_H_
|
|
|
|
#define CPS_DRV_H_
|
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
#ifdef DEMO_TB
|
|
|
|
#include <cdn_demo.h>
|
|
|
|
#else
|
2019-10-07 13:56:36 +00:00
|
|
|
#include <asm/io.h>
|
2021-05-11 15:22:11 +00:00
|
|
|
#endif
|
2019-10-07 13:56:36 +00:00
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
#define CPS_REG_READ(reg) (cps_regread((volatile u32 *)(reg)))
|
2019-10-07 13:56:36 +00:00
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
#define CPS_REG_WRITE(reg, value) (cps_regwrite((volatile u32 *)(reg), (u32)(value)))
|
2019-10-07 13:56:36 +00:00
|
|
|
|
|
|
|
#define CPS_FLD_MASK(fld) (fld ## _MASK)
|
|
|
|
#define CPS_FLD_SHIFT(fld) (fld ## _SHIFT)
|
|
|
|
#define CPS_FLD_WIDTH(fld) (fld ## _WIDTH)
|
|
|
|
#define CPS_FLD_WOCLR(fld) (fld ## _WOCLR)
|
|
|
|
#define CPS_FLD_WOSET(fld) (fld ## _WOSET)
|
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
#define CPS_FLD_READ(fld, reg_value) (cps_fldread((u32)(CPS_FLD_MASK(fld)), \
|
|
|
|
(u32)(CPS_FLD_SHIFT(fld)), \
|
|
|
|
(u32)(reg_value)))
|
2019-10-07 13:56:36 +00:00
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
#define CPS_FLD_WRITE(fld, reg_value, value) (cps_fldwrite((u32)(CPS_FLD_MASK(fld)), \
|
|
|
|
(u32)(CPS_FLD_SHIFT(fld)), \
|
|
|
|
(u32)(reg_value), (u32)(value)))
|
|
|
|
|
|
|
|
#define CPS_FLD_SET(fld, reg_value) (cps_fldset((u32)(CPS_FLD_WIDTH(fld)), \
|
|
|
|
(u32)(CPS_FLD_MASK(fld)), \
|
|
|
|
(u32)(CPS_FLD_WOCLR(fld)), \
|
|
|
|
(u32)(reg_value)))
|
|
|
|
|
|
|
|
#ifdef CLR_USED
|
|
|
|
#define CPS_FLD_CLEAR(reg, fld, reg_value) (cps_fldclear((u32)(CPS_FLD_WIDTH(fld)), \
|
|
|
|
(u32)(CPS_FLD_MASK(fld)), \
|
|
|
|
(u32)(CPS_FLD_WOSET(fld)), \
|
|
|
|
(u32)(CPS_FLD_WOCLR(fld)), \
|
|
|
|
(u32)(reg_value)))
|
|
|
|
|
|
|
|
#endif
|
|
|
|
static inline u32 cps_regread(volatile u32 *reg);
|
|
|
|
static inline u32 cps_regread(volatile u32 *reg)
|
2019-10-07 13:56:36 +00:00
|
|
|
{
|
2021-05-11 15:22:11 +00:00
|
|
|
return readl(reg);
|
|
|
|
}
|
2019-10-07 13:56:36 +00:00
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
static inline void cps_regwrite(volatile u32 *reg, u32 value);
|
|
|
|
static inline void cps_regwrite(volatile u32 *reg, u32 value)
|
|
|
|
{
|
|
|
|
writel(value, reg);
|
2019-10-07 13:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
static inline u32 cps_fldread(u32 mask, u32 shift, u32 reg_value);
|
|
|
|
static inline u32 cps_fldread(u32 mask, u32 shift, u32 reg_value)
|
2019-10-07 13:56:36 +00:00
|
|
|
{
|
2021-05-11 15:22:11 +00:00
|
|
|
u32 result = (reg_value & mask) >> shift;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 cps_fldwrite(u32 mask, u32 shift, u32 reg_value, u32 value);
|
|
|
|
static inline u32 cps_fldwrite(u32 mask, u32 shift, u32 reg_value, u32 value)
|
|
|
|
{
|
|
|
|
u32 new_value = (value << shift) & mask;
|
2019-10-07 13:56:36 +00:00
|
|
|
|
|
|
|
new_value = (reg_value & ~mask) | new_value;
|
2021-05-11 15:22:11 +00:00
|
|
|
return new_value;
|
2019-10-07 13:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
static inline u32 cps_fldset(u32 width, u32 mask, u32 is_woclr, u32 reg_value);
|
|
|
|
static inline u32 cps_fldset(u32 width, u32 mask, u32 is_woclr, u32 reg_value)
|
2019-10-07 13:56:36 +00:00
|
|
|
{
|
2021-05-11 15:22:11 +00:00
|
|
|
u32 new_value = reg_value;
|
|
|
|
|
|
|
|
if ((width == 1U) && (is_woclr == 0U))
|
2019-10-07 13:56:36 +00:00
|
|
|
new_value |= mask;
|
|
|
|
|
2021-05-11 15:22:11 +00:00
|
|
|
return new_value;
|
2019-10-07 13:56:36 +00:00
|
|
|
}
|
2021-05-11 15:22:11 +00:00
|
|
|
|
|
|
|
#ifdef CLR_USED
|
|
|
|
static inline u32 cps_fldclear(u32 width, u32 mask, u32 is_woset, u32 is_woclr, u32 reg_value);
|
|
|
|
static inline u32 cps_fldclear(u32 width, u32 mask, u32 is_woset, u32 is_woclr, u32 reg_value)
|
|
|
|
{
|
|
|
|
u32 new_value = reg_value;
|
|
|
|
|
|
|
|
if ((width == 1U) && (is_woset == 0U))
|
|
|
|
new_value = (new_value & ~mask) | ((is_woclr != 0U) ? mask : 0U);
|
|
|
|
|
|
|
|
return new_value;
|
|
|
|
}
|
|
|
|
#endif /* CLR_USED */
|
|
|
|
|
2019-10-07 13:56:36 +00:00
|
|
|
#endif /* CPS_DRV_H_ */
|