1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/dram/ddr5.h>
6 #include <memory_info.h>
10 enum ddr5_speed_grade
{
27 struct ddr5_speed_attr
{
28 uint32_t min_clock_mhz
; // inclusive
29 uint32_t max_clock_mhz
; // inclusive
30 uint32_t reported_mts
;
34 * (LP)DDR5 speed attributes derived from JEDEC JESD79-5B, JESD209-5B and industry norms
36 * min_clock_mhz = previous max speed + 1
37 * max_clock_mhz = 50% of speed grade, +/- 1
38 * reported_mts = Standard reported DDR5 speed in MT/s
39 * May be slightly less than the actual max MT/s
41 static const struct ddr5_speed_attr ddr5_speeds
[] = {
59 .max_clock_mhz
= 1067,
63 .min_clock_mhz
= 1068,
64 .max_clock_mhz
= 1200,
68 .min_clock_mhz
= 1201,
69 .max_clock_mhz
= 1333,
73 .min_clock_mhz
= 1334,
74 .max_clock_mhz
= 1467,
78 .min_clock_mhz
= 1468,
79 .max_clock_mhz
= 1600,
83 .min_clock_mhz
= 1601,
84 .max_clock_mhz
= 1866,
88 .min_clock_mhz
= 1867,
89 .max_clock_mhz
= 2133,
93 .min_clock_mhz
= 2134,
94 .max_clock_mhz
= 2400,
98 .min_clock_mhz
= 2401,
99 .max_clock_mhz
= 2750,
103 .min_clock_mhz
= 2751,
104 .max_clock_mhz
= 3000,
108 .min_clock_mhz
= 3001,
109 .max_clock_mhz
= 3200,
115 * Converts DDR5 clock speed in MHz to the standard reported speed in MT/s
117 uint16_t ddr5_speed_mhz_to_reported_mts(uint16_t speed_mhz
)
119 for (enum ddr5_speed_grade speed
= 0; speed
< ARRAY_SIZE(ddr5_speeds
); speed
++) {
120 const struct ddr5_speed_attr
*speed_attr
= &ddr5_speeds
[speed
];
121 if (speed_mhz
>= speed_attr
->min_clock_mhz
&&
122 speed_mhz
<= speed_attr
->max_clock_mhz
) {
123 return speed_attr
->reported_mts
;
126 printk(BIOS_ERR
, "DDR5 speed of %d MHz is out of range\n", speed_mhz
);