Debian Codegraph @

src/soc/amd/stoneyridge/smbus_spd.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
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>
11
12 /*
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.
18 */
19 static int readspd(uint8_t SmbusSlaveAddress, char *buffer, size_t count)
20 {
21 uint8_t dev_addr;
22 size_t index;
23 int error;
24 char *pbuf = buffer;
25
26 printk(BIOS_SPEW, "-------------READING SPD-----------\n");
27 printk(BIOS_SPEW, "SmbusSlave: 0x%08X, count: %zd\n",
28 SmbusSlaveAddress, count);
29
30 /*
31 * Convert received device address to the format accepted by
32 * do_smbus_read_byte and do_smbus_recv_byte.
33 */
34 dev_addr = (SmbusSlaveAddress >> 1);
35
36 /* Read the first SPD byte */
37 error = do_smbus_read_byte((uintptr_t)acpimmio_smbus, dev_addr, 0);
38 if (error < 0) {
39 printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n");
40 return error;
41 }
42 *pbuf = (char)error;
43 pbuf++;
44
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);
48 if (error < 0) {
49 printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n");
50 return error;
51 }
52 *pbuf = (char)error;
53 pbuf++;
54 }
55 printk(BIOS_SPEW, "\n");
56 printk(BIOS_SPEW, "-------------FINISHED READING SPD-----------\n");
57
58 return 0;
59 }
60
61 int sb_read_spd(uint8_t spdAddress, char *buf, size_t len)
62 {
63 return readspd(spdAddress, buf, len);
64 }