[coreboot-gerrit] Patch set updated for coreboot: 3e609b5 AGESA fam15tn fam16kb 00730f01: Add common agesa_readSpd()

Kyösti Mälkki (kyosti.malkki@gmail.com) gerrit at coreboot.org
Sat Oct 18 08:33:00 CEST 2014


Kyösti Mälkki (kyosti.malkki at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/7112

-gerrit

commit 3e609b5428e636734d92e8fc60ee1f1e4e4cd24d
Author: Kyösti Mälkki <kyosti.malkki at gmail.com>
Date:   Fri Oct 17 22:33:22 2014 +0300

    AGESA fam15tn fam16kb 00730f01: Add common agesa_readSpd()
    
    Remove northbridge specific callouts for AGESA_READ_SPD.
    
    Move low-level SMBus code to southbridge.
    
    Change-Id: I3e272389e2a7db542fb48fca8606325af27b65a5
    Signed-off-by: Kyösti Mälkki <kyosti.malkki at gmail.com>
---
 src/mainboard/amd/olivehill/BiosCallOuts.c         |   2 +-
 src/mainboard/amd/olivehillplus/BiosCallOuts.c     |   2 +-
 src/mainboard/amd/parmer/BiosCallOuts.c            |   2 +-
 src/mainboard/amd/thatcher/BiosCallOuts.c          |   2 +-
 src/mainboard/asrock/imb-a180/BiosCallOuts.c       |   2 +-
 src/mainboard/asus/f2a85-m/BiosCallOuts.c          |   2 +-
 src/mainboard/hp/pavilion_m6_1035dx/BiosCallOuts.c |   2 +-
 src/northbridge/amd/agesa/00730F01/Makefile.inc    |   1 -
 .../amd/agesa/00730F01/callouts_for_00730F01.c     |   8 --
 .../amd/agesa/00730F01/callouts_for_00730F01.h     |   1 -
 src/northbridge/amd/agesa/00730F01/dimmSpd.c       | 132 ++----------------
 src/northbridge/amd/agesa/00730F01/dimmSpd.h       |  26 ----
 src/northbridge/amd/agesa/def_callouts.c           |  10 ++
 src/northbridge/amd/agesa/def_callouts.h           |   1 +
 src/northbridge/amd/agesa/dimmSpd.h                |  30 ++++
 src/northbridge/amd/agesa/family15tn/Makefile.inc  |   1 -
 src/northbridge/amd/agesa/family15tn/dimmSpd.c     | 119 ++--------------
 src/northbridge/amd/agesa/family15tn/dimmSpd.h     |  56 --------
 .../amd/agesa/family15tn/fam15tn_callouts.c        |   9 --
 .../amd/agesa/family15tn/fam15tn_callouts.h        |   2 -
 src/northbridge/amd/agesa/family16kb/Makefile.inc  |   1 -
 src/northbridge/amd/agesa/family16kb/dimmSpd.c     | 119 ++--------------
 src/northbridge/amd/agesa/family16kb/dimmSpd.h     |  56 --------
 .../amd/agesa/family16kb/fam16kb_callouts.c        |   8 --
 .../amd/agesa/family16kb/fam16kb_callouts.h        |   2 -
 src/southbridge/amd/agesa/hudson/Makefile.inc      |   2 +-
 src/southbridge/amd/agesa/hudson/smbus_spd.c       | 152 +++++++++++++++++++++
 27 files changed, 228 insertions(+), 522 deletions(-)

diff --git a/src/mainboard/amd/olivehill/BiosCallOuts.c b/src/mainboard/amd/olivehill/BiosCallOuts.c
index 09e4169..bb43e19 100644
--- a/src/mainboard/amd/olivehill/BiosCallOuts.c
+++ b/src/mainboard/amd/olivehill/BiosCallOuts.c
@@ -37,8 +37,8 @@ const BIOS_CALLOUT_STRUCT BiosCallouts[] =
 	{AGESA_ALLOCATE_BUFFER,          agesa_AllocateBuffer },
 	{AGESA_DEALLOCATE_BUFFER,        agesa_DeallocateBuffer },
 	{AGESA_LOCATE_BUFFER,            agesa_LocateBuffer },
-	{AGESA_READ_SPD,                 fam16kb_ReadSpd },
 	{AGESA_DO_RESET,                 agesa_Reset },
+	{AGESA_READ_SPD,                 agesa_ReadSpd },
 	{AGESA_READ_SPD_RECOVERY,        agesa_NoopUnsupported },
 	{AGESA_RUNFUNC_ONAP,             agesa_RunFuncOnAp },
 	{AGESA_GET_IDS_INIT_DATA,        agesa_EmptyIdsInitData },
diff --git a/src/mainboard/amd/olivehillplus/BiosCallOuts.c b/src/mainboard/amd/olivehillplus/BiosCallOuts.c
index 719edf2..88e316b 100644
--- a/src/mainboard/amd/olivehillplus/BiosCallOuts.c
+++ b/src/mainboard/amd/olivehillplus/BiosCallOuts.c
@@ -37,7 +37,7 @@ const BIOS_CALLOUT_STRUCT BiosCallouts[] =
 	{AGESA_ALLOCATE_BUFFER,          agesa_AllocateBuffer },
 	{AGESA_DEALLOCATE_BUFFER,        agesa_DeallocateBuffer },
 	{AGESA_LOCATE_BUFFER,            agesa_LocateBuffer },
-	{AGESA_READ_SPD,                 ReadSpd_00730F01 },
+	{AGESA_READ_SPD,                 agesa_ReadSpd },
 	{AGESA_DO_RESET,                 agesa_Reset },
 	{AGESA_READ_SPD_RECOVERY,        agesa_NoopUnsupported },
 	{AGESA_RUNFUNC_ONAP,             agesa_RunFuncOnAp },
diff --git a/src/mainboard/amd/parmer/BiosCallOuts.c b/src/mainboard/amd/parmer/BiosCallOuts.c
index 67ae05f..9d7ab0b 100644
--- a/src/mainboard/amd/parmer/BiosCallOuts.c
+++ b/src/mainboard/amd/parmer/BiosCallOuts.c
@@ -37,8 +37,8 @@ const BIOS_CALLOUT_STRUCT BiosCallouts[] =
 	{AGESA_ALLOCATE_BUFFER,          agesa_AllocateBuffer },
 	{AGESA_DEALLOCATE_BUFFER,        agesa_DeallocateBuffer },
 	{AGESA_LOCATE_BUFFER,            agesa_LocateBuffer },
-	{AGESA_READ_SPD,                 fam15tn_ReadSpd },
 	{AGESA_DO_RESET,                 agesa_Reset },
+	{AGESA_READ_SPD,                 agesa_ReadSpd },
 	{AGESA_READ_SPD_RECOVERY,        agesa_NoopUnsupported },
 	{AGESA_RUNFUNC_ONAP,             agesa_RunFuncOnAp },
 	{AGESA_GET_IDS_INIT_DATA,        agesa_EmptyIdsInitData },
diff --git a/src/mainboard/amd/thatcher/BiosCallOuts.c b/src/mainboard/amd/thatcher/BiosCallOuts.c
index 0e5539a..921fcf4 100644
--- a/src/mainboard/amd/thatcher/BiosCallOuts.c
+++ b/src/mainboard/amd/thatcher/BiosCallOuts.c
@@ -37,8 +37,8 @@ const BIOS_CALLOUT_STRUCT BiosCallouts[] =
 	{AGESA_ALLOCATE_BUFFER,          agesa_AllocateBuffer },
 	{AGESA_DEALLOCATE_BUFFER,        agesa_DeallocateBuffer },
 	{AGESA_LOCATE_BUFFER,            agesa_LocateBuffer },
-	{AGESA_READ_SPD,                 fam15tn_ReadSpd },
 	{AGESA_DO_RESET,                 agesa_Reset },
+	{AGESA_READ_SPD,                 agesa_ReadSpd },
 	{AGESA_READ_SPD_RECOVERY,        agesa_NoopUnsupported },
 	{AGESA_RUNFUNC_ONAP,             agesa_RunFuncOnAp },
 	{AGESA_GET_IDS_INIT_DATA,        agesa_EmptyIdsInitData },
diff --git a/src/mainboard/asrock/imb-a180/BiosCallOuts.c b/src/mainboard/asrock/imb-a180/BiosCallOuts.c
index 8ee56b4..54ba216 100644
--- a/src/mainboard/asrock/imb-a180/BiosCallOuts.c
+++ b/src/mainboard/asrock/imb-a180/BiosCallOuts.c
@@ -35,8 +35,8 @@ const BIOS_CALLOUT_STRUCT BiosCallouts[] =
 	{AGESA_ALLOCATE_BUFFER,          agesa_AllocateBuffer },
 	{AGESA_DEALLOCATE_BUFFER,        agesa_DeallocateBuffer },
 	{AGESA_LOCATE_BUFFER,            agesa_LocateBuffer },
-	{AGESA_READ_SPD,                 fam16kb_ReadSpd },
 	{AGESA_DO_RESET,                 agesa_Reset },
+	{AGESA_READ_SPD,                 agesa_ReadSpd },
 	{AGESA_READ_SPD_RECOVERY,        agesa_NoopUnsupported },
 	{AGESA_RUNFUNC_ONAP,             agesa_RunFuncOnAp },
 	{AGESA_GET_IDS_INIT_DATA,        agesa_EmptyIdsInitData },
diff --git a/src/mainboard/asus/f2a85-m/BiosCallOuts.c b/src/mainboard/asus/f2a85-m/BiosCallOuts.c
index 0c56823..be90170 100644
--- a/src/mainboard/asus/f2a85-m/BiosCallOuts.c
+++ b/src/mainboard/asus/f2a85-m/BiosCallOuts.c
@@ -32,8 +32,8 @@ const BIOS_CALLOUT_STRUCT BiosCallouts[] =
 	{AGESA_ALLOCATE_BUFFER,          agesa_AllocateBuffer },
 	{AGESA_DEALLOCATE_BUFFER,        agesa_DeallocateBuffer },
 	{AGESA_LOCATE_BUFFER,            agesa_LocateBuffer },
-	{AGESA_READ_SPD,                 fam15tn_ReadSpd },
 	{AGESA_DO_RESET,                 agesa_Reset },
+	{AGESA_READ_SPD,                 agesa_ReadSpd },
 	{AGESA_READ_SPD_RECOVERY,        agesa_NoopUnsupported },
 	{AGESA_RUNFUNC_ONAP,             agesa_RunFuncOnAp },
 	{AGESA_GET_IDS_INIT_DATA,        agesa_EmptyIdsInitData },
diff --git a/src/mainboard/hp/pavilion_m6_1035dx/BiosCallOuts.c b/src/mainboard/hp/pavilion_m6_1035dx/BiosCallOuts.c
index adfa4e4..ad3f041 100644
--- a/src/mainboard/hp/pavilion_m6_1035dx/BiosCallOuts.c
+++ b/src/mainboard/hp/pavilion_m6_1035dx/BiosCallOuts.c
@@ -33,8 +33,8 @@ const BIOS_CALLOUT_STRUCT BiosCallouts[] =
 	{AGESA_ALLOCATE_BUFFER,          agesa_AllocateBuffer },
 	{AGESA_DEALLOCATE_BUFFER,        agesa_DeallocateBuffer },
 	{AGESA_LOCATE_BUFFER,            agesa_LocateBuffer },
-	{AGESA_READ_SPD,                 fam15tn_ReadSpd },
 	{AGESA_DO_RESET,                 agesa_Reset },
+	{AGESA_READ_SPD,                 agesa_ReadSpd },
 	{AGESA_READ_SPD_RECOVERY,        agesa_NoopUnsupported },
 	{AGESA_RUNFUNC_ONAP,             agesa_RunFuncOnAp },
 	{AGESA_GET_IDS_INIT_DATA,        agesa_EmptyIdsInitData },
diff --git a/src/northbridge/amd/agesa/00730F01/Makefile.inc b/src/northbridge/amd/agesa/00730F01/Makefile.inc
index b56b541..08f94bf 100644
--- a/src/northbridge/amd/agesa/00730F01/Makefile.inc
+++ b/src/northbridge/amd/agesa/00730F01/Makefile.inc
@@ -22,4 +22,3 @@ romstage-y += dimmSpd.c
 
 ramstage-y += northbridge.c
 ramstage-y += callouts_for_00730F01.c
-ramstage-y += dimmSpd.c
diff --git a/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.c b/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.c
index 91bf338..75f1849 100644
--- a/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.c
+++ b/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.c
@@ -24,14 +24,6 @@
 #include "heapManager.h"
 #include "FchPlatform.h"
 #include "cbfs.h"
-#include "dimmSpd.h"
 #include "callouts_for_00730F01.h"
 #include "northbridge/amd/agesa/def_callouts.h"
 
-AGESA_STATUS ReadSpd_00730F01 (UINT32 Func, UINT32 Data, VOID *ConfigPtr)
-{
-	AGESA_STATUS Status;
-	Status = AmdMemoryReadSPD (Func, Data, ConfigPtr);
-
-	return Status;
-}
diff --git a/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.h b/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.h
index 4bf27f8..31bd721 100644
--- a/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.h
+++ b/src/northbridge/amd/agesa/00730F01/callouts_for_00730F01.h
@@ -23,6 +23,5 @@
 #include "Porting.h"
 #include "AGESA.h"
 
-AGESA_STATUS ReadSpd_00730F01 (UINT32 Func, UINT32 Data, VOID *ConfigPtr);
 
 #endif /* CALLOUTS_AMD_AGESA_FAM16_0X30_H */
diff --git a/src/northbridge/amd/agesa/00730F01/dimmSpd.c b/src/northbridge/amd/agesa/00730F01/dimmSpd.c
index d31f721..4cfbb7f 100644
--- a/src/northbridge/amd/agesa/00730F01/dimmSpd.c
+++ b/src/northbridge/amd/agesa/00730F01/dimmSpd.c
@@ -24,132 +24,15 @@
 #include "Porting.h"
 #include "AGESA.h"
 #include "amdlib.h"
-#include "dimmSpd.h"
 #include "chip.h"
 
+#include "northbridge/amd/agesa/dimmSpd.h"
 
 #define DIMENSION(array)(sizeof (array)/ sizeof (array [0]))
 
-/*-----------------------------------------------------------------------------
- *
- * readSmbusByteData - read a single SPD byte from any offset
- */
-
-static int readSmbusByteData (int iobase, int address, char *buffer, int offset)
-{
-	unsigned int status;
-	UINT64 limit;
-
-	address |= 1; // set read bit
-
-	__outbyte (iobase + 0, 0xFF);                // clear error status
-	__outbyte (iobase + 1, 0x1F);                // clear error status
-	__outbyte (iobase + 3, offset);              // offset in eeprom
-	__outbyte (iobase + 4, address);             // slave address and read bit
-	__outbyte (iobase + 2, 0x48);                // read byte command
-
-	// time limit to avoid hanging for unexpected error status (should never happen)
-	limit = __rdtsc () + 2000000000 / 10;
-	for (;;)
-	{
-		status = __inbyte (iobase);
-		if (__rdtsc () > limit) break;
-		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
-		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
-		break;
-	}
-
-	buffer [0] = __inbyte (iobase + 5);
-	if (status == 2) status = 0;                      // check for done with no errors
-	return status;
-}
-
-/*-----------------------------------------------------------------------------
- *
- * readSmbusByte - read a single SPD byte from the default offset
- *                 this function is faster function readSmbusByteData
- */
-
-static int readSmbusByte (int iobase, int address, char *buffer)
-{
-	unsigned int status;
-	UINT64 limit;
-
-	__outbyte (iobase + 0, 0xFF);                // clear error status
-	__outbyte (iobase + 2, 0x44);                // read command
-
-	// time limit to avoid hanging for unexpected error status
-	limit = __rdtsc () + 2000000000 / 10;
-	for (;;)
-	{
-		status = __inbyte (iobase);
-		if (__rdtsc () > limit) break;
-		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
-		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
-		break;
-	}
-
-	buffer [0] = __inbyte (iobase + 5);
-	if (status == 2) status = 0;                      // check for done with no errors
-	return status;
-}
-
-/*---------------------------------------------------------------------------
- *
- * readspd - Read one or more SPD bytes from a DIMM.
- *           Start with offset zero and read sequentially.
- *           Optimization relies on autoincrement to avoid
- *           sending offset for every byte.
- *          Reads 128 bytes in 7-8 ms at 400 KHz.
- */
-
-static int readspd (int iobase, int SmbusSlaveAddress, char *buffer, int count)
-{
-	int index, error;
-
-	printk(BIOS_SPEW, "-------------READING SPD-----------\n");
-	printk(BIOS_SPEW, "iobase: 0x%08X, SmbusSlave: 0x%08X, count: %d\n",
-						iobase, SmbusSlaveAddress, count);
-
-	/* read the first byte using offset zero */
-	error = readSmbusByteData (iobase, SmbusSlaveAddress, buffer, 0);
-
-	if (error) {
-		printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n");
-		return error;
-	}
-
-	/* read the remaining bytes using auto-increment for speed */
-	for (index = 1; index < count; index++)
-	{
-		error = readSmbusByte (iobase, SmbusSlaveAddress, &buffer [index]);
-		if (error) {
-			printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n");
-			return error;
-		}
-	}
-	printk(BIOS_SPEW, "\n");
-	printk(BIOS_SPEW, "-------------FINISHED READING SPD-----------\n");
-
-	return 0;
-}
-
-static void writePmReg (int reg, int data)
-{
-	__outbyte (0xCD6, reg);
-	__outbyte (0xCD7, data);
-}
-
-static void setupFch (int ioBase)
-{
-	writePmReg (0x2D, ioBase >> 8);
-	writePmReg (0x2C, ioBase | 1);
-	__outbyte (ioBase + 0x0E, 66000000 / 400000 / 4); // set SMBus clock to 400 KHz
-}
-
 AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PARAMS *info)
 {
-	int spdAddress, ioBase;
+	int spdAddress;
 	ROMSTAGE_CONST struct device *dev = dev_find_slot(0, PCI_DEVFN(0x18, 2));
 	ROMSTAGE_CONST struct northbridge_amd_agesa_00730F01_config *config = dev->chip_info;
 
@@ -166,8 +49,11 @@ AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PA
 	spdAddress = config->spdAddrLookup
 		[info->SocketId] [info->MemChannelId] [info->DimmId];
 
-	if (spdAddress == 0) return AGESA_ERROR;
-	ioBase = 0xB00;
-	setupFch (ioBase);
-	return readspd (ioBase, spdAddress, (void *) info->Buffer, 128);
+	if (spdAddress == 0)
+		return AGESA_ERROR;
+
+	int err = hudson_readSpd(spdAddress, (void *) info->Buffer, 128);
+	if (err)
+		return AGESA_ERROR;
+	return AGESA_SUCCESS;
 }
diff --git a/src/northbridge/amd/agesa/00730F01/dimmSpd.h b/src/northbridge/amd/agesa/00730F01/dimmSpd.h
deleted file mode 100644
index 667fe26..0000000
--- a/src/northbridge/amd/agesa/00730F01/dimmSpd.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2012 Advanced Micro Devices, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef _DIMMSPD_H_
-#define _DIMMSPD_H_
-
-AGESA_STATUS
-AmdMemoryReadSPD (IN UINT32 Func, IN UINT32 Data, IN OUT AGESA_READ_SPD_PARAMS *SpdData);
-
-#endif
diff --git a/src/northbridge/amd/agesa/def_callouts.c b/src/northbridge/amd/agesa/def_callouts.c
index c8b74d4..9975924 100644
--- a/src/northbridge/amd/agesa/def_callouts.c
+++ b/src/northbridge/amd/agesa/def_callouts.c
@@ -26,6 +26,7 @@
 #include "Ids.h"
 #include "agesawrapper.h"
 #include "def_callouts.h"
+#include "dimmSpd.h"
 
 AGESA_STATUS GetBiosCallout (UINT32 Func, UINT32 Data, VOID *ConfigPtr)
 {
@@ -114,6 +115,15 @@ AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINT32 FchData, VOID *ConfigPrt
 	/* printk(BIOS_DEBUG, "IMGptr=%x\n", pVbiosImageInfo->ImagePtr); */
 	return pVbiosImageInfo->ImagePtr == NULL ? AGESA_WARNING : AGESA_SUCCESS;
 }
+
+AGESA_STATUS agesa_ReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr)
+{
+	AGESA_STATUS Status = AGESA_UNSUPPORTED;
+#ifdef __PRE_RAM__
+	Status = AmdMemoryReadSPD (Func, Data, ConfigPtr);
+#endif
+	return Status;
+}
 #endif
 
 AGESA_STATUS agesa_ReadSpd_from_cbfs(UINT32 Func, UINT32 Data, VOID *ConfigPtr)
diff --git a/src/northbridge/amd/agesa/def_callouts.h b/src/northbridge/amd/agesa/def_callouts.h
index 2d23f3e..60299b7 100644
--- a/src/northbridge/amd/agesa/def_callouts.h
+++ b/src/northbridge/amd/agesa/def_callouts.h
@@ -64,6 +64,7 @@ AGESA_STATUS agesa_Reset (UINT32 Func, UINT32 Data, VOID *ConfigPtr);
 AGESA_STATUS agesa_RunFuncOnAp (UINT32 Func, UINT32 Data, VOID *ConfigPtr);
 AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINT32 FchData, VOID *ConfigPrt);
 
+AGESA_STATUS agesa_ReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr);
 AGESA_STATUS agesa_ReadSpd_from_cbfs(UINT32 Func, UINT32 Data, VOID *ConfigPtr);
 
 AGESA_STATUS GetBiosCallout (UINT32 Func, UINT32 Data, VOID *ConfigPtr);
diff --git a/src/northbridge/amd/agesa/dimmSpd.h b/src/northbridge/amd/agesa/dimmSpd.h
new file mode 100644
index 0000000..3af6720
--- /dev/null
+++ b/src/northbridge/amd/agesa/dimmSpd.h
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2012 Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _DIMMSPD_H_
+#define _DIMMSPD_H_
+
+AGESA_STATUS
+AmdMemoryReadSPD (IN UINT32 Func, IN UINT32 Data, IN OUT AGESA_READ_SPD_PARAMS *SpdData);
+
+int hudson_readSpd(int spdAddress, char *buf, size_t len);
+
+int smbus_readSpd(int spdAddress, char *buf, size_t len);
+
+#endif
diff --git a/src/northbridge/amd/agesa/family15tn/Makefile.inc b/src/northbridge/amd/agesa/family15tn/Makefile.inc
index afec3c0..c4d4b0d 100644
--- a/src/northbridge/amd/agesa/family15tn/Makefile.inc
+++ b/src/northbridge/amd/agesa/family15tn/Makefile.inc
@@ -23,4 +23,3 @@ romstage-y += dimmSpd.c
 ramstage-y += iommu.c
 ramstage-y += northbridge.c
 ramstage-y += fam15tn_callouts.c
-ramstage-y += dimmSpd.c
diff --git a/src/northbridge/amd/agesa/family15tn/dimmSpd.c b/src/northbridge/amd/agesa/family15tn/dimmSpd.c
index 5b8a9b5..4d5ab5f 100644
--- a/src/northbridge/amd/agesa/family15tn/dimmSpd.c
+++ b/src/northbridge/amd/agesa/family15tn/dimmSpd.c
@@ -24,119 +24,15 @@
 #include "Porting.h"
 #include "AGESA.h"
 #include "amdlib.h"
-#include "dimmSpd.h"
 #include "chip.h"
 
+#include "northbridge/amd/agesa/dimmSpd.h"
 
 #define DIMENSION(array)(sizeof (array)/ sizeof (array [0]))
 
-/*-----------------------------------------------------------------------------
- *
- * readSmbusByteData - read a single SPD byte from any offset
- */
-
-static int readSmbusByteData (int iobase, int address, char *buffer, int offset)
-{
-	unsigned int status;
-	UINT64 limit;
-
-	address |= 1; // set read bit
-
-	__outbyte (iobase + 0, 0xFF);                // clear error status
-	__outbyte (iobase + 1, 0x1F);                // clear error status
-	__outbyte (iobase + 3, offset);              // offset in eeprom
-	__outbyte (iobase + 4, address);             // slave address and read bit
-	__outbyte (iobase + 2, 0x48);                // read byte command
-
-	// time limit to avoid hanging for unexpected error status (should never happen)
-	limit = __rdtsc () + 2000000000 / 10;
-	for (;;)
-	{
-		status = __inbyte (iobase);
-		if (__rdtsc () > limit) break;
-		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
-		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
-		break;
-	}
-
-	buffer [0] = __inbyte (iobase + 5);
-	if (status == 2) status = 0;                      // check for done with no errors
-	return status;
-}
-
-/*-----------------------------------------------------------------------------
- *
- * readSmbusByte - read a single SPD byte from the default offset
- *                 this function is faster function readSmbusByteData
- */
-
-static int readSmbusByte (int iobase, int address, char *buffer)
-{
-	unsigned int status;
-	UINT64 limit;
-
-	__outbyte (iobase + 0, 0xFF);                // clear error status
-	__outbyte (iobase + 2, 0x44);                // read command
-
-	// time limit to avoid hanging for unexpected error status
-	limit = __rdtsc () + 2000000000 / 10;
-	for (;;)
-	{
-		status = __inbyte (iobase);
-		if (__rdtsc () > limit) break;
-		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
-		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
-		break;
-	}
-
-	buffer [0] = __inbyte (iobase + 5);
-	if (status == 2) status = 0;                      // check for done with no errors
-	return status;
-}
-
-/*---------------------------------------------------------------------------
- *
- * readspd - Read one or more SPD bytes from a DIMM.
- *           Start with offset zero and read sequentially.
- *           Optimization relies on autoincrement to avoid
- *           sending offset for every byte.
- *          Reads 128 bytes in 7-8 ms at 400 KHz.
- */
-
-static int readspd (int iobase, int SmbusSlaveAddress, char *buffer, int count)
-{
-	int index, error;
-
-	/* read the first byte using offset zero */
-	error = readSmbusByteData (iobase, SmbusSlaveAddress, buffer, 0);
-	if (error) return error;
-
-	/* read the remaining bytes using auto-increment for speed */
-	for (index = 1; index < count; index++)
-	{
-		error = readSmbusByte (iobase, SmbusSlaveAddress, &buffer [index]);
-		if (error) return error;
-	}
-
-	return 0;
-}
-
-static void writePmReg (int reg, int data)
-{
-	__outbyte (0xCD6, reg);
-	__outbyte (0xCD7, data);
-}
-
-static void setupFch (int ioBase)
-{
-	writePmReg (0x2D, ioBase >> 8);
-	writePmReg (0x2C, ioBase | 1);
-	__outbyte (ioBase + 0x0E, 66000000 / 400000 / 4); // set SMBus clock to 400 KHz
-}
-
 AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PARAMS *info)
 {
-	int spdAddress, ioBase;
+	int spdAddress;
 	ROMSTAGE_CONST struct device *dev = dev_find_slot(0, PCI_DEVFN(0x18, 2));
 	ROMSTAGE_CONST struct northbridge_amd_agesa_family15tn_config *config = dev->chip_info;
 
@@ -153,8 +49,11 @@ AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PA
 	spdAddress = config->spdAddrLookup
 		[info->SocketId] [info->MemChannelId] [info->DimmId];
 
-	if (spdAddress == 0) return AGESA_ERROR;
-	ioBase = 0xB00;
-	setupFch (ioBase);
-	return readspd (ioBase, spdAddress, (void *) info->Buffer, 128);
+	if (spdAddress == 0)
+		return AGESA_ERROR;
+
+	int err = hudson_readSpd(spdAddress, (void *) info->Buffer, 128);
+	if (err)
+		return AGESA_ERROR;
+	return AGESA_SUCCESS;
 }
diff --git a/src/northbridge/amd/agesa/family15tn/dimmSpd.h b/src/northbridge/amd/agesa/family15tn/dimmSpd.h
deleted file mode 100644
index e50d53e..0000000
--- a/src/northbridge/amd/agesa/family15tn/dimmSpd.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2012 Advanced Micro Devices, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*----------------------------------------------------------------------------------------
- *                             M O D U L E S    U S E D
- *----------------------------------------------------------------------------------------
- */
-
-#ifndef _DIMMSPD_H_
-#define _DIMMSPD_H_
-
-/*----------------------------------------------------------------------------------------
- *                   D E F I N I T I O N S    A N D    M A C R O S
- *----------------------------------------------------------------------------------------
- */
-
-/*----------------------------------------------------------------------------------------
- *                  T Y P E D E F S     A N D     S T R U C T U  R E S
- *----------------------------------------------------------------------------------------
- */
-
-/*----------------------------------------------------------------------------------------
- *           P R O T O T Y P E S     O F     L O C A L     F U  N C T I O N S
- *----------------------------------------------------------------------------------------
- */
-
-/*----------------------------------------------------------------------------------------
- *                          E X P O R T E D    F U N C T I O N S
- *----------------------------------------------------------------------------------------
- */
-
-AGESA_STATUS
-AmdMemoryReadSPD (IN UINT32 Func, IN UINT32 Data, IN OUT AGESA_READ_SPD_PARAMS *SpdData);
-
-/*---------------------------------------------------------------------------------------
- *                          L O C A L    F U N C T I O N S
- *---------------------------------------------------------------------------------------
- */
-
-#endif
diff --git a/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.c b/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.c
index 3cd81c6..287cb97 100644
--- a/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.c
+++ b/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.c
@@ -24,14 +24,5 @@
 #include "heapManager.h"
 #include "FchPlatform.h"
 #include "cbfs.h"
-#include "dimmSpd.h"
 #include "fam15tn_callouts.h"
 
-
-AGESA_STATUS fam15tn_ReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr)
-{
-	AGESA_STATUS Status;
-	Status = AmdMemoryReadSPD (Func, Data, ConfigPtr);
-
-	return Status;
-}
diff --git a/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.h b/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.h
index 6864b50..d6d265e 100644
--- a/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.h
+++ b/src/northbridge/amd/agesa/family15tn/fam15tn_callouts.h
@@ -24,6 +24,4 @@
 #include "AGESA.h"
 
 
-AGESA_STATUS fam15tn_ReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr);
-
 #endif /* CALLOUTS_AMD_AGESA_FAM15TN_H */
diff --git a/src/northbridge/amd/agesa/family16kb/Makefile.inc b/src/northbridge/amd/agesa/family16kb/Makefile.inc
index fe9d3bc..2fa4736 100644
--- a/src/northbridge/amd/agesa/family16kb/Makefile.inc
+++ b/src/northbridge/amd/agesa/family16kb/Makefile.inc
@@ -22,4 +22,3 @@ romstage-y += dimmSpd.c
 
 ramstage-y += northbridge.c
 ramstage-y += fam16kb_callouts.c
-ramstage-y += dimmSpd.c
diff --git a/src/northbridge/amd/agesa/family16kb/dimmSpd.c b/src/northbridge/amd/agesa/family16kb/dimmSpd.c
index 1d9363c..8991bdb 100644
--- a/src/northbridge/amd/agesa/family16kb/dimmSpd.c
+++ b/src/northbridge/amd/agesa/family16kb/dimmSpd.c
@@ -24,119 +24,15 @@
 #include "Porting.h"
 #include "AGESA.h"
 #include "amdlib.h"
-#include "dimmSpd.h"
 #include "chip.h"
 
+#include "northbridge/amd/agesa/dimmSpd.h"
 
 #define DIMENSION(array)(sizeof (array)/ sizeof (array [0]))
 
-/*-----------------------------------------------------------------------------
- *
- * readSmbusByteData - read a single SPD byte from any offset
- */
-
-static int readSmbusByteData (int iobase, int address, char *buffer, int offset)
-{
-	unsigned int status;
-	UINT64 limit;
-
-	address |= 1; // set read bit
-
-	__outbyte (iobase + 0, 0xFF);                // clear error status
-	__outbyte (iobase + 1, 0x1F);                // clear error status
-	__outbyte (iobase + 3, offset);              // offset in eeprom
-	__outbyte (iobase + 4, address);             // slave address and read bit
-	__outbyte (iobase + 2, 0x48);                // read byte command
-
-	// time limit to avoid hanging for unexpected error status (should never happen)
-	limit = __rdtsc () + 2000000000 / 10;
-	for (;;)
-	{
-		status = __inbyte (iobase);
-		if (__rdtsc () > limit) break;
-		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
-		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
-		break;
-	}
-
-	buffer [0] = __inbyte (iobase + 5);
-	if (status == 2) status = 0;                      // check for done with no errors
-	return status;
-}
-
-/*-----------------------------------------------------------------------------
- *
- * readSmbusByte - read a single SPD byte from the default offset
- *                 this function is faster function readSmbusByteData
- */
-
-static int readSmbusByte (int iobase, int address, char *buffer)
-{
-	unsigned int status;
-	UINT64 limit;
-
-	__outbyte (iobase + 0, 0xFF);                // clear error status
-	__outbyte (iobase + 2, 0x44);                // read command
-
-	// time limit to avoid hanging for unexpected error status
-	limit = __rdtsc () + 2000000000 / 10;
-	for (;;)
-	{
-		status = __inbyte (iobase);
-		if (__rdtsc () > limit) break;
-		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
-		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
-		break;
-	}
-
-	buffer [0] = __inbyte (iobase + 5);
-	if (status == 2) status = 0;                      // check for done with no errors
-	return status;
-}
-
-/*---------------------------------------------------------------------------
- *
- * readspd - Read one or more SPD bytes from a DIMM.
- *           Start with offset zero and read sequentially.
- *           Optimization relies on autoincrement to avoid
- *           sending offset for every byte.
- *          Reads 128 bytes in 7-8 ms at 400 KHz.
- */
-
-static int readspd (int iobase, int SmbusSlaveAddress, char *buffer, int count)
-{
-	int index, error;
-
-	/* read the first byte using offset zero */
-	error = readSmbusByteData (iobase, SmbusSlaveAddress, buffer, 0);
-	if (error) return error;
-
-	/* read the remaining bytes using auto-increment for speed */
-	for (index = 1; index < count; index++)
-	{
-		error = readSmbusByte (iobase, SmbusSlaveAddress, &buffer [index]);
-		if (error) return error;
-	}
-
-	return 0;
-}
-
-static void writePmReg (int reg, int data)
-{
-	__outbyte (0xCD6, reg);
-	__outbyte (0xCD7, data);
-}
-
-static void setupFch (int ioBase)
-{
-	writePmReg (0x2D, ioBase >> 8);
-	writePmReg (0x2C, ioBase | 1);
-	__outbyte (ioBase + 0x0E, 66000000 / 400000 / 4); // set SMBus clock to 400 KHz
-}
-
 AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PARAMS *info)
 {
-	int spdAddress, ioBase;
+	int spdAddress;
 	ROMSTAGE_CONST struct device *dev = dev_find_slot(0, PCI_DEVFN(0x18, 2));
 	ROMSTAGE_CONST struct northbridge_amd_agesa_family16kb_config *config = dev->chip_info;
 
@@ -153,8 +49,11 @@ AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PA
 	spdAddress = config->spdAddrLookup
 		[info->SocketId] [info->MemChannelId] [info->DimmId];
 
-	if (spdAddress == 0) return AGESA_ERROR;
-	ioBase = 0xB00;
-	setupFch (ioBase);
-	return readspd (ioBase, spdAddress, (void *) info->Buffer, 128);
+	if (spdAddress == 0)
+		return AGESA_ERROR;
+
+	int err = hudson_readSpd(spdAddress, (void *) info->Buffer, 128);
+	if (err)
+		return AGESA_ERROR;
+	return AGESA_SUCCESS;
 }
diff --git a/src/northbridge/amd/agesa/family16kb/dimmSpd.h b/src/northbridge/amd/agesa/family16kb/dimmSpd.h
deleted file mode 100644
index e50d53e..0000000
--- a/src/northbridge/amd/agesa/family16kb/dimmSpd.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2012 Advanced Micro Devices, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*----------------------------------------------------------------------------------------
- *                             M O D U L E S    U S E D
- *----------------------------------------------------------------------------------------
- */
-
-#ifndef _DIMMSPD_H_
-#define _DIMMSPD_H_
-
-/*----------------------------------------------------------------------------------------
- *                   D E F I N I T I O N S    A N D    M A C R O S
- *----------------------------------------------------------------------------------------
- */
-
-/*----------------------------------------------------------------------------------------
- *                  T Y P E D E F S     A N D     S T R U C T U  R E S
- *----------------------------------------------------------------------------------------
- */
-
-/*----------------------------------------------------------------------------------------
- *           P R O T O T Y P E S     O F     L O C A L     F U  N C T I O N S
- *----------------------------------------------------------------------------------------
- */
-
-/*----------------------------------------------------------------------------------------
- *                          E X P O R T E D    F U N C T I O N S
- *----------------------------------------------------------------------------------------
- */
-
-AGESA_STATUS
-AmdMemoryReadSPD (IN UINT32 Func, IN UINT32 Data, IN OUT AGESA_READ_SPD_PARAMS *SpdData);
-
-/*---------------------------------------------------------------------------------------
- *                          L O C A L    F U N C T I O N S
- *---------------------------------------------------------------------------------------
- */
-
-#endif
diff --git a/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.c b/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.c
index 87e2dc8..2e1cd3d 100644
--- a/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.c
+++ b/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.c
@@ -24,16 +24,8 @@
 #include "heapManager.h"
 #include "FchPlatform.h"
 #include "cbfs.h"
-#include "dimmSpd.h"
 #include "fam16kb_callouts.h"
 
 
 
 
-AGESA_STATUS fam16kb_ReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr)
-{
-	AGESA_STATUS Status;
-	Status = AmdMemoryReadSPD (Func, Data, ConfigPtr);
-
-	return Status;
-}
diff --git a/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.h b/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.h
index c83ae27..debdc4b 100644
--- a/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.h
+++ b/src/northbridge/amd/agesa/family16kb/fam16kb_callouts.h
@@ -24,6 +24,4 @@
 #include "AGESA.h"
 
 
-AGESA_STATUS fam16kb_ReadSpd (UINT32 Func, UINT32 Data, VOID *ConfigPtr);
-
 #endif /* CALLOUTS_AMD_AGESA_FAM16KB_H */
diff --git a/src/southbridge/amd/agesa/hudson/Makefile.inc b/src/southbridge/amd/agesa/hudson/Makefile.inc
index 6ed0ff6..eb02936 100644
--- a/src/southbridge/amd/agesa/hudson/Makefile.inc
+++ b/src/southbridge/amd/agesa/hudson/Makefile.inc
@@ -30,7 +30,7 @@
 
 INCLUDES += -Isrc/southbridge/amd/agesa/hudson
 
-romstage-y += smbus.c
+romstage-y += smbus.c smbus_spd.c
 ramstage-y += hudson.c
 ramstage-y += usb.c
 ramstage-y += lpc.c
diff --git a/src/southbridge/amd/agesa/hudson/smbus_spd.c b/src/southbridge/amd/agesa/hudson/smbus_spd.c
new file mode 100644
index 0000000..32e00d6
--- /dev/null
+++ b/src/southbridge/amd/agesa/hudson/smbus_spd.c
@@ -0,0 +1,152 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2012 Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <device/pci_def.h>
+#include <device/device.h>
+
+/* warning: Porting.h includes an open #pragma pack(1) */
+#include "Porting.h"
+#include "AGESA.h"
+#include "amdlib.h"
+
+#include <northbridge/amd/agesa/dimmSpd.h>
+
+/*-----------------------------------------------------------------------------
+ *
+ * readSmbusByteData - read a single SPD byte from any offset
+ */
+
+static int readSmbusByteData (int iobase, int address, char *buffer, int offset)
+{
+	unsigned int status;
+	UINT64 limit;
+
+	address |= 1; // set read bit
+
+	__outbyte (iobase + 0, 0xFF);                // clear error status
+	__outbyte (iobase + 1, 0x1F);                // clear error status
+	__outbyte (iobase + 3, offset);              // offset in eeprom
+	__outbyte (iobase + 4, address);             // slave address and read bit
+	__outbyte (iobase + 2, 0x48);                // read byte command
+
+	// time limit to avoid hanging for unexpected error status (should never happen)
+	limit = __rdtsc () + 2000000000 / 10;
+	for (;;)
+	{
+		status = __inbyte (iobase);
+		if (__rdtsc () > limit) break;
+		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
+		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
+		break;
+	}
+
+	buffer [0] = __inbyte (iobase + 5);
+	if (status == 2) status = 0;                      // check for done with no errors
+	return status;
+}
+
+/*-----------------------------------------------------------------------------
+ *
+ * readSmbusByte - read a single SPD byte from the default offset
+ *                 this function is faster function readSmbusByteData
+ */
+
+static int readSmbusByte (int iobase, int address, char *buffer)
+{
+	unsigned int status;
+	UINT64 limit;
+
+	__outbyte (iobase + 0, 0xFF);                // clear error status
+	__outbyte (iobase + 2, 0x44);                // read command
+
+	// time limit to avoid hanging for unexpected error status
+	limit = __rdtsc () + 2000000000 / 10;
+	for (;;)
+	{
+		status = __inbyte (iobase);
+		if (__rdtsc () > limit) break;
+		if ((status & 2) == 0) continue;               // SMBusInterrupt not set, keep waiting
+		if ((status & 1) == 1) continue;               // HostBusy set, keep waiting
+		break;
+	}
+
+	buffer [0] = __inbyte (iobase + 5);
+	if (status == 2) status = 0;                      // check for done with no errors
+	return status;
+}
+
+/*---------------------------------------------------------------------------
+ *
+ * readspd - Read one or more SPD bytes from a DIMM.
+ *           Start with offset zero and read sequentially.
+ *           Optimization relies on autoincrement to avoid
+ *           sending offset for every byte.
+ *          Reads 128 bytes in 7-8 ms at 400 KHz.
+ */
+
+static int readspd (int iobase, int SmbusSlaveAddress, char *buffer, int count)
+{
+	int index, error;
+
+	printk(BIOS_SPEW, "-------------READING SPD-----------\n");
+	printk(BIOS_SPEW, "iobase: 0x%08X, SmbusSlave: 0x%08X, count: %d\n",
+						iobase, SmbusSlaveAddress, count);
+
+	/* read the first byte using offset zero */
+	error = readSmbusByteData (iobase, SmbusSlaveAddress, buffer, 0);
+
+	if (error) {
+		printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n");
+		return error;
+	}
+
+	/* read the remaining bytes using auto-increment for speed */
+	for (index = 1; index < count; index++)
+	{
+		error = readSmbusByte (iobase, SmbusSlaveAddress, &buffer [index]);
+		if (error) {
+			printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n");
+			return error;
+		}
+	}
+	printk(BIOS_SPEW, "\n");
+	printk(BIOS_SPEW, "-------------FINISHED READING SPD-----------\n");
+
+	return 0;
+}
+
+static void writePmReg (int reg, int data)
+{
+	__outbyte (0xCD6, reg);
+	__outbyte (0xCD7, data);
+}
+
+static void setupFch (int ioBase)
+{
+	writePmReg (0x2D, ioBase >> 8);
+	writePmReg (0x2C, ioBase | 1);
+	__outbyte (ioBase + 0x0E, 66000000 / 400000 / 4); // set SMBus clock to 400 KHz
+}
+
+int hudson_readSpd(int spdAddress, char *buf, size_t len)
+{
+	int ioBase = 0xB00;
+	setupFch (ioBase);
+	return readspd (ioBase, spdAddress, buf, len);
+}



More information about the coreboot-gerrit mailing list