Skip to content

Commit 4970883

Browse files
rodrigosiqueiraalexdeucher
authored andcommitted
drm/amd/pm: Use devm_i2c_add_adapter() in the V13 smu
The I2C init for SMU_V13 uses i2c_add_adapter() and i2c_del_adapter(), this commit replaces the use of these two functions with devm_i2c_add_adapter(). Notice that SMU_V13 init initializes multiple I2C buses in a loop; if something goes wrong, the previous adapters are removed, and the amdgpu load is interrupted. Since I2C init is required for the correct load of amdgpu, it is safe to rely on devm_i2c_add_adapter() to handle any previously initialized I2C adapter. Signed-off-by: Rodrigo Siqueira <siqueira@igalia.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 13f785d commit 4970883

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,10 +2825,10 @@ static int smu_v13_0_0_i2c_control_init(struct smu_context *smu)
28252825
control->quirks = &smu_v13_0_0_i2c_control_quirks;
28262826
i2c_set_adapdata(control, smu_i2c);
28272827

2828-
res = i2c_add_adapter(control);
2828+
res = devm_i2c_add_adapter(adev->dev, control);
28292829
if (res) {
28302830
DRM_ERROR("Failed to register hw i2c, err: %d\n", res);
2831-
goto Out_err;
2831+
return res;
28322832
}
28332833
}
28342834

@@ -2838,27 +2838,12 @@ static int smu_v13_0_0_i2c_control_init(struct smu_context *smu)
28382838
adev->pm.fru_eeprom_i2c_bus = &adev->pm.smu_i2c[0].adapter;
28392839

28402840
return 0;
2841-
Out_err:
2842-
for ( ; i >= 0; i--) {
2843-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
2844-
struct i2c_adapter *control = &smu_i2c->adapter;
2845-
2846-
i2c_del_adapter(control);
2847-
}
2848-
return res;
28492841
}
28502842

28512843
static void smu_v13_0_0_i2c_control_fini(struct smu_context *smu)
28522844
{
28532845
struct amdgpu_device *adev = smu->adev;
2854-
int i;
28552846

2856-
for (i = 0; i < MAX_SMU_I2C_BUSES; i++) {
2857-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
2858-
struct i2c_adapter *control = &smu_i2c->adapter;
2859-
2860-
i2c_del_adapter(control);
2861-
}
28622847
adev->pm.ras_eeprom_i2c_bus = NULL;
28632848
adev->pm.fru_eeprom_i2c_bus = NULL;
28642849
}

0 commit comments

Comments
 (0)