Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2017-2019 Intel Corporation <www.intel.com> |
| 4 | */ |
| 5 | |
| 6 | #ifndef _SDRAM_SOC64_H_ |
| 7 | #define _SDRAM_SOC64_H_ |
| 8 | |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 9 | #include <linux/sizes.h> |
| 10 | |
| 11 | struct altera_sdram_priv { |
| 12 | struct ram_info info; |
| 13 | struct reset_ctl_bulk resets; |
| 14 | }; |
| 15 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 16 | struct altera_sdram_plat { |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 17 | void __iomem *hmc; |
| 18 | void __iomem *ddr_sch; |
| 19 | void __iomem *iomhc; |
| 20 | }; |
| 21 | |
| 22 | /* ECC HMC registers */ |
| 23 | #define DDRIOCTRL 0x8 |
| 24 | #define DDRCALSTAT 0xc |
| 25 | #define DRAMADDRWIDTH 0xe0 |
| 26 | #define ECCCTRL1 0x100 |
| 27 | #define ECCCTRL2 0x104 |
| 28 | #define ERRINTEN 0x110 |
| 29 | #define ERRINTENS 0x114 |
| 30 | #define INTMODE 0x11c |
| 31 | #define INTSTAT 0x120 |
| 32 | #define AUTOWB_CORRADDR 0x138 |
| 33 | #define ECC_REG2WRECCDATABUS 0x144 |
| 34 | #define ECC_DIAGON 0x150 |
| 35 | #define ECC_DECSTAT 0x154 |
| 36 | #define HPSINTFCSEL 0x210 |
| 37 | #define RSTHANDSHAKECTRL 0x214 |
| 38 | #define RSTHANDSHAKESTAT 0x218 |
| 39 | |
| 40 | #define DDR_HMC_DDRIOCTRL_IOSIZE_MSK 0x00000003 |
| 41 | #define DDR_HMC_DDRCALSTAT_CAL_MSK BIT(0) |
| 42 | #define DDR_HMC_ECCCTL_AWB_CNT_RST_SET_MSK BIT(16) |
| 43 | #define DDR_HMC_ECCCTL_CNT_RST_SET_MSK BIT(8) |
| 44 | #define DDR_HMC_ECCCTL_ECC_EN_SET_MSK BIT(0) |
| 45 | #define DDR_HMC_ECCCTL2_RMW_EN_SET_MSK BIT(8) |
| 46 | #define DDR_HMC_ECCCTL2_AWB_EN_SET_MSK BIT(0) |
| 47 | #define DDR_HMC_ECC_DIAGON_ECCDIAGON_EN_SET_MSK BIT(16) |
| 48 | #define DDR_HMC_ECC_DIAGON_WRDIAGON_EN_SET_MSK BIT(0) |
| 49 | #define DDR_HMC_ERRINTEN_SERRINTEN_EN_SET_MSK BIT(0) |
| 50 | #define DDR_HMC_ERRINTEN_DERRINTEN_EN_SET_MSK BIT(1) |
| 51 | #define DDR_HMC_INTSTAT_SERRPENA_SET_MSK BIT(0) |
| 52 | #define DDR_HMC_INTSTAT_DERRPENA_SET_MSK BIT(1) |
| 53 | #define DDR_HMC_INTSTAT_ADDRMTCFLG_SET_MSK BIT(16) |
| 54 | #define DDR_HMC_INTMODE_INTMODE_SET_MSK BIT(0) |
Tien Fong Chee | 7bcd663 | 2022-04-27 12:27:21 +0800 | [diff] [blame] | 55 | #define DDR_HMC_RSTHANDSHAKE_MASK 0x0000000f |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 56 | #define DDR_HMC_CORE2SEQ_INT_REQ 0xF |
| 57 | #define DDR_HMC_SEQ2CORE_INT_RESP_MASK BIT(3) |
| 58 | #define DDR_HMC_HPSINTFCSEL_ENABLE_MASK 0x001f1f1f |
| 59 | |
| 60 | #define DDR_HMC_ERRINTEN_INTMASK \ |
| 61 | (DDR_HMC_ERRINTEN_SERRINTEN_EN_SET_MSK | \ |
| 62 | DDR_HMC_ERRINTEN_DERRINTEN_EN_SET_MSK) |
| 63 | |
| 64 | /* HMC MMR IO48 registers */ |
| 65 | #define CTRLCFG0 0x28 |
| 66 | #define CTRLCFG1 0x2c |
Ley Foon Tan | 4ddb909 | 2019-11-27 15:55:27 +0800 | [diff] [blame] | 67 | #define CTRLCFG3 0x34 |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 68 | #define DRAMTIMING0 0x50 |
| 69 | #define CALTIMING0 0x7c |
| 70 | #define CALTIMING1 0x80 |
| 71 | #define CALTIMING2 0x84 |
| 72 | #define CALTIMING3 0x88 |
| 73 | #define CALTIMING4 0x8c |
| 74 | #define CALTIMING9 0xa0 |
| 75 | #define DRAMADDRW 0xa8 |
| 76 | #define DRAMSTS 0xec |
| 77 | #define NIOSRESERVED0 0x110 |
| 78 | #define NIOSRESERVED1 0x114 |
| 79 | #define NIOSRESERVED2 0x118 |
| 80 | |
| 81 | #define DRAMADDRW_CFG_COL_ADDR_WIDTH(x) \ |
| 82 | (((x) >> 0) & 0x1F) |
| 83 | #define DRAMADDRW_CFG_ROW_ADDR_WIDTH(x) \ |
| 84 | (((x) >> 5) & 0x1F) |
| 85 | #define DRAMADDRW_CFG_BANK_ADDR_WIDTH(x) \ |
| 86 | (((x) >> 10) & 0xF) |
| 87 | #define DRAMADDRW_CFG_BANK_GRP_ADDR_WIDTH(x) \ |
| 88 | (((x) >> 14) & 0x3) |
| 89 | #define DRAMADDRW_CFG_CS_ADDR_WIDTH(x) \ |
| 90 | (((x) >> 16) & 0x7) |
| 91 | |
| 92 | #define CTRLCFG0_CFG_MEMTYPE(x) \ |
| 93 | (((x) >> 0) & 0xF) |
| 94 | #define CTRLCFG0_CFG_DIMM_TYPE(x) \ |
| 95 | (((x) >> 4) & 0x7) |
| 96 | #define CTRLCFG0_CFG_AC_POS(x) \ |
| 97 | (((x) >> 7) & 0x3) |
| 98 | #define CTRLCFG0_CFG_CTRL_BURST_LEN(x) \ |
| 99 | (((x) >> 9) & 0x1F) |
| 100 | |
| 101 | #define CTRLCFG1_CFG_DBC3_BURST_LEN(x) \ |
| 102 | (((x) >> 0) & 0x1F) |
| 103 | #define CTRLCFG1_CFG_ADDR_ORDER(x) \ |
| 104 | (((x) >> 5) & 0x3) |
| 105 | #define CTRLCFG1_CFG_CTRL_EN_ECC(x) \ |
| 106 | (((x) >> 7) & 0x1) |
| 107 | |
| 108 | #define DRAMTIMING0_CFG_TCL(x) \ |
| 109 | (((x) >> 0) & 0x7F) |
| 110 | |
| 111 | #define CALTIMING0_CFG_ACT_TO_RDWR(x) \ |
| 112 | (((x) >> 0) & 0x3F) |
| 113 | #define CALTIMING0_CFG_ACT_TO_PCH(x) \ |
| 114 | (((x) >> 6) & 0x3F) |
| 115 | #define CALTIMING0_CFG_ACT_TO_ACT(x) \ |
| 116 | (((x) >> 12) & 0x3F) |
| 117 | #define CALTIMING0_CFG_ACT_TO_ACT_DB(x) \ |
| 118 | (((x) >> 18) & 0x3F) |
| 119 | |
| 120 | #define CALTIMING1_CFG_RD_TO_RD(x) \ |
| 121 | (((x) >> 0) & 0x3F) |
| 122 | #define CALTIMING1_CFG_RD_TO_RD_DC(x) \ |
| 123 | (((x) >> 6) & 0x3F) |
| 124 | #define CALTIMING1_CFG_RD_TO_RD_DB(x) \ |
| 125 | (((x) >> 12) & 0x3F) |
| 126 | #define CALTIMING1_CFG_RD_TO_WR(x) \ |
| 127 | (((x) >> 18) & 0x3F) |
| 128 | #define CALTIMING1_CFG_RD_TO_WR_DC(x) \ |
| 129 | (((x) >> 24) & 0x3F) |
| 130 | |
| 131 | #define CALTIMING2_CFG_RD_TO_WR_DB(x) \ |
| 132 | (((x) >> 0) & 0x3F) |
| 133 | #define CALTIMING2_CFG_RD_TO_WR_PCH(x) \ |
| 134 | (((x) >> 6) & 0x3F) |
| 135 | #define CALTIMING2_CFG_RD_AP_TO_VALID(x) \ |
| 136 | (((x) >> 12) & 0x3F) |
| 137 | #define CALTIMING2_CFG_WR_TO_WR(x) \ |
| 138 | (((x) >> 18) & 0x3F) |
| 139 | #define CALTIMING2_CFG_WR_TO_WR_DC(x) \ |
| 140 | (((x) >> 24) & 0x3F) |
| 141 | |
| 142 | #define CALTIMING3_CFG_WR_TO_WR_DB(x) \ |
| 143 | (((x) >> 0) & 0x3F) |
| 144 | #define CALTIMING3_CFG_WR_TO_RD(x) \ |
| 145 | (((x) >> 6) & 0x3F) |
| 146 | #define CALTIMING3_CFG_WR_TO_RD_DC(x) \ |
| 147 | (((x) >> 12) & 0x3F) |
| 148 | #define CALTIMING3_CFG_WR_TO_RD_DB(x) \ |
| 149 | (((x) >> 18) & 0x3F) |
| 150 | #define CALTIMING3_CFG_WR_TO_PCH(x) \ |
| 151 | (((x) >> 24) & 0x3F) |
| 152 | |
| 153 | #define CALTIMING4_CFG_WR_AP_TO_VALID(x) \ |
| 154 | (((x) >> 0) & 0x3F) |
| 155 | #define CALTIMING4_CFG_PCH_TO_VALID(x) \ |
| 156 | (((x) >> 6) & 0x3F) |
| 157 | #define CALTIMING4_CFG_PCH_ALL_TO_VALID(x) \ |
| 158 | (((x) >> 12) & 0x3F) |
| 159 | #define CALTIMING4_CFG_ARF_TO_VALID(x) \ |
| 160 | (((x) >> 18) & 0xFF) |
| 161 | #define CALTIMING4_CFG_PDN_TO_VALID(x) \ |
| 162 | (((x) >> 26) & 0x3F) |
| 163 | |
| 164 | #define CALTIMING9_CFG_4_ACT_TO_ACT(x) \ |
| 165 | (((x) >> 0) & 0xFF) |
| 166 | |
| 167 | /* Firewall DDR scheduler MPFE */ |
| 168 | #define FW_HMC_ADAPTOR_REG_ADDR 0xf8020004 |
| 169 | #define FW_HMC_ADAPTOR_MPU_MASK BIT(0) |
| 170 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 171 | u32 hmc_readl(struct altera_sdram_plat *plat, u32 reg); |
| 172 | u32 hmc_ecc_readl(struct altera_sdram_plat *plat, u32 reg); |
| 173 | u32 hmc_ecc_writel(struct altera_sdram_plat *plat, |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 174 | u32 data, u32 reg); |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 175 | u32 ddr_sch_writel(struct altera_sdram_plat *plat, u32 data, |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 176 | u32 reg); |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 177 | int emif_clear(struct altera_sdram_plat *plat); |
| 178 | int emif_reset(struct altera_sdram_plat *plat); |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 179 | int poll_hmc_clock_status(void); |
| 180 | void sdram_clear_mem(phys_addr_t addr, phys_size_t size); |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 181 | void sdram_init_ecc_bits(struct bd_info *bd); |
Tien Fong Chee | f8e2eab | 2021-08-10 11:26:37 +0800 | [diff] [blame] | 182 | void sdram_set_firewall(struct bd_info *bd); |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 183 | void sdram_size_check(struct bd_info *bd); |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 184 | phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat); |
Ley Foon Tan | 25572cf | 2019-11-27 15:55:26 +0800 | [diff] [blame] | 185 | int sdram_mmr_init_full(struct udevice *dev); |
| 186 | |
| 187 | #endif /* _SDRAM_SOC64_H_ */ |