Skip to content

Commit 49e957b

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

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,10 +2087,10 @@ static int smu_v14_0_2_i2c_control_init(struct smu_context *smu)
20872087
control->quirks = &smu_v14_0_2_i2c_control_quirks;
20882088
i2c_set_adapdata(control, smu_i2c);
20892089

2090-
res = i2c_add_adapter(control);
2090+
res = devm_i2c_add_adapter(adev->dev, control);
20912091
if (res) {
20922092
DRM_ERROR("Failed to register hw i2c, err: %d\n", res);
2093-
goto Out_err;
2093+
return res;
20942094
}
20952095
}
20962096

@@ -2100,27 +2100,12 @@ static int smu_v14_0_2_i2c_control_init(struct smu_context *smu)
21002100
adev->pm.fru_eeprom_i2c_bus = &adev->pm.smu_i2c[0].adapter;
21012101

21022102
return 0;
2103-
Out_err:
2104-
for ( ; i >= 0; i--) {
2105-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
2106-
struct i2c_adapter *control = &smu_i2c->adapter;
2107-
2108-
i2c_del_adapter(control);
2109-
}
2110-
return res;
21112103
}
21122104

21132105
static void smu_v14_0_2_i2c_control_fini(struct smu_context *smu)
21142106
{
21152107
struct amdgpu_device *adev = smu->adev;
2116-
int i;
21172108

2118-
for (i = 0; i < MAX_SMU_I2C_BUSES; i++) {
2119-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
2120-
struct i2c_adapter *control = &smu_i2c->adapter;
2121-
2122-
i2c_del_adapter(control);
2123-
}
21242109
adev->pm.ras_eeprom_i2c_bus = NULL;
21252110
adev->pm.fru_eeprom_i2c_bus = NULL;
21262111
}

0 commit comments

Comments
 (0)