efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 14 | */ |
| 15 | |
Kyösti Mälkki | 526c2fb | 2014-07-10 22:16:58 +0300 | [diff] [blame] | 16 | #include "AGESA.h" |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 17 | #include "amdlib.h" |
Kyösti Mälkki | 6e74b2c | 2014-12-16 07:34:58 +0200 | [diff] [blame] | 18 | #include <northbridge/amd/agesa/agesawrapper.h> |
Kyösti Mälkki | 26f297e | 2014-05-26 11:27:54 +0300 | [diff] [blame] | 19 | #include <northbridge/amd/agesa/BiosCallOuts.h> |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 20 | #include "Ids.h" |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 21 | #include "heapManager.h" |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame] | 22 | #include <arch/io.h> |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame] | 23 | |
| 24 | #ifdef __PRE_RAM__ |
| 25 | /* These defines are used to select the appropriate socket for the SPD read |
| 26 | * because this is a multi-socket design. |
| 27 | */ |
| 28 | #define PCI_REG_GPIO_56_to_53_CNTRL (0x52) |
| 29 | #define GPIO_OUT_BIT_GPIO53 (BIT0) |
| 30 | #define GPIO_OUT_BIT_GPIO54 (BIT1) |
| 31 | #define GPIO_OUT_ENABLE_BIT_GPIO53 (BIT4) |
| 32 | #define GPIO_OUT_ENABLE_BIT_GPIO54 (BIT5) |
| 33 | |
| 34 | #define GPIO_OUT_BIT_GPIO54_to_53_MASK \ |
| 35 | (GPIO_OUT_BIT_GPIO54 | GPIO_OUT_BIT_GPIO53) |
| 36 | #define GPIO_OUT_ENABLE_BIT_GPIO54_to_53_MASK \ |
| 37 | (GPIO_OUT_ENABLE_BIT_GPIO54 | GPIO_OUT_ENABLE_BIT_GPIO53) |
| 38 | |
| 39 | static UINT8 select_socket(UINT8 socket_id) |
| 40 | { |
Antonello Dettori | 6fec83a | 2016-11-08 18:44:46 +0100 | [diff] [blame^] | 41 | pci_devfn_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBus |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame] | 42 | UINT8 value = 0; |
| 43 | UINT8 gpio56_to_53 = 0; |
| 44 | |
| 45 | /* Configure GPIO54,53 to select the desired socket |
| 46 | * GPIO54,53 control the HC4052 S1,S0 |
| 47 | * S1 S0 true table |
| 48 | * 0 0 channel 1 (Socket1) |
| 49 | * 0 1 channel 2 (Socket2) |
| 50 | * 1 0 channel 3 (Socket3) |
| 51 | * 1 1 channel 4 (Socket4) |
| 52 | */ |
| 53 | gpio56_to_53 = pci_read_config8(sm_dev, PCI_REG_GPIO_56_to_53_CNTRL); |
| 54 | value = gpio56_to_53 & (~GPIO_OUT_BIT_GPIO54_to_53_MASK); |
| 55 | value |= socket_id; |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 56 | value &= (~GPIO_OUT_ENABLE_BIT_GPIO54_to_53_MASK); // 0 = Output Enabled, 1 = Tristate |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame] | 57 | pci_write_config8(sm_dev, PCI_REG_GPIO_56_to_53_CNTRL, value); |
| 58 | |
| 59 | return gpio56_to_53; |
| 60 | } |
| 61 | |
| 62 | static void restore_socket(UINT8 original_value) |
| 63 | { |
Antonello Dettori | 6fec83a | 2016-11-08 18:44:46 +0100 | [diff] [blame^] | 64 | pci_devfn_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBus |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame] | 65 | pci_write_config8(sm_dev, PCI_REG_GPIO_56_to_53_CNTRL, original_value); |
| 66 | } |
| 67 | #endif |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 68 | |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 69 | static AGESA_STATUS board_ReadSpd (UINT32 Func, UINTN Data, VOID *ConfigPtr); |
Kyösti Mälkki | c009601 | 2014-05-05 18:56:33 +0300 | [diff] [blame] | 70 | |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 71 | #include <stdlib.h> |
| 72 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 73 | { |
Kyösti Mälkki | 5e19fa4 | 2014-05-04 23:13:54 +0300 | [diff] [blame] | 74 | {AGESA_DO_RESET, agesa_Reset }, |
Kyösti Mälkki | c009601 | 2014-05-05 18:56:33 +0300 | [diff] [blame] | 75 | {AGESA_READ_SPD, board_ReadSpd }, |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 76 | {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported }, |
Kyösti Mälkki | 6b4b151 | 2014-05-05 12:05:53 +0300 | [diff] [blame] | 77 | {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp }, |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 78 | {AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData }, |
| 79 | {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess }, |
| 80 | {AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopSuccess }, |
| 81 | {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess }, |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 82 | }; |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 83 | const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts); |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 84 | |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 85 | static AGESA_STATUS board_ReadSpd (UINT32 Func, UINTN Data, VOID *ConfigPtr) |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 86 | { |
| 87 | AGESA_STATUS Status; |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame] | 88 | #ifdef __PRE_RAM__ |
| 89 | UINT8 original_value = 0; |
| 90 | |
| 91 | if (ConfigPtr == NULL) |
| 92 | return AGESA_ERROR; |
| 93 | |
| 94 | original_value = select_socket(((AGESA_READ_SPD_PARAMS *)ConfigPtr)->SocketId); |
| 95 | |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 96 | Status = agesa_ReadSpd (Func, Data, ConfigPtr); |
Kimarie Hoot | eef45f9 | 2013-03-08 13:54:10 -0700 | [diff] [blame] | 97 | |
| 98 | restore_socket(original_value); |
| 99 | #else |
| 100 | Status = AGESA_UNSUPPORTED; |
| 101 | #endif |
efdesign98 | 95b6611 | 2011-07-20 13:23:04 -0600 | [diff] [blame] | 102 | |
| 103 | return Status; |
| 104 | } |