1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* SPDX-License-Identifier: GPL-2.0-only */
#include <console/console.h>
#include <device/device.h>
#include <device/dram/ddr5.h>
#include <memory_info.h>
#include <types.h>
enum ddr5_speed_grade {
DDR5_1333,
DDR5_1600,
DDR5_1866,
DDR5_2133,
DDR5_2400,
DDR5_2667,
DDR5_2933,
DDR5_3200,
DDR5_3733,
DDR5_4267,
DDR5_4800,
DDR5_5500,
DDR5_6000,
DDR5_6400,
};
struct ddr5_speed_attr {
uint32_t min_clock_mhz; // inclusive
uint32_t max_clock_mhz; // inclusive
uint32_t reported_mts;
};
/**
* (LP)DDR5 speed attributes derived from JEDEC JESD79-5B, JESD209-5B and industry norms
*
* min_clock_mhz = previous max speed + 1
* max_clock_mhz = 50% of speed grade, +/- 1
* reported_mts = Standard reported DDR5 speed in MT/s
* May be slightly less than the actual max MT/s
*/
static const struct ddr5_speed_attr ddr5_speeds[] = {
[DDR5_1333] = {
.min_clock_mhz = 10,
.max_clock_mhz = 667,
.reported_mts = 1333,
},
[DDR5_1600] = {
.min_clock_mhz = 668,
.max_clock_mhz = 800,
.reported_mts = 1600,
},
[DDR5_1866] = {
.min_clock_mhz = 801,
.max_clock_mhz = 933,
.reported_mts = 1866,
},
[DDR5_2133] = {
.min_clock_mhz = 934,
.max_clock_mhz = 1067,
.reported_mts = 2133,
},
[DDR5_2400] = {
.min_clock_mhz = 1068,
.max_clock_mhz = 1200,
.reported_mts = 2400,
},
[DDR5_2667] = {
.min_clock_mhz = 1201,
.max_clock_mhz = 1333,
.reported_mts = 2667,
},
[DDR5_2933] = {
.min_clock_mhz = 1334,
.max_clock_mhz = 1467,
.reported_mts = 2933,
},
[DDR5_3200] = {
.min_clock_mhz = 1468,
.max_clock_mhz = 1600,
.reported_mts = 3200,
},
[DDR5_3733] = {
.min_clock_mhz = 1601,
.max_clock_mhz = 1866,
.reported_mts = 3733
},
[DDR5_4267] = {
.min_clock_mhz = 1867,
.max_clock_mhz = 2133,
.reported_mts = 4267
},
[DDR5_4800] = {
.min_clock_mhz = 2134,
.max_clock_mhz = 2400,
.reported_mts = 4800
},
[DDR5_5500] = {
.min_clock_mhz = 2401,
.max_clock_mhz = 2750,
.reported_mts = 5500
},
[DDR5_6000] = {
.min_clock_mhz = 2751,
.max_clock_mhz = 3000,
.reported_mts = 6000
},
[DDR5_6400] = {
.min_clock_mhz = 3001,
.max_clock_mhz = 3200,
.reported_mts = 6400
},
};
/**
* Converts DDR5 clock speed in MHz to the standard reported speed in MT/s
*/
uint16_t ddr5_speed_mhz_to_reported_mts(uint16_t speed_mhz)
{
for (enum ddr5_speed_grade speed = 0; speed < ARRAY_SIZE(ddr5_speeds); speed++) {
const struct ddr5_speed_attr *speed_attr = &ddr5_speeds[speed];
if (speed_mhz >= speed_attr->min_clock_mhz &&
speed_mhz <= speed_attr->max_clock_mhz) {
return speed_attr->reported_mts;
}
}
printk(BIOS_ERR, "DDR5 speed of %d MHz is out of range\n", speed_mhz);
return 0;
}
|