Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 3 | #include <amdblocks/agesawrapper.h> |
Kyösti Mälkki | d786520 | 2020-07-01 13:15:27 +0300 | [diff] [blame] | 4 | #include <amdblocks/acpimmio.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 5 | #include <console/console.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 6 | #include <device/pci_def.h> |
| 7 | #include <device/device.h> |
Aaron Durbin | 178d644 | 2020-01-28 11:10:23 -0700 | [diff] [blame] | 8 | #include <device/smbus_host.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 9 | #include <soc/southbridge.h> |
Marc Jones | afd03d8 | 2017-11-16 10:01:08 -0700 | [diff] [blame] | 10 | #include <amdblocks/dimm_spd.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 11 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 12 | /* |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 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 | */ |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 19 | static int readspd(uint8_t SmbusSlaveAddress, char *buffer, size_t count) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 20 | { |
Richard Spiegel | 77fee09 | 2017-11-10 08:33:57 -0700 | [diff] [blame] | 21 | uint8_t dev_addr; |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 22 | size_t index; |
| 23 | int error; |
| 24 | char *pbuf = buffer; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 25 | |
| 26 | printk(BIOS_SPEW, "-------------READING SPD-----------\n"); |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 27 | printk(BIOS_SPEW, "SmbusSlave: 0x%08X, count: %zd\n", |
| 28 | SmbusSlaveAddress, count); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 29 | |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 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); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 35 | |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 36 | /* Read the first SPD byte */ |
Kyösti Mälkki | d786520 | 2020-07-01 13:15:27 +0300 | [diff] [blame] | 37 | error = do_smbus_read_byte((uintptr_t)acpimmio_smbus, dev_addr, 0); |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 38 | if (error < 0) { |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 39 | printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); |
| 40 | return error; |
| 41 | } |
Richard Spiegel | d46bb6b | 2018-10-16 13:44:03 -0700 | [diff] [blame] | 42 | *pbuf = (char) error; |
| 43 | pbuf++; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 44 | |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 45 | /* Read the remaining SPD bytes using do_smbus_recv_byte for speed */ |
| 46 | for (index = 1 ; index < count ; index++) { |
Kyösti Mälkki | d786520 | 2020-07-01 13:15:27 +0300 | [diff] [blame] | 47 | error = do_smbus_recv_byte((uintptr_t)acpimmio_smbus, dev_addr); |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 48 | if (error < 0) { |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 49 | printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); |
| 50 | return error; |
| 51 | } |
Richard Spiegel | d46bb6b | 2018-10-16 13:44:03 -0700 | [diff] [blame] | 52 | *pbuf = (char) error; |
| 53 | pbuf++; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 54 | } |
| 55 | printk(BIOS_SPEW, "\n"); |
| 56 | printk(BIOS_SPEW, "-------------FINISHED READING SPD-----------\n"); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Marc Jones | afd03d8 | 2017-11-16 10:01:08 -0700 | [diff] [blame] | 61 | int sb_read_spd(uint8_t spdAddress, char *buf, size_t len) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 62 | { |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 63 | return readspd(spdAddress, buf, len); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 64 | } |