Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef AGX_MEMORYCONTROLLER_H |
| 8 | #define AGX_MEMORYCONTROLLER_H |
| 9 | |
| 10 | #define AGX_MPFE_IOHMC_REG_DRAMADDRW 0xf80100a8 |
| 11 | #define AGX_MPFE_IOHMC_CTRLCFG0 0xf8010028 |
| 12 | #define AGX_MPFE_IOHMC_CTRLCFG1 0xf801002c |
Hadi Asyrafi | 83fe38e | 2019-08-08 18:52:31 +0800 | [diff] [blame] | 13 | #define AGX_MPFE_IOHMC_CTRLCFG2 0xf8010030 |
| 14 | #define AGX_MPFE_IOHMC_CTRLCFG3 0xf8010034 |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 15 | #define AGX_MPFE_IOHMC_DRAMADDRW 0xf80100a8 |
| 16 | #define AGX_MPFE_IOHMC_DRAMTIMING0 0xf8010050 |
| 17 | #define AGX_MPFE_IOHMC_CALTIMING0 0xf801007c |
| 18 | #define AGX_MPFE_IOHMC_CALTIMING1 0xf8010080 |
| 19 | #define AGX_MPFE_IOHMC_CALTIMING2 0xf8010084 |
| 20 | #define AGX_MPFE_IOHMC_CALTIMING3 0xf8010088 |
| 21 | #define AGX_MPFE_IOHMC_CALTIMING4 0xf801008c |
| 22 | #define AGX_MPFE_IOHMC_CALTIMING9 0xf80100a0 |
| 23 | #define AGX_MPFE_IOHMC_CALTIMING9_ACT_TO_ACT(x) (((x) & 0x000000ff) >> 0) |
| 24 | #define AGX_MPFE_IOHMC_CTRLCFG1_CFG_ADDR_ORDER(value) \ |
| 25 | (((value) & 0x00000060) >> 5) |
| 26 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 27 | #define AGX_MPFE_HMC_ADP_ECCCTRL1 0xf8011100 |
| 28 | #define AGX_MPFE_HMC_ADP_ECCCTRL2 0xf8011104 |
| 29 | #define AGX_MPFE_HMC_ADP_RSTHANDSHAKESTAT 0xf8011218 |
| 30 | #define AGX_MPFE_HMC_ADP_RSTHANDSHAKESTAT_SEQ2CORE 0x000000ff |
| 31 | #define AGX_MPFE_HMC_ADP_RSTHANDSHAKECTRL 0xf8011214 |
| 32 | |
| 33 | |
| 34 | #define AGX_MPFE_IOHMC_REG_CTRLCFG1 0xf801002c |
| 35 | |
| 36 | #define AGX_MPFE_IOHMC_REG_NIOSRESERVE0_OFST 0xf8010110 |
| 37 | |
| 38 | #define IOHMC_DRAMADDRW_COL_ADDR_WIDTH(x) (((x) & 0x0000001f) >> 0) |
| 39 | #define IOHMC_DRAMADDRW_ROW_ADDR_WIDTH(x) (((x) & 0x000003e0) >> 5) |
| 40 | #define IOHMC_DRAMADDRW_CS_ADDR_WIDTH(x) (((x) & 0x00070000) >> 16) |
| 41 | #define IOHMC_DRAMADDRW_BANK_GRP_ADDR_WIDTH(x) (((x) & 0x0000c000) >> 14) |
| 42 | #define IOHMC_DRAMADDRW_BANK_ADDR_WIDTH(x) (((x) & 0x00003c00) >> 10) |
| 43 | |
| 44 | #define AGX_MPFE_DDR(x) (0xf8000000 + x) |
| 45 | #define AGX_MPFE_HMC_ADP_DDRCALSTAT 0xf801100c |
| 46 | #define AGX_MPFE_DDR_MAIN_SCHED 0xf8000400 |
| 47 | #define AGX_MPFE_DDR_MAIN_SCHED_DDRCONF 0xf8000408 |
| 48 | #define AGX_MPFE_DDR_MAIN_SCHED_DDRTIMING 0xf800040c |
| 49 | #define AGX_MPFE_DDR_MAIN_SCHED_DDRCONF_SET_MSK 0x0000001f |
| 50 | #define AGX_MPFE_DDR_MAIN_SCHED_DDRMODE 0xf8000410 |
| 51 | #define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV 0xf800043c |
| 52 | #define AGX_MPFE_DDR_MAIN_SCHED_READLATENCY 0xf8000414 |
| 53 | #define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE 0xf8000438 |
| 54 | #define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_FAWBANK_OFST 10 |
| 55 | #define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_FAW_OFST 4 |
| 56 | #define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_RRD_OFST 0 |
| 57 | #define AGX_MPFE_DDR_MAIN_SCHED_DDRCONF_SET(x) (((x) << 0) & 0x0000001f) |
| 58 | #define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTORD_OFST 0 |
| 59 | #define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTORD_MSK (BIT(0) | BIT(1)) |
| 60 | #define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTOWR_OFST 2 |
| 61 | #define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTOWR_MSK (BIT(2) | BIT(3)) |
| 62 | #define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSWRTORD_OFST 4 |
| 63 | #define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSWRTORD_MSK (BIT(4) | BIT(5)) |
| 64 | |
| 65 | #define AGX_MPFE_HMC_ADP(x) (0xf8011000 + (x)) |
| 66 | #define AGX_MPFE_HMC_ADP_HPSINTFCSEL 0xf8011210 |
| 67 | #define AGX_MPFE_HMC_ADP_DDRIOCTRL 0xf8011008 |
| 68 | #define HMC_ADP_DDRIOCTRL 0x8 |
| 69 | #define HMC_ADP_DDRIOCTRL_IO_SIZE(x) (((x) & 0x00000003) >> 0) |
| 70 | #define HMC_ADP_DDRIOCTRL_CTRL_BURST_LENGTH(x) (((x) & 0x00003e00) >> 9) |
| 71 | #define ADP_DRAMADDRWIDTH 0xe0 |
| 72 | |
| 73 | #define ACT_TO_ACT_DIFF_BANK(value) (((value) & 0x00fc0000) >> 18) |
| 74 | #define ACT_TO_ACT(value) (((value) & 0x0003f000) >> 12) |
| 75 | #define ACT_TO_RDWR(value) (((value) & 0x0000003f) >> 0) |
| 76 | #define ACT_TO_ACT(value) (((value) & 0x0003f000) >> 12) |
| 77 | |
| 78 | /* timing 2 */ |
| 79 | #define RD_TO_RD_DIFF_CHIP(value) (((value) & 0x00000fc0) >> 6) |
| 80 | #define RD_TO_WR_DIFF_CHIP(value) (((value) & 0x3f000000) >> 24) |
| 81 | #define RD_TO_WR(value) (((value) & 0x00fc0000) >> 18) |
| 82 | #define RD_TO_PCH(value) (((value) & 0x00000fc0) >> 6) |
| 83 | |
| 84 | /* timing 3 */ |
| 85 | #define CALTIMING3_WR_TO_RD_DIFF_CHIP(value) (((value) & 0x0003f000) >> 12) |
| 86 | #define CALTIMING3_WR_TO_RD(value) (((value) & 0x00000fc0) >> 6) |
| 87 | |
| 88 | /* timing 4 */ |
| 89 | #define PCH_TO_VALID(value) (((value) & 0x00000fc0) >> 6) |
| 90 | |
| 91 | #define DDRTIMING_BWRATIO_OFST 31 |
| 92 | #define DDRTIMING_WRTORD_OFST 26 |
| 93 | #define DDRTIMING_RDTOWR_OFST 21 |
| 94 | #define DDRTIMING_BURSTLEN_OFST 18 |
| 95 | #define DDRTIMING_WRTOMISS_OFST 12 |
| 96 | #define DDRTIMING_RDTOMISS_OFST 6 |
| 97 | #define DDRTIMING_ACTTOACT_OFST 0 |
| 98 | |
| 99 | #define ADP_DDRIOCTRL_IO_SIZE(x) (((x) & 0x3) >> 0) |
| 100 | |
| 101 | #define DDRMODE_AUTOPRECHARGE_OFST 1 |
| 102 | #define DDRMODE_BWRATIOEXTENDED_OFST 0 |
| 103 | |
| 104 | |
| 105 | #define AGX_MPFE_IOHMC_REG_DRAMTIMING0_CFG_TCL(x) (((x) & 0x7f) >> 0) |
| 106 | #define AGX_MPFE_IOHMC_REG_CTRLCFG0_CFG_MEM_TYPE(x) (((x) & 0x0f) >> 0) |
| 107 | |
| 108 | #define AGX_CCU_CPU0_MPRT_DDR 0xf7004400 |
| 109 | #define AGX_CCU_CPU0_MPRT_MEM0 0xf70045c0 |
| 110 | #define AGX_CCU_CPU0_MPRT_MEM1A 0xf70045e0 |
| 111 | #define AGX_CCU_CPU0_MPRT_MEM1B 0xf7004600 |
| 112 | #define AGX_CCU_CPU0_MPRT_MEM1C 0xf7004620 |
| 113 | #define AGX_CCU_CPU0_MPRT_MEM1D 0xf7004640 |
| 114 | #define AGX_CCU_CPU0_MPRT_MEM1E 0xf7004660 |
| 115 | #define AGX_CCU_IOM_MPRT_MEM0 0xf7018560 |
| 116 | #define AGX_CCU_IOM_MPRT_MEM1A 0xf7018580 |
| 117 | #define AGX_CCU_IOM_MPRT_MEM1B 0xf70185a0 |
| 118 | #define AGX_CCU_IOM_MPRT_MEM1C 0xf70185c0 |
| 119 | #define AGX_CCU_IOM_MPRT_MEM1D 0xf70185e0 |
| 120 | #define AGX_CCU_IOM_MPRT_MEM1E 0xf7018600 |
| 121 | |
| 122 | #define AGX_NOC_FW_DDR_SCR 0xf8020200 |
| 123 | #define AGX_NOC_FW_DDR_SCR_MPUREGION0ADDR_LIMITEXT 0xf802021c |
| 124 | #define AGX_NOC_FW_DDR_SCR_MPUREGION0ADDR_LIMIT 0xf8020218 |
| 125 | #define AGX_NOC_FW_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT 0xf802029c |
| 126 | #define AGX_NOC_FW_DDR_SCR_NONMPUREGION0ADDR_LIMIT 0xf8020298 |
| 127 | |
| 128 | #define AGX_SOC_NOC_FW_DDR_SCR_ENABLE 0xf8020200 |
Hadi Asyrafi | 83fe38e | 2019-08-08 18:52:31 +0800 | [diff] [blame] | 129 | #define AGX_SOC_NOC_FW_DDR_SCR_ENABLESET 0xf8020204 |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 130 | #define AGX_CCU_NOC_DI_SET_MSK 0x10 |
| 131 | |
| 132 | #define AGX_SYSMGR_CORE_HMC_CLK 0xffd120b4 |
| 133 | #define AGX_SYSMGR_CORE_HMC_CLK_STATUS 0x00000001 |
| 134 | |
| 135 | #define AGX_MPFE_IOHMC_NIOSRESERVE0_NIOS_RESERVE0(x) (((x) & 0xffff) >> 0) |
| 136 | #define AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE_MSK 0x00000003 |
| 137 | #define AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE_OFST 0 |
| 138 | #define AGX_MPFE_HMC_ADP_HPSINTFCSEL_ENABLE 0x001f1f1f |
| 139 | #define AGX_IOHMC_CTRLCFG1_ENABLE_ECC_OFST 7 |
| 140 | |
| 141 | #define AGX_MPFE_HMC_ADP_ECCCTRL1_AUTOWB_CNT_RST_SET_MSK 0x00010000 |
| 142 | #define AGX_MPFE_HMC_ADP_ECCCTRL1_CNT_RST_SET_MSK 0x00000100 |
| 143 | #define AGX_MPFE_HMC_ADP_ECCCTRL1_ECC_EN_SET_MSK 0x00000001 |
| 144 | |
| 145 | #define AGX_MPFE_HMC_ADP_ECCCTRL2_AUTOWB_EN_SET_MSK 0x00000001 |
| 146 | #define AGX_MPFE_HMC_ADP_ECCCTRL2_OVRW_RB_ECC_EN_SET_MSK 0x00010000 |
| 147 | #define AGX_MPFE_HMC_ADP_ECCCTRL2_RMW_EN_SET_MSK 0x00000100 |
| 148 | #define AGX_MPFE_HMC_ADP_DDRCALSTAT_CAL(value) (((value) & 0x1) >> 0) |
| 149 | |
| 150 | |
| 151 | #define AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE(x) (((x) & 0x00003) >> 0) |
| 152 | #define IOHMC_DRAMADDRW_CFG_BANK_ADDR_WIDTH(x) (((x) & 0x03c00) >> 10) |
| 153 | #define IOHMC_DRAMADDRW_CFG_BANK_GROUP_ADDR_WIDTH(x) (((x) & 0x0c000) >> 14) |
| 154 | #define IOHMC_DRAMADDRW_CFG_COL_ADDR_WIDTH(x) (((x) & 0x0001f) >> 0) |
| 155 | #define IOHMC_DRAMADDRW_CFG_CS_ADDR_WIDTH(x) (((x) & 0x70000) >> 16) |
| 156 | #define IOHMC_DRAMADDRW_CFG_ROW_ADDR_WIDTH(x) (((x) & 0x003e0) >> 5) |
| 157 | |
| 158 | #define AGX_SDRAM_0_LB_ADDR 0x0 |
Hadi Asyrafi | 83fe38e | 2019-08-08 18:52:31 +0800 | [diff] [blame] | 159 | #define AGX_DDR_SIZE 0x40000000 |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 160 | |
Jit Loon Lim | 86f6fb3 | 2023-05-17 12:26:11 +0800 | [diff] [blame^] | 161 | /* Macros */ |
| 162 | #define SOCFPGA_MEMCTRL_ECCCTRL1 0x008 |
| 163 | #define SOCFPGA_MEMCTRL_ERRINTEN 0x010 |
| 164 | #define SOCFPGA_MEMCTRL_ERRINTENS 0x014 |
| 165 | #define SOCFPGA_MEMCTRL_ERRINTENR 0x018 |
| 166 | #define SOCFPGA_MEMCTRL_INTMODE 0x01C |
| 167 | #define SOCFPGA_MEMCTRL_INTSTAT 0x020 |
| 168 | #define SOCFPGA_MEMCTRL_DIAGINTTEST 0x024 |
| 169 | #define SOCFPGA_MEMCTRL_DERRADDRA 0x02C |
| 170 | |
| 171 | #define SOCFPGA_MEMCTRL(_reg) (SOCFPGA_MEMCTRL_REG_BASE \ |
| 172 | + (SOCFPGA_MEMCTRL_##_reg)) |
| 173 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 174 | int init_hard_memory_controller(void); |
| 175 | |
| 176 | #endif |