2 * Copyright 2019 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include <linux/pci.h>
26 #include "amdgpu_i2c.h"
27 #include "smu_v11_0_i2c.h"
30 #define I2C_PRODUCT_INFO_ADDR 0xAC
31 #define I2C_PRODUCT_INFO_ADDR_SIZE 0x2
32 #define I2C_PRODUCT_INFO_OFFSET 0xC0
34 bool is_fru_eeprom_supported(struct amdgpu_device *adev)
36 /* TODO: Gaming SKUs don't have the FRU EEPROM.
37 * Use this hack to address hangs on modprobe on gaming SKUs
38 * until a proper solution can be implemented by only supporting
39 * the explicit chip IDs for VG20 Server cards
41 * TODO: Add list of supported Arcturus DIDs once confirmed
43 if ((adev->asic_type == CHIP_VEGA20 && adev->pdev->device == 0x66a0) ||
44 (adev->asic_type == CHIP_VEGA20 && adev->pdev->device == 0x66a1) ||
45 (adev->asic_type == CHIP_VEGA20 && adev->pdev->device == 0x66a4))
50 int amdgpu_fru_read_eeprom(struct amdgpu_device *adev, uint32_t addrptr,
54 struct i2c_msg msg = {
55 .addr = I2C_PRODUCT_INFO_ADDR,
61 msg.len = I2C_PRODUCT_INFO_ADDR_SIZE + 1;
62 ret = i2c_transfer(&adev->pm.smu_i2c, &msg, 1);
65 DRM_WARN("FRU: Failed to get size field");
69 /* The size returned by the i2c requires subtraction of 0xC0 since the
70 * size apparently always reports as 0xC0+actual size.
72 size = buff[2] - I2C_PRODUCT_INFO_OFFSET;
73 /* Add 1 since address field was 1 byte */
74 buff[1] = addrptr + 1;
76 msg.len = I2C_PRODUCT_INFO_ADDR_SIZE + size;
77 ret = i2c_transfer(&adev->pm.smu_i2c, &msg, 1);
80 DRM_WARN("FRU: Failed to get data field");
87 int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
89 unsigned char buff[34];
90 int addrptr = 0, size = 0;
92 if (!is_fru_eeprom_supported(adev))
95 /* If algo exists, it means that the i2c_adapter's initialized */
96 if (!adev->pm.smu_i2c.algo) {
97 DRM_WARN("Cannot access FRU, EEPROM accessor not initialized");
101 /* There's a lot of repetition here. This is due to the FRU having
102 * variable-length fields. To get the information, we have to find the
103 * size of each field, and then keep reading along and reading along
104 * until we get all of the data that we want. We use addrptr to track
105 * the address as we go
108 /* The first fields are all of size 1-byte, from 0-7 are offsets that
109 * contain information that isn't useful to us.
110 * Bytes 8-a are all 1-byte and refer to the size of the entire struct,
111 * and the language field, so just start from 0xb, manufacturer size
114 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
116 DRM_ERROR("Failed to read FRU Manufacturer, ret:%d", size);
120 /* Increment the addrptr by the size of the field, and 1 due to the
121 * size field being 1 byte. This pattern continues below.
124 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
126 DRM_ERROR("Failed to read FRU product name, ret:%d", size);
130 /* Product name should only be 32 characters. Any more,
131 * and something could be wrong. Cap it at 32 to be safe
134 DRM_WARN("FRU Product Number is larger than 32 characters. This is likely a mistake");
137 /* Start at 2 due to buff using fields 0 and 1 for the address */
138 memcpy(adev->product_name, &buff[2], size);
139 adev->product_name[size] = '\0';
142 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
144 DRM_ERROR("Failed to read FRU product number, ret:%d", size);
148 /* Product number should only be 16 characters. Any more,
149 * and something could be wrong. Cap it at 16 to be safe
152 DRM_WARN("FRU Product Number is larger than 16 characters. This is likely a mistake");
155 memcpy(adev->product_number, &buff[2], size);
156 adev->product_number[size] = '\0';
159 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
162 DRM_ERROR("Failed to read FRU product version, ret:%d", size);
167 size = amdgpu_fru_read_eeprom(adev, addrptr, buff);
170 DRM_ERROR("Failed to read FRU serial number, ret:%d", size);
174 /* Serial number should only be 16 characters. Any more,
175 * and something could be wrong. Cap it at 16 to be safe
178 DRM_WARN("FRU Serial Number is larger than 16 characters. This is likely a mistake");
181 memcpy(adev->serial, &buff[2], size);
182 adev->serial[size] = '\0';