Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 2 | |
| 3 | #include <device/pci_def.h> |
| 4 | #include <device/device.h> |
Elyes HAOUAS | 3b3d085 | 2021-02-01 10:09:40 +0100 | [diff] [blame] | 5 | #include <OEM.h> |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 6 | |
| 7 | /* warning: Porting.h includes an open #pragma pack(1) */ |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 8 | #include <Porting.h> |
| 9 | #include <AGESA.h> |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 10 | #include "chip.h" |
| 11 | |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 12 | #include <northbridge/amd/agesa/dimmSpd.h> |
| 13 | |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 14 | /** |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 15 | * Gets the SMBus address for an SPD from the array in devicetree.cb |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 16 | * then read the SPD into the supplied buffer. |
| 17 | */ |
Elyes Haouas | f63edd9 | 2022-07-16 09:36:50 +0200 | [diff] [blame^] | 18 | AGESA_STATUS AmdMemoryReadSPD(UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info) |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 19 | { |
| 20 | UINT8 spdAddress; |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 21 | |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 22 | DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2); |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 23 | if (dev == NULL) |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 24 | return AGESA_ERROR; |
| 25 | |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 26 | DEVTREE_CONST struct northbridge_amd_agesa_family14_config *config = dev->chip_info; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 27 | if (config == NULL) |
| 28 | return AGESA_ERROR; |
| 29 | |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 30 | if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup)) |
| 31 | return AGESA_ERROR; |
| 32 | if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0])) |
| 33 | return AGESA_ERROR; |
| 34 | if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0])) |
| 35 | return AGESA_ERROR; |
| 36 | |
| 37 | spdAddress = config->spdAddrLookup |
| 38 | [info->SocketId][info->MemChannelId][info->DimmId]; |
| 39 | |
| 40 | if (spdAddress == 0) |
| 41 | return AGESA_ERROR; |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 42 | |
Elyes Haouas | f63edd9 | 2022-07-16 09:36:50 +0200 | [diff] [blame^] | 43 | int err = smbus_readSpd(spdAddress, (void *)info->Buffer, DDR3_SPD_SIZE); |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 44 | if (err) |
| 45 | return AGESA_ERROR; |
| 46 | return AGESA_SUCCESS; |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 47 | } |