Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Cadence DDR Driver |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 4 | * |
Bryan Brattlof | 85b5cc8 | 2022-10-24 16:53:28 -0500 | [diff] [blame] | 5 | * Copyright (C) 2012-2022 Cadence Design Systems, Inc. |
| 6 | * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef CPS_DRV_H_ |
| 10 | #define CPS_DRV_H_ |
| 11 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 12 | #ifdef DEMO_TB |
| 13 | #include <cdn_demo.h> |
| 14 | #else |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 15 | #include <asm/io.h> |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 16 | #endif |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 17 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 18 | #define CPS_REG_READ(reg) (cps_regread((volatile u32 *)(reg))) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 19 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 20 | #define CPS_REG_WRITE(reg, value) (cps_regwrite((volatile u32 *)(reg), (u32)(value))) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 21 | |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 22 | #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 Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 28 | #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 Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 31 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 32 | #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 Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 35 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 36 | #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 Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 40 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 41 | #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 |
| 49 | static inline u32 cps_regread(volatile u32 *reg); |
| 50 | static inline u32 cps_regread(volatile u32 *reg) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 51 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 52 | return readl(reg); |
| 53 | } |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 54 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 55 | static inline void cps_regwrite(volatile u32 *reg, u32 value); |
| 56 | static inline void cps_regwrite(volatile u32 *reg, u32 value) |
| 57 | { |
| 58 | writel(value, reg); |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 59 | } |
| 60 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 61 | static inline u32 cps_fldread(u32 mask, u32 shift, u32 reg_value); |
| 62 | static inline u32 cps_fldread(u32 mask, u32 shift, u32 reg_value) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 63 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 64 | u32 result = (reg_value & mask) >> shift; |
| 65 | |
| 66 | return result; |
| 67 | } |
| 68 | |
| 69 | static inline u32 cps_fldwrite(u32 mask, u32 shift, u32 reg_value, u32 value); |
| 70 | static inline u32 cps_fldwrite(u32 mask, u32 shift, u32 reg_value, u32 value) |
| 71 | { |
| 72 | u32 new_value = (value << shift) & mask; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 73 | |
| 74 | new_value = (reg_value & ~mask) | new_value; |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 75 | return new_value; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 76 | } |
| 77 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 78 | static inline u32 cps_fldset(u32 width, u32 mask, u32 is_woclr, u32 reg_value); |
| 79 | static inline u32 cps_fldset(u32 width, u32 mask, u32 is_woclr, u32 reg_value) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 80 | { |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 81 | u32 new_value = reg_value; |
| 82 | |
| 83 | if ((width == 1U) && (is_woclr == 0U)) |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 84 | new_value |= mask; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 85 | |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 86 | return new_value; |
Kevin Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 87 | } |
Dave Gerlach | d712b36 | 2021-05-11 10:22:11 -0500 | [diff] [blame] | 88 | |
| 89 | #ifdef CLR_USED |
| 90 | static inline u32 cps_fldclear(u32 width, u32 mask, u32 is_woset, u32 is_woclr, u32 reg_value); |
| 91 | static 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 Scholz | 521a4ef | 2019-10-07 19:26:36 +0530 | [diff] [blame] | 102 | #endif /* CPS_DRV_H_ */ |