1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <amdblocks/agesawrapper.h>
4 #include <amdblocks/acpimmio.h>
5 #include <console/console.h>
6 #include <device/pci_def.h>
7 #include <device/device.h>
8 #include <device/smbus_host.h>
9 #include <soc/southbridge.h>
10 #include <amdblocks/dimm_spd.h>
13 * readspd - Read one or more SPD bytes from a DIMM.
14 * Start with offset zero and read sequentially.
15 * Optimization relies on autoincrement to avoid
16 * sending offset for every byte.
17 * Reads 128 bytes in 7-8 ms at 400 KHz.
19 static int readspd(uint8_t SmbusSlaveAddress
, char *buffer
, size_t count
)
26 printk(BIOS_SPEW
, "-------------READING SPD-----------\n");
27 printk(BIOS_SPEW
, "SmbusSlave: 0x%08X, count: %zd\n",
28 SmbusSlaveAddress
, count
);
31 * Convert received device address to the format accepted by
32 * do_smbus_read_byte and do_smbus_recv_byte.
34 dev_addr
= (SmbusSlaveAddress
>> 1);
36 /* Read the first SPD byte */
37 error
= do_smbus_read_byte((uintptr_t)acpimmio_smbus
, dev_addr
, 0);
39 printk(BIOS_ERR
, "-------------SPD READ ERROR-----------\n");
45 /* Read the remaining SPD bytes using do_smbus_recv_byte for speed */
46 for (index
= 1 ; index
< count
; index
++) {
47 error
= do_smbus_recv_byte((uintptr_t)acpimmio_smbus
, dev_addr
);
49 printk(BIOS_ERR
, "-------------SPD READ ERROR-----------\n");
55 printk(BIOS_SPEW
, "\n");
56 printk(BIOS_SPEW
, "-------------FINISHED READING SPD-----------\n");
61 int sb_read_spd(uint8_t spdAddress
, char *buf
, size_t len
)
63 return readspd(spdAddress
, buf
, len
);