Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/modules/hekate_libsys_minerva/mtc.h
3694 views
1
/*
2
* Minerva Training Cell
3
* DRAM Training for Tegra X1 SoC. Supports LPDDR4.
4
*
5
* Copyright (c) 2018-2025 CTCaer <[email protected]>
6
*
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms and conditions of the GNU General Public License,
9
* version 2, as published by the Free Software Foundation.
10
*
11
* This program is distributed in the hope it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
* more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef _MTC_H_
21
#define _MTC_H_
22
23
#include "mtc_table.h"
24
#include "types.h"
25
26
/* Address bases and access macros - Change these for mapped access */
27
#define TMR_BASE 0x60005000
28
#define CLOCK_BASE 0x60006000
29
#define APB_MISC_BASE 0x70000000
30
#define FUSE_BASE 0x7000F800
31
#define MC_BASE 0x70019000
32
#define EMC_BASE 0x7001B000
33
#define EMC0_BASE 0x7001E000
34
#define EMC1_BASE 0x7001F000
35
36
#define MTC_INIT_MAGIC 0x3043544D
37
#define MTC_NEW_MAGIC 0x5243544D
38
#define MTC_IRB_MAGIC 0x4943544D
39
40
#define MTC_INIT_FREQUENCY 204000
41
42
#define _REG(base, off) *(vu32 *)((base) + (off))
43
44
#define TMR(off) _REG(TMR_BASE, off)
45
#define CLOCK(off) _REG(CLOCK_BASE, off)
46
#define APB_MISC(off) _REG(APB_MISC_BASE, off)
47
#define FUSE(off) _REG(FUSE_BASE, off)
48
#define MC(off) _REG(MC_BASE, off)
49
#define EMC(off) _REG(EMC_BASE, off)
50
#define EMC_CH0(off) _REG(EMC0_BASE, off)
51
#define EMC_CH1(off) _REG(EMC1_BASE, off)
52
/* End of addresses and access macros */
53
54
#define EMC_TABLE_ENTRY_SIZE_R7 4928
55
#define EMC_TABLE_ENTRY_SIZE_R3 4300
56
#define EMC_TABLE_SIZE_ODINX02_R7 (EMC_TABLE_ENTRY_SIZE_R7 * 7)
57
58
#define EMC_STATUS_UPDATE_TIMEOUT 2000
59
#define EMC_PERIODIC_TRAIN_MS 100
60
#define EMC_TEMP_COMP_MS 1000
61
62
/* Training types */
63
#define NEEDS_TRAINING_CA BIT(0)
64
#define NEEDS_TRAINING_CA_VREF BIT(1)
65
#define NEEDS_TRAINING_QUSE BIT(2)
66
#define NEEDS_TRAINING_QUSE_VREF BIT(3)
67
#define NEEDS_TRAINING_WR BIT(4)
68
#define NEEDS_TRAINING_WR_VREF BIT(5)
69
#define NEEDS_TRAINING_RD BIT(6)
70
#define NEEDS_TRAINING_RD_VREF BIT(7)
71
#define NEEDS_TRAINING_SWAP_RANK BIT(8)
72
#define NEEDS_TRAINING_IN_SELF_REFRESH BIT(9)
73
74
#define NEEDS_TRAINING (NEEDS_TRAINING_CA | NEEDS_TRAINING_CA_VREF | \
75
NEEDS_TRAINING_QUSE | NEEDS_TRAINING_WR | \
76
NEEDS_TRAINING_WR_VREF | NEEDS_TRAINING_RD | \
77
NEEDS_TRAINING_RD_VREF)
78
#define NEEDS_TRAINING_CA_COMBO (NEEDS_TRAINING_CA | NEEDS_TRAINING_CA_VREF)
79
#define NEEDS_TRAINING_QUSE_COMBO (NEEDS_TRAINING_QUSE | NEEDS_TRAINING_QUSE_VREF)
80
#define NEEDS_TRAINING_WR_COMBO (NEEDS_TRAINING_WR | NEEDS_TRAINING_WR_VREF)
81
#define NEEDS_TRAINING_RD_COMBO (NEEDS_TRAINING_RD | NEEDS_TRAINING_RD_VREF)
82
83
typedef struct
84
{
85
u32 rate_to;
86
u32 rate_from;
87
emc_table_t *mtc_table;
88
u32 table_entries;
89
emc_table_t *current_emc_table;
90
u32 train_mode;
91
u32 sdram_id;
92
u32 prev_temp;
93
bool emc_2X_clk_src_is_pllmb;
94
bool fsp_for_src_freq;
95
bool train_ram_patterns;
96
u32 init_done;
97
} mtc_config_t;
98
99
enum train_mode_t
100
{
101
OP_SWITCH = 0,
102
OP_TRAIN = 1,
103
OP_TRAIN_SWITCH = 2,
104
OP_PERIODIC_TRAIN = 3,
105
OP_TEMP_COMP = 4
106
};
107
108
enum comp_seq_t
109
{
110
DVFS_SEQUENCE = 1,
111
WRITE_TRAINING_SEQUENCE = 2,
112
PERIODIC_TRAINING_SEQUENCE = 3
113
};
114
115
enum tree_update_mode_t
116
{
117
DVFS_PT1 = 10,
118
DVFS_UPDATE = 11,
119
TRAINING_PT1 = 12,
120
TRAINING_UPDATE = 13,
121
PERIODIC_TRAINING_UPDATE = 14
122
};
123
124
enum emc_channels
125
{
126
EMC_CHANNEL0 = 0,
127
EMC_CHANNEL1 = 1
128
};
129
130
enum EMC_2X_CLK_SRC
131
{
132
PLLM_OUT0 = 0x0,
133
PLLC_OUT0 = 0x1,
134
PLLP_OUT0 = 0x2,
135
CLK_M = 0x3,
136
PLLM_UD = 0x4,
137
PLLMB_UD = 0x5,
138
PLLMB_OUT0 = 0x6,
139
PLLP_UD = 0x7
140
};
141
142
enum DRAM_TYPE
143
{
144
DRAM_TYPE_DDR3 = 0,
145
DRAM_TYPE_LPDDR4 = 1,
146
DRAM_TYPE_LPDDR2 = 2,
147
DRAM_TYPE_DDR2 = 3
148
};
149
150
enum DRAM_DEV_NO
151
{
152
ONE_RANK = 1,
153
TWO_RANK = 2
154
};
155
156
enum DRAM_OVER_TEMP_REF
157
{
158
REFRESH_X2 = 1,
159
REFRESH_X4 = 2
160
};
161
162
/* Timers for the below two compensation functions should be paused when changing timings. */
163
164
/* Change refresh rate based on dram temps. Run every 1000ms. */
165
/* Timer should be run only when another component reports over temperature. */
166
void _minerva_do_over_temp_compensation(mtc_config_t *mtc_cfg);
167
168
/* Periodic compensation only for tight timings that need it. Run every 100ms. */
169
/* Over temp and periodic compensation, should not access EMC_MRR at the same time. */
170
u32 _minerva_do_periodic_compensation(emc_table_t *mtc_table_entry);
171
172
#endif
173
174