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>
9 enum ddr5_speed_grade
{
26 struct ddr5_speed_attr
{
27 uint32_t min_clock_mhz
; // inclusive
28 uint32_t max_clock_mhz
; // inclusive
29 uint32_t reported_mts
;
33 * (LP)DDR5 speed attributes derived from JEDEC JESD79-5B, JESD209-5B and industry norms
35 * min_clock_mhz = previous max speed + 1
36 * max_clock_mhz = 50% of speed grade, +/- 1
37 * reported_mts = Standard reported DDR5 speed in MT/s
38 * May be slightly less than the actual max MT/s
40 static const struct ddr5_speed_attr ddr5_speeds
[] = {
58 .max_clock_mhz
= 1067,
62 .min_clock_mhz
= 1068,
63 .max_clock_mhz
= 1200,
67 .min_clock_mhz
= 1201,
68 .max_clock_mhz
= 1333,
72 .min_clock_mhz
= 1334,
73 .max_clock_mhz
= 1467,
77 .min_clock_mhz
= 1468,
78 .max_clock_mhz
= 1600,
82 .min_clock_mhz
= 1601,
83 .max_clock_mhz
= 1866,
87 .min_clock_mhz
= 1867,
88 .max_clock_mhz
= 2133,
92 .min_clock_mhz
= 2134,
93 .max_clock_mhz
= 2400,
97 .min_clock_mhz
= 2401,
98 .max_clock_mhz
= 2750,
102 .min_clock_mhz
= 2751,
103 .max_clock_mhz
= 3000,
107 .min_clock_mhz
= 3001,
108 .max_clock_mhz
= 3200,
114 * Converts DDR5 clock speed in MHz to the standard reported speed in MT/s
116 uint16_t ddr5_speed_mhz_to_reported_mts(uint16_t speed_mhz
)
118 for (enum ddr5_speed_grade speed
= 0; speed
< ARRAY_SIZE(ddr5_speeds
); speed
++) {
119 const struct ddr5_speed_attr
*speed_attr
= &ddr5_speeds
[speed
];
120 if (speed_mhz
>= speed_attr
->min_clock_mhz
&&
121 speed_mhz
<= speed_attr
->max_clock_mhz
) {
122 return speed_attr
->reported_mts
;
125 printk(BIOS_ERR
, "DDR5 speed of %d MHz is out of range\n", speed_mhz
);