smu_i2c_eeprom_init may be invoked twice or more under sroiv mode, while we don't want to add check if (!amdgpu_sriov_vf) before we invoke smu_i2c_eeprom_init/fini each time, so we check if i2c adapter is already added before we invoke i2c_add_adapter Signed-off-by: Wenhui Sheng <Wenhui.Sheng@xxxxxxx> Change-Id: I3500ff474e0f04ea6bd4f9adf9f97b159443dfd9 Reviewed-by: Hawking Zhang <Hawking.Zhang@xxxxxxx> --- drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 24 +++++++------------- drivers/gpu/drm/amd/powerplay/arcturus_ppt.c | 14 ++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c index 1e9be1dcc62b..8ce907280dc9 100644 --- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c +++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c @@ -1354,11 +1354,9 @@ static int smu_hw_init(void *handle) if (ret) goto failed; - if (!amdgpu_sriov_vf(adev)) { - ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c); - if (ret) - goto failed; - } + ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c); + if (ret) + goto failed; adev->pm.dpm_enabled = true; @@ -1396,9 +1394,7 @@ static int smu_hw_fini(void *handle) adev->pm.dpm_enabled = false; - if (!amdgpu_sriov_vf(adev)) { - smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c); - } + smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c); ret = smu_stop_thermal_control(smu); if (ret) { @@ -1539,9 +1535,7 @@ static int smu_suspend(void *handle) adev->pm.dpm_enabled = false; - if (!amdgpu_sriov_vf(adev)) { - smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c); - } + smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c); ret = smu_disable_dpm(smu); if (ret) @@ -1586,11 +1580,9 @@ static int smu_resume(void *handle) if (ret) goto failed; - if (!amdgpu_sriov_vf(adev)) { - ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c); - if (ret) - goto failed; - } + ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c); + if (ret) + goto failed; if (smu->is_apu) smu_set_gfx_cgpg(&adev->smu, true); diff --git a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c index 70cc1c12f196..437f8a317838 100644 --- a/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c +++ b/drivers/gpu/drm/amd/powerplay/arcturus_ppt.c @@ -2224,11 +2224,22 @@ static const struct i2c_algorithm arcturus_i2c_eeprom_i2c_algo = { .functionality = arcturus_i2c_eeprom_i2c_func, }; +static bool arcturus_i2c_adapter_is_added(struct i2c_adapter *control) +{ + struct amdgpu_device *adev = to_amdgpu_device(control); + + return control->dev.parent == &adev->pdev->dev ? true : false; +} + static int arcturus_i2c_eeprom_control_init(struct i2c_adapter *control) { struct amdgpu_device *adev = to_amdgpu_device(control); int res; + /* smu_i2c_eeprom_init may be called twice in sriov */ + if (arcturus_i2c_adapter_is_added(control)) + return 0; + control->owner = THIS_MODULE; control->class = I2C_CLASS_SPD; control->dev.parent = &adev->pdev->dev; @@ -2244,6 +2255,9 @@ static int arcturus_i2c_eeprom_control_init(struct i2c_adapter *control) static void arcturus_i2c_eeprom_control_fini(struct i2c_adapter *control) { + if (!arcturus_i2c_adapter_is_added(control)) + return; + i2c_del_adapter(control); } -- 2.17.1 _______________________________________________ amd-gfx mailing list amd-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/amd-gfx