Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/modules/hekate_libsys_minerva/mtc.h
1476 views
1
/*
2
* Minerva Training Cell
3
* DRAM Training for Tegra X1 SoC. Supports DDR2/3 and LPDDR3/4.
4
*
5
* Copyright (c) 2018-2022 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 MC_BASE 0x70019000
30
#define EMC_BASE 0x7001B000
31
#define EMC0_BASE 0x7001E000
32
#define EMC1_BASE 0x7001F000
33
34
#define MTC_INIT_MAGIC 0x3043544D
35
#define MTC_NEW_MAGIC 0x5243544D
36
37
#define _REG(base, off) *(vu32 *)((base) + (off))
38
39
#define TMR(off) _REG(TMR_BASE, off)
40
#define CLOCK(off) _REG(CLOCK_BASE, off)
41
#define MC(off) _REG(MC_BASE, off)
42
#define EMC(off) _REG(EMC_BASE, off)
43
#define EMC_CH0(off) _REG(EMC0_BASE, off)
44
#define EMC_CH1(off) _REG(EMC1_BASE, off)
45
/* End of addresses and access macros */
46
47
#define EMC_TABLE_ENTRY_SIZE_R7 4928
48
#define EMC_TABLE_ENTRY_SIZE_R3 4300
49
#define EMC_TABLE_SIZE_R7 (EMC_TABLE_ENTRY_SIZE_R7 * 7)
50
#define EMC_STATUS_UPDATE_TIMEOUT 1000
51
#define EMC_PERIODIC_TRAIN_MS 100
52
#define EMC_TEMP_COMP_MS 1000
53
54
/* Training types */
55
#define NEEDS_TRAINING_CA BIT(0)
56
#define NEEDS_TRAINING_CA_VREF BIT(1)
57
#define NEEDS_TRAINING_QUSE BIT(2)
58
#define NEEDS_TRAINING_QUSE_VREF BIT(3)
59
#define NEEDS_TRAINING_WR BIT(4)
60
#define NEEDS_TRAINING_WR_VREF BIT(5)
61
#define NEEDS_TRAINING_RD BIT(6)
62
#define NEEDS_TRAINING_RD_VREF BIT(7)
63
#define NEEDS_TRAINING_SWAP_RANK BIT(8)
64
#define NEEDS_TRAINING_IN_SELF_REFRESH BIT(9)
65
66
#define NEEDS_TRISTATE_TRAINING (NEEDS_TRAINING_CA | NEEDS_TRAINING_CA_VREF | \
67
NEEDS_TRAINING_QUSE | NEEDS_TRAINING_WR | \
68
NEEDS_TRAINING_WR_VREF | NEEDS_TRAINING_RD | \
69
NEEDS_TRAINING_RD_VREF)
70
#define NEEDS_TRAINING_CA_COMBO (NEEDS_TRAINING_CA | NEEDS_TRAINING_CA_VREF)
71
#define NEEDS_TRAINING_QUSE_COMBO (NEEDS_TRAINING_QUSE | NEEDS_TRAINING_QUSE_VREF)
72
#define NEEDS_TRAINING_WR_COMBO (NEEDS_TRAINING_WR | NEEDS_TRAINING_WR_VREF)
73
#define NEEDS_TRAINING_RD_COMBO (NEEDS_TRAINING_RD | NEEDS_TRAINING_RD_VREF)
74
75
typedef struct
76
{
77
u32 rate_to;
78
u32 rate_from;
79
emc_table_t *mtc_table;
80
u32 table_entries;
81
emc_table_t *current_emc_table;
82
u32 train_mode;
83
u32 sdram_id;
84
u32 prev_temp;
85
bool emc_2X_clk_src_is_pllmb;
86
bool fsp_for_src_freq;
87
bool train_ram_patterns;
88
u32 init_done;
89
} mtc_config_t;
90
91
enum train_mode_t
92
{
93
OP_SWITCH = 0,
94
OP_TRAIN = 1,
95
OP_TRAIN_SWITCH = 2,
96
OP_PERIODIC_TRAIN = 3,
97
OP_TEMP_COMP = 4
98
};
99
100
enum comp_seq_t
101
{
102
DVFS_SEQUENCE = 1,
103
WRITE_TRAINING_SEQUENCE = 2,
104
PERIODIC_TRAINING_SEQUENCE = 3
105
};
106
107
enum tree_update_mode_t
108
{
109
DVFS_PT1 = 10,
110
DVFS_UPDATE = 11,
111
TRAINING_PT1 = 12,
112
TRAINING_UPDATE = 13,
113
PERIODIC_TRAINING_UPDATE = 14
114
};
115
116
enum emc_channels
117
{
118
EMC_CHANNEL0 = 0,
119
EMC_CHANNEL1 = 1
120
};
121
122
enum EMC_2X_CLK_SRC
123
{
124
PLLM_OUT0 = 0x0,
125
PLLC_OUT0 = 0x1,
126
PLLP_OUT0 = 0x2,
127
CLK_M = 0x3,
128
PLLM_UD = 0x4,
129
PLLMB_UD = 0x5,
130
PLLMB_OUT0 = 0x6,
131
PLLP_UD = 0x7
132
};
133
134
enum DRAM_TYPE
135
{
136
DRAM_TYPE_DDR3 = 0,
137
DRAM_TYPE_LPDDR4 = 1,
138
DRAM_TYPE_LPDDR2 = 2,
139
DRAM_TYPE_DDR2 = 3
140
};
141
142
enum DRAM_DEV_NO
143
{
144
ONE_RANK = 1,
145
TWO_RANK = 2
146
};
147
148
enum DRAM_OVER_TEMP_REF
149
{
150
REFRESH_X2 = 1,
151
REFRESH_X4 = 2
152
};
153
154
/* Timers for the below two compensation functions should be paused when changing timings. */
155
156
/* Change refresh rate based on dram temps. Run every 1000ms. */
157
/* Timer should be run only when another component reports over temperature. */
158
void _minerva_do_over_temp_compensation(mtc_config_t *mtc_cfg);
159
160
/* Periodic compensation only for tight timings that need it. Run every 100ms. */
161
/* Over temp and periodic compensation, should not access EMC_MRR at the same time. */
162
u32 _minerva_do_periodic_compensation(emc_table_t *mtc_table_entry);
163
164
#endif
165
166