Skip to content

Commit c32da00

Browse files
rodrigosiqueiraalexdeucher
authored andcommitted
drm/amd/pm: Use devm_i2c_add_adapter() in the V13_0_6 smu
The I2C init for V13_0_6 uses i2c_add_adapter() and i2c_del_adapter(), this commit replaces the use of these two functions with devm_i2c_add_adapter(). Notice that V13_0_6 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 4970883 commit c32da00

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_6_ppt.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,38 +2494,23 @@ static int smu_v13_0_6_i2c_control_init(struct smu_context *smu)
24942494
control->quirks = &smu_v13_0_6_i2c_control_quirks;
24952495
i2c_set_adapdata(control, smu_i2c);
24962496

2497-
res = i2c_add_adapter(control);
2497+
res = devm_i2c_add_adapter(adev->dev, control);
24982498
if (res) {
24992499
DRM_ERROR("Failed to register hw i2c, err: %d\n", res);
2500-
goto Out_err;
2500+
return res;
25012501
}
25022502
}
25032503

25042504
adev->pm.ras_eeprom_i2c_bus = &adev->pm.smu_i2c[0].adapter;
25052505
adev->pm.fru_eeprom_i2c_bus = &adev->pm.smu_i2c[0].adapter;
25062506

25072507
return 0;
2508-
Out_err:
2509-
for ( ; i >= 0; i--) {
2510-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
2511-
struct i2c_adapter *control = &smu_i2c->adapter;
2512-
2513-
i2c_del_adapter(control);
2514-
}
2515-
return res;
25162508
}
25172509

25182510
static void smu_v13_0_6_i2c_control_fini(struct smu_context *smu)
25192511
{
25202512
struct amdgpu_device *adev = smu->adev;
2521-
int i;
25222513

2523-
for (i = 0; i < MAX_SMU_I2C_BUSES; i++) {
2524-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
2525-
struct i2c_adapter *control = &smu_i2c->adapter;
2526-
2527-
i2c_del_adapter(control);
2528-
}
25292514
adev->pm.ras_eeprom_i2c_bus = NULL;
25302515
adev->pm.fru_eeprom_i2c_bus = NULL;
25312516
}

0 commit comments

Comments
 (0)