blob: c4fd253efd5bb757385514316a5561b40a022988 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -05002
Elyes HAOUASaa8e7e72016-06-19 12:38:47 +02003/*
4 * JEDEC Standard No. 21-C
5 * Annex K: Serial Presence Detect (SPD) for DDR3 SDRAM Modules 2014
6 * http://www.jedec.org/sites/default/files/docs/4_01_02_11R24.pdf
7 */
8
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -05009#ifndef DEVICE_DRAM_DDR3L_H
10#define DEVICE_DRAM_DDR3L_H
11
12/**
13 * @file ddr3.h
14 *
15 * \brief Utilities for decoding DDR3 SPDs
16 */
17
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050018#include <spd.h>
Arthur Heymansfc31e442018-02-12 15:12:34 +010019#include <device/dram/common.h>
Patrick Rudolph24efe732018-08-19 11:06:06 +020020#include <types.h>
Arthur Heymansfc31e442018-02-12 15:12:34 +010021
Martin Roth58964ff2023-10-23 09:59:09 -060022/** Maximum SPD size supported */
23#define SPD_SIZE_MAX_DDR3 256
24
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050025/**
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050026 * Convenience definitions for SPD offsets
27 *
28 * @{
29 */
Elyes Haouas8bcd8212024-05-06 11:48:41 +020030#define SPD_DDR3_MOD_ID1 117
31#define SPD_DDR3_MOD_ID2 118
32#define SPD_DDR3_SERIAL_NUM 122
33#define SPD_DDR3_SERIAL_LEN 4
34#define SPD_DDR3_PART_NUM 128
35#define SPD_DDR3_PART_LEN 18
Matt DeVillier5aaa8ce2016-09-02 13:29:17 -050036/** @} */
37
Elyes Haouasf82e68c2022-12-28 12:33:58 +010038/* Byte 3 [3:0]: DDR3 Module type information */
Angel Pons18571382021-03-28 13:49:39 +020039enum spd_dimm_type_ddr3 {
40 SPD_DDR3_DIMM_TYPE_UNDEFINED = 0x00,
41 SPD_DDR3_DIMM_TYPE_RDIMM = 0x01,
42 SPD_DDR3_DIMM_TYPE_UDIMM = 0x02,
43 SPD_DDR3_DIMM_TYPE_SO_DIMM = 0x03,
44 SPD_DDR3_DIMM_TYPE_MICRO_DIMM = 0x04,
45 SPD_DDR3_DIMM_TYPE_MINI_RDIMM = 0x05,
46 SPD_DDR3_DIMM_TYPE_MINI_UDIMM = 0x06,
47 SPD_DDR3_DIMM_TYPE_MINI_CDIMM = 0x07,
48 SPD_DDR3_DIMM_TYPE_72B_SO_UDIMM = 0x08,
49 SPD_DDR3_DIMM_TYPE_72B_SO_RDIMM = 0x09,
50 SPD_DDR3_DIMM_TYPE_72B_SO_CDIMM = 0x0a,
51 SPD_DDR3_DIMM_TYPE_LRDIMM = 0x0b,
52 SPD_DDR3_DIMM_TYPE_16B_SO_DIMM = 0x0c,
53 SPD_DDR3_DIMM_TYPE_32B_SO_DIMM = 0x0d,
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050054 /* Masks to bits 3:0 to give the dimm type */
Angel Pons18571382021-03-28 13:49:39 +020055 SPD_DDR3_DIMM_TYPE_MASK = 0x0f,
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050056};
57
58/**
59 * \brief DIMM flags
60 *
61 * Characteristic flags for the DIMM, as presented by the SPD
62 */
Angel Ponsafb3d7e2021-03-28 13:43:13 +020063union dimm_flags_ddr3_st {
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050064 /* The whole point of the union/struct construct is to allow us to clear
65 * all the bits with one line: flags.raw = 0.
66 * We do not care how these bits are ordered */
67 struct {
68 /* Indicates if rank 1 of DIMM uses a mirrored pin mapping. See:
69 * Annex K: Serial Presence Detect (SPD) for DDR3 SDRAM */
Lee Leahy0ca2a062017-03-06 18:01:04 -080070 unsigned int pins_mirrored:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050071 /* Module can work at 1.50V - All DIMMS must be 1.5V operable */
Lee Leahy0ca2a062017-03-06 18:01:04 -080072 unsigned int operable_1_50V:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050073 /* Module can work at 1.35V */
Lee Leahy0ca2a062017-03-06 18:01:04 -080074 unsigned int operable_1_35V:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050075 /* Module can work at 1.20V */
Lee Leahy0ca2a062017-03-06 18:01:04 -080076 unsigned int operable_1_25V:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050077 /* Has an 8-bit bus extension, meaning the DIMM supports ECC */
Lee Leahy0ca2a062017-03-06 18:01:04 -080078 unsigned int is_ecc:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050079 /* DLL-Off Mode Support */
Lee Leahy0ca2a062017-03-06 18:01:04 -080080 unsigned int dll_off_mode:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050081 /* Indicates a drive strength of RZQ/6 (40 Ohm) is supported */
Lee Leahy0ca2a062017-03-06 18:01:04 -080082 unsigned int rzq6_supported:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050083 /* Indicates a drive strength of RZQ/7 (35 Ohm) is supported */
Lee Leahy0ca2a062017-03-06 18:01:04 -080084 unsigned int rzq7_supported:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050085 /* Partial Array Self Refresh */
Lee Leahy0ca2a062017-03-06 18:01:04 -080086 unsigned int pasr:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050087 /* On-die Thermal Sensor Readout */
Lee Leahy0ca2a062017-03-06 18:01:04 -080088 unsigned int odts:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050089 /* Auto Self Refresh */
Lee Leahy0ca2a062017-03-06 18:01:04 -080090 unsigned int asr:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050091 /* Extended temperature range supported */
Lee Leahy0ca2a062017-03-06 18:01:04 -080092 unsigned int ext_temp_range:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050093 /* Operating at extended temperature requires 2X refresh rate */
Lee Leahy0ca2a062017-03-06 18:01:04 -080094 unsigned int ext_temp_refresh:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050095 /* Thermal sensor incorporated */
Lee Leahy0ca2a062017-03-06 18:01:04 -080096 unsigned int therm_sensor:1;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -050097 };
Lee Leahy0ca2a062017-03-06 18:01:04 -080098 unsigned int raw;
Angel Ponsafb3d7e2021-03-28 13:43:13 +020099};
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500100
101/**
102 * \brief DIMM characteristics
103 *
104 * The characteristics of each DIMM, as presented by the SPD
105 */
Angel Ponsafb3d7e2021-03-28 13:43:13 +0200106struct dimm_attr_ddr3_st {
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500107 enum spd_memory_type dram_type;
Angel Pons18571382021-03-28 13:49:39 +0200108 enum spd_dimm_type_ddr3 dimm_type;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500109 u16 cas_supported;
110 /* Flags extracted from SPD */
Angel Ponsafb3d7e2021-03-28 13:43:13 +0200111 union dimm_flags_ddr3_st flags;
Vladimir Serbinenko7686a562014-05-18 11:05:56 +0200112 /* SDRAM width */
113 u8 width;
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500114 /* Number of ranks */
115 u8 ranks;
116 /* Number or row address bits */
117 u8 row_bits;
118 /* Number or column address bits */
119 u8 col_bits;
120 /* Size of module in MiB */
121 u32 size_mb;
122 /* Latencies are in units of 1/256 ns */
123 u32 tCK;
124 u32 tAA;
125 u32 tWR;
126 u32 tRCD;
127 u32 tRRD;
128 u32 tRP;
129 u32 tRAS;
130 u32 tRC;
131 u32 tRFC;
132 u32 tWTR;
133 u32 tRTP;
134 u32 tFAW;
Dan Elkouby0c024202018-04-13 18:45:02 +0300135 u32 tCWL;
136 u16 tCMD;
Vladimir Serbinenko7686a562014-05-18 11:05:56 +0200137
138 u8 reference_card;
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100139 /* XMP: Module voltage in mV */
140 u16 voltage;
141 /* XMP: max DIMMs per channel supported (1-4) */
142 u8 dimms_per_channel;
Patrick Rudolph07691592016-02-29 18:21:00 +0100143 /* Manufacturer ID */
144 u16 manufacturer_id;
145 /* ASCII part number - NULL terminated */
146 u8 part_number[17];
Patrick Rudolph15e64692018-08-17 15:24:56 +0200147 /* Serial number */
Elyes Haouas8bcd8212024-05-06 11:48:41 +0200148 u8 serial[SPD_DDR3_SERIAL_LEN];
Angel Ponsafb3d7e2021-03-28 13:43:13 +0200149};
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500150
Patrick Rudolphbd1fdc62016-01-26 08:45:21 +0100151enum ddr3_xmp_profile {
152 DDR3_XMP_PROFILE_1 = 0,
153 DDR3_XMP_PROFILE_2 = 1,
154};
155
Elyes Haouas78ba7a72024-05-06 05:11:28 +0200156typedef u8 spd_ddr3_raw_data[SPD_SIZE_MAX_DDR3];
Alexandru Gagniucf97ff3f2013-05-21 14:43:45 -0500157
Alexandru Gagniuc4c37e582013-12-17 13:08:01 -0500158u16 spd_ddr3_calc_crc(u8 *spd, int len);
Kyösti Mälkki7dc4b842016-11-18 18:41:17 +0200159u16 spd_ddr3_calc_unique_crc(u8 *spd, int len);
Elyes Haouas78ba7a72024-05-06 05:11:28 +0200160int spd_decode_ddr3(struct dimm_attr_ddr3_st *dimm, spd_ddr3_raw_data spd_data);
Angel Pons18571382021-03-28 13:49:39 +0200161int spd_dimm_is_registered_ddr3(enum spd_dimm_type_ddr3 type);
Angel Ponsafb3d7e2021-03-28 13:43:13 +0200162void dram_print_spd_ddr3(const struct dimm_attr_ddr3_st *dimm);
163int spd_xmp_decode_ddr3(struct dimm_attr_ddr3_st *dimm,
Elyes Haouas78ba7a72024-05-06 05:11:28 +0200164 spd_ddr3_raw_data spd,
Lee Leahy708fc272017-03-07 12:18:53 -0800165 enum ddr3_xmp_profile profile);
Patrick Rudolph24efe732018-08-19 11:06:06 +0200166enum cb_err spd_add_smbios17(const u8 channel, const u8 slot,
167 const u16 selected_freq,
Angel Ponsafb3d7e2021-03-28 13:43:13 +0200168 const struct dimm_attr_ddr3_st *info);
Alexandru Gagniuc78706fd2013-06-03 13:58:10 -0500169
Martin Rothfd277d82016-01-11 12:47:30 -0700170#endif /* DEVICE_DRAM_DDR3L_H */