Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: Move EEPROM I2C adapter to amdgpu_device

Puts the i2c adapter in common place for sharing by RAS
and upcoming data read from FRU EEPROM feature.

v2:
Move i2c adapter to amdgpu_pm and rename it.

v3: Move i2c adapter init to ASIC specific code and get rid
of the switch case in amdgpu_device

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Andrey Grodzovsky and committed by
Alex Deucher
9015d60c 57210c19

+41 -50
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
··· 448 448 /* powerplay feature */ 449 449 uint32_t pp_feature; 450 450 451 + /* Used for I2C access to various EEPROMs on relevant ASICs */ 452 + struct i2c_adapter smu_i2c; 451 453 }; 452 454 453 455 #define R600_SSTU_DFLT 0
+8 -40
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c
··· 25 25 #include "amdgpu.h" 26 26 #include "amdgpu_ras.h" 27 27 #include <linux/bits.h> 28 - #include "smu_v11_0_i2c.h" 29 28 #include "atom.h" 30 29 31 30 #define EEPROM_I2C_TARGET_ADDR_VEGA20 0xA0 ··· 123 124 unsigned char *buff) 124 125 { 125 126 int ret = 0; 127 + struct amdgpu_device *adev = to_amdgpu_device(control); 126 128 struct i2c_msg msg = { 127 129 .addr = 0, 128 130 .flags = 0, ··· 137 137 138 138 msg.addr = control->i2c_address; 139 139 140 - ret = i2c_transfer(&control->eeprom_accessor, &msg, 1); 140 + ret = i2c_transfer(&adev->pm.smu_i2c, &msg, 1); 141 141 if (ret < 1) 142 142 DRM_ERROR("Failed to write EEPROM table header, ret:%d", ret); 143 143 ··· 251 251 .buf = buff, 252 252 }; 253 253 254 + /* Verify i2c adapter is initialized */ 255 + if (!adev->pm.smu_i2c.algo) 256 + return -ENOENT; 257 + 254 258 if (!__get_eeprom_i2c_addr(adev, &control->i2c_address)) 255 259 return -EINVAL; 256 260 257 261 mutex_init(&control->tbl_mutex); 258 262 259 - switch (adev->asic_type) { 260 - case CHIP_VEGA20: 261 - ret = smu_v11_0_i2c_eeprom_control_init(&control->eeprom_accessor); 262 - break; 263 - 264 - case CHIP_ARCTURUS: 265 - ret = smu_i2c_eeprom_init(&adev->smu, &control->eeprom_accessor); 266 - break; 267 - 268 - default: 269 - return 0; 270 - } 271 - 272 - if (ret) { 273 - DRM_ERROR("Failed to init I2C controller, ret:%d", ret); 274 - return ret; 275 - } 276 - 277 263 msg.addr = control->i2c_address; 278 - 279 264 /* Read/Create table header from EEPROM address 0 */ 280 - ret = i2c_transfer(&control->eeprom_accessor, &msg, 1); 265 + ret = i2c_transfer(&adev->pm.smu_i2c, &msg, 1); 281 266 if (ret < 1) { 282 267 DRM_ERROR("Failed to read EEPROM table header, ret:%d", ret); 283 268 return ret; ··· 286 301 } 287 302 288 303 return ret == 1 ? 0 : -EIO; 289 - } 290 - 291 - void amdgpu_ras_eeprom_fini(struct amdgpu_ras_eeprom_control *control) 292 - { 293 - struct amdgpu_device *adev = to_amdgpu_device(control); 294 - 295 - switch (adev->asic_type) { 296 - case CHIP_VEGA20: 297 - smu_v11_0_i2c_eeprom_control_fini(&control->eeprom_accessor); 298 - break; 299 - case CHIP_ARCTURUS: 300 - smu_i2c_eeprom_fini(&adev->smu, &control->eeprom_accessor); 301 - break; 302 - 303 - default: 304 - return; 305 - } 306 304 } 307 305 308 306 static void __encode_table_record_to_buff(struct amdgpu_ras_eeprom_control *control, ··· 444 476 control->next_addr += EEPROM_TABLE_RECORD_SIZE; 445 477 } 446 478 447 - ret = i2c_transfer(&control->eeprom_accessor, msgs, num); 479 + ret = i2c_transfer(&adev->pm.smu_i2c, msgs, num); 448 480 if (ret < 1) { 449 481 DRM_ERROR("Failed to process EEPROM table records, ret:%d", ret); 450 482
-2
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h
··· 44 44 45 45 struct amdgpu_ras_eeprom_control { 46 46 struct amdgpu_ras_eeprom_table_header tbl_hdr; 47 - struct i2c_adapter eeprom_accessor; 48 47 uint32_t next_addr; 49 48 unsigned int num_recs; 50 49 struct mutex tbl_mutex; ··· 78 79 }__attribute__((__packed__)); 79 80 80 81 int amdgpu_ras_eeprom_init(struct amdgpu_ras_eeprom_control *control); 81 - void amdgpu_ras_eeprom_fini(struct amdgpu_ras_eeprom_control *control); 82 82 int amdgpu_ras_eeprom_reset_table(struct amdgpu_ras_eeprom_control *control); 83 83 84 84 int amdgpu_ras_eeprom_process_recods(struct amdgpu_ras_eeprom_control *control,
+8 -6
drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c
··· 46 46 #define I2C_NO_STOP 1 47 47 #define I2C_RESTART 2 48 48 49 - #define to_amdgpu_device(x) (container_of(x, struct amdgpu_ras, eeprom_control.eeprom_accessor))->adev 50 - #define to_eeprom_control(x) container_of(x, struct amdgpu_ras_eeprom_control, eeprom_accessor) 49 + #define to_amdgpu_device(x) (container_of(x, struct amdgpu_device, pm.smu_i2c)) 51 50 52 51 static void smu_v11_0_i2c_set_clock_gating(struct i2c_adapter *control, bool en) 53 52 { ··· 591 592 592 593 static void lock_bus(struct i2c_adapter *i2c, unsigned int flags) 593 594 { 594 - struct amdgpu_ras_eeprom_control *control = to_eeprom_control(i2c); 595 + struct amdgpu_device *adev = to_amdgpu_device(i2c); 596 + struct amdgpu_ras_eeprom_control *control = &adev->psp.ras.ras->eeprom_control; 595 597 596 598 if (!smu_v11_0_i2c_bus_lock(i2c)) { 597 599 DRM_ERROR("Failed to lock the bus from SMU"); ··· 610 610 611 611 static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags) 612 612 { 613 - struct amdgpu_ras_eeprom_control *control = to_eeprom_control(i2c); 613 + struct amdgpu_device *adev = to_amdgpu_device(i2c); 614 + struct amdgpu_ras_eeprom_control *control = &adev->psp.ras.ras->eeprom_control; 614 615 615 616 if (!smu_v11_0_i2c_bus_unlock(i2c)) { 616 617 DRM_ERROR("Failed to unlock the bus from SMU"); ··· 631 630 struct i2c_msg *msgs, int num) 632 631 { 633 632 int i, ret; 634 - struct amdgpu_ras_eeprom_control *control = to_eeprom_control(i2c_adap); 633 + struct amdgpu_device *adev = to_amdgpu_device(i2c_adap); 634 + struct amdgpu_ras_eeprom_control *control = &adev->psp.ras.ras->eeprom_control; 635 635 636 636 if (!control->bus_locked) { 637 637 DRM_ERROR("I2C bus unlocked, stopping transaction!"); ··· 681 679 control->class = I2C_CLASS_SPD; 682 680 control->dev.parent = &adev->pdev->dev; 683 681 control->algo = &smu_v11_0_i2c_eeprom_i2c_algo; 684 - snprintf(control->name, sizeof(control->name), "RAS EEPROM"); 682 + snprintf(control->name, sizeof(control->name), "AMDGPU EEPROM"); 685 683 control->lock_ops = &smu_v11_0_i2c_i2c_lock_ops; 686 684 687 685 res = i2c_add_adapter(control);
+10
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
··· 932 932 return ret; 933 933 } 934 934 935 + if (adev->smu.ppt_funcs->i2c_eeprom_init) { 936 + ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c); 937 + 938 + if (ret) 939 + return ret; 940 + } 941 + 935 942 return 0; 936 943 } 937 944 ··· 947 940 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 948 941 struct smu_context *smu = &adev->smu; 949 942 int ret; 943 + 944 + if (adev->smu.ppt_funcs->i2c_eeprom_fini) 945 + smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c); 950 946 951 947 kfree(smu->irq_source); 952 948 smu->irq_source = NULL;
+2 -2
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
··· 41 41 #include <linux/pci.h> 42 42 #include "amdgpu_ras.h" 43 43 44 - #define to_amdgpu_device(x) (container_of(x, struct amdgpu_ras, eeprom_control.eeprom_accessor))->adev 44 + #define to_amdgpu_device(x) (container_of(x, struct amdgpu_device, pm.smu_i2c)) 45 45 46 46 #define CTF_OFFSET_EDGE 5 47 47 #define CTF_OFFSET_HOTSPOT 5 ··· 2190 2190 control->class = I2C_CLASS_SPD; 2191 2191 control->dev.parent = &adev->pdev->dev; 2192 2192 control->algo = &arcturus_i2c_eeprom_i2c_algo; 2193 - snprintf(control->name, sizeof(control->name), "RAS EEPROM"); 2193 + snprintf(control->name, sizeof(control->name), "AMDGPU EEPROM"); 2194 2194 2195 2195 res = i2c_add_adapter(control); 2196 2196 if (res)
+11
drivers/gpu/drm/amd/powerplay/smumgr/vega20_smumgr.c
··· 33 33 #include "smu7_smumgr.h" 34 34 #include "vega20_hwmgr.h" 35 35 36 + #include "smu_v11_0_i2c.h" 37 + 36 38 /* MP Apertures */ 37 39 #define MP0_Public 0x03800000 38 40 #define MP0_SRAM 0x03900000 ··· 408 406 struct vega20_smumgr *priv; 409 407 unsigned long tools_size = 0x19000; 410 408 int ret = 0; 409 + struct amdgpu_device *adev = hwmgr->adev; 411 410 412 411 struct cgs_firmware_info info = {0}; 413 412 ··· 508 505 priv->smu_tables.entry[TABLE_ACTIVITY_MONITOR_COEFF].version = 0x01; 509 506 priv->smu_tables.entry[TABLE_ACTIVITY_MONITOR_COEFF].size = sizeof(DpmActivityMonitorCoeffInt_t); 510 507 508 + ret = smu_v11_0_i2c_eeprom_control_init(&adev->pm.smu_i2c); 509 + if (ret) 510 + goto err4; 511 + 511 512 return 0; 512 513 513 514 err4: ··· 544 537 { 545 538 struct vega20_smumgr *priv = 546 539 (struct vega20_smumgr *)(hwmgr->smu_backend); 540 + struct amdgpu_device *adev = hwmgr->adev; 541 + 542 + smu_v11_0_i2c_eeprom_control_fini(&adev->pm.smu_i2c); 547 543 548 544 if (priv) { 549 545 amdgpu_bo_free_kernel(&priv->smu_tables.entry[TABLE_PPTABLE].handle, ··· 570 560 kfree(hwmgr->smu_backend); 571 561 hwmgr->smu_backend = NULL; 572 562 } 563 + 573 564 return 0; 574 565 } 575 566