blob: 0fa9742fc0b99134a499d1133f498e1dfa642042 [file] [log] [blame]
Siyuan Wang1ee8b452012-09-07 19:20:02 +08001/*
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.
Siyuan Wang1ee8b452012-09-07 19:20:02 +080014 */
15
Kyösti Mälkki526c2fb2014-07-10 22:16:58 +030016#include "AGESA.h"
Siyuan Wang1ee8b452012-09-07 19:20:02 +080017#include "amdlib.h"
Kyösti Mälkki6e74b2c2014-12-16 07:34:58 +020018#include <northbridge/amd/agesa/agesawrapper.h>
Kyösti Mälkki26f297e2014-05-26 11:27:54 +030019#include <northbridge/amd/agesa/BiosCallOuts.h>
Siyuan Wang1ee8b452012-09-07 19:20:02 +080020#include "Ids.h"
Siyuan Wang1ee8b452012-09-07 19:20:02 +080021#include "heapManager.h"
Kimarie Hootb37ec542013-03-08 15:31:49 -070022#include <arch/io.h>
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030023#include <stdlib.h>
Kimarie Hootb37ec542013-03-08 15:31:49 -070024
25#ifdef __PRE_RAM__
26/* These defines are used to select the appropriate socket for the SPD read
27 * because this is a multi-socket design.
28 */
29#define PCI_REG_GPIO_48_47_46_37_CNTRL (0xA6)
30#define PCI_REG_GPIO_52_to_49_CNTRL (0x50)
31#define GPIO_OUT_BIT_GPIO48 (BIT3)
32#define GPIO_OUT_BIT_GPIO49 (BIT0)
33#define GPIO_OUT_ENABLE_BIT_GPIO48 (BIT7)
34#define GPIO_OUT_ENABLE_BIT_GPIO49 (BIT4)
35
36static UINT8 select_socket(UINT8 socket_id)
37{
38 device_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBUS
39 UINT8 value = 0;
40 UINT8 gpio52_to_49 = 0;
41
42 /* Configure GPIO49,48 to select the desired socket
43 * GPIO49,48 control the IDTQS3253 S1,S0
44 * S1 S0 true table
45 * 0 0 channel 0
46 * 0 1 channel 1
47 * 1 0 channel 2 - Socket 0
48 * 1 1 channel 3 - Socket 1
49 * Note: Above is abstracted from Schematic. But actually it seems to be other way.
50 * 1 0 channel 2 - Socket 1
51 * 1 1 channel 3 - Socket 0
52 * Note: The DIMMs need to be plugged in from the farthest slot for each channel.
53 */
54 gpio52_to_49 = pci_read_config8(sm_dev, PCI_REG_GPIO_52_to_49_CNTRL);
55 value = gpio52_to_49 | GPIO_OUT_BIT_GPIO49; // Output of GPIO49 is always forced to "1"
56 value &= ~(GPIO_OUT_ENABLE_BIT_GPIO49); // 0=Output Enabled, 1=Tristate
57 pci_write_config8(sm_dev, PCI_REG_GPIO_52_to_49_CNTRL, value);
58
59 value = pci_read_config8(sm_dev, PCI_REG_GPIO_48_47_46_37_CNTRL);
60 value &= ~(GPIO_OUT_BIT_GPIO48);
61 value |= (~(socket_id & 1)) << 3; // Output of GPIO48 is inverse of SocketId
62 value &= ~(GPIO_OUT_ENABLE_BIT_GPIO48); // 0=Output Enabled, 1=Tristate
63 pci_write_config8(sm_dev, PCI_REG_GPIO_48_47_46_37_CNTRL, value);
64
65 return gpio52_to_49;
66}
67
68static void restore_socket(UINT8 original_value)
69{
70 device_t sm_dev = PCI_DEV(0, 0x14, 0); //SMBUS
71 pci_write_config8(sm_dev, PCI_REG_GPIO_52_to_49_CNTRL, original_value);
72
73 // TODO: Restore previous GPIO48 configurations?
74 //pci_write_config8(sm_dev, PCI_REG_GPIO_48_47_46_37_CNTRL, gpio48_47_46_37_save);
75}
76#endif
Siyuan Wang1ee8b452012-09-07 19:20:02 +080077
Stefan Reinauerdd132a52015-07-30 11:16:37 -070078static AGESA_STATUS board_ReadSpd (UINT32 Func, UINTN Data, VOID *ConfigPtr);
Kyösti Mälkkic0096012014-05-05 18:56:33 +030079
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030080const BIOS_CALLOUT_STRUCT BiosCallouts[] =
Siyuan Wang1ee8b452012-09-07 19:20:02 +080081{
Kyösti Mälkki5e19fa42014-05-04 23:13:54 +030082 {AGESA_DO_RESET, agesa_Reset },
Kyösti Mälkkic0096012014-05-05 18:56:33 +030083 {AGESA_READ_SPD, board_ReadSpd },
Kyösti Mälkkic459f962014-05-04 17:07:45 +030084 {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
Kyösti Mälkki6b4b1512014-05-05 12:05:53 +030085 {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
Kyösti Mälkkic459f962014-05-04 17:07:45 +030086 {AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
87 {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess },
88 {AGESA_HOOKBEFORE_DRAM_INIT, agesa_NoopSuccess },
89 {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess },
Siyuan Wang1ee8b452012-09-07 19:20:02 +080090};
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030091const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
Siyuan Wang1ee8b452012-09-07 19:20:02 +080092
Stefan Reinauerdd132a52015-07-30 11:16:37 -070093static AGESA_STATUS board_ReadSpd (UINT32 Func, UINTN Data, VOID *ConfigPtr)
Siyuan Wang1ee8b452012-09-07 19:20:02 +080094{
95 AGESA_STATUS Status;
Kimarie Hootb37ec542013-03-08 15:31:49 -070096#ifdef __PRE_RAM__
97 UINT8 original_value = 0;
98
99 if (ConfigPtr == NULL)
100 return AGESA_ERROR;
101
102 original_value = select_socket(((AGESA_READ_SPD_PARAMS *)ConfigPtr)->SocketId);
103
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +0300104 Status = agesa_ReadSpd (Func, Data, ConfigPtr);
Kimarie Hootb37ec542013-03-08 15:31:49 -0700105
106 restore_socket(original_value);
107#else
108 Status = AGESA_UNSUPPORTED;
109#endif
Siyuan Wang1ee8b452012-09-07 19:20:02 +0800110
111 return Status;
112}