Skip to content

Commit 9058cb7

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

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,38 +3145,23 @@ static int navi10_i2c_control_init(struct smu_context *smu)
31453145
control->quirks = &navi10_i2c_control_quirks;
31463146
i2c_set_adapdata(control, smu_i2c);
31473147

3148-
res = i2c_add_adapter(control);
3148+
res = devm_i2c_add_adapter(adev->dev, control);
31493149
if (res) {
31503150
DRM_ERROR("Failed to register hw i2c, err: %d\n", res);
3151-
goto Out_err;
3151+
return res;
31523152
}
31533153
}
31543154

31553155
adev->pm.ras_eeprom_i2c_bus = &adev->pm.smu_i2c[0].adapter;
31563156
adev->pm.fru_eeprom_i2c_bus = &adev->pm.smu_i2c[1].adapter;
31573157

31583158
return 0;
3159-
Out_err:
3160-
for ( ; i >= 0; i--) {
3161-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
3162-
struct i2c_adapter *control = &smu_i2c->adapter;
3163-
3164-
i2c_del_adapter(control);
3165-
}
3166-
return res;
31673159
}
31683160

31693161
static void navi10_i2c_control_fini(struct smu_context *smu)
31703162
{
31713163
struct amdgpu_device *adev = smu->adev;
3172-
int i;
31733164

3174-
for (i = 0; i < MAX_SMU_I2C_BUSES; i++) {
3175-
struct amdgpu_smu_i2c_bus *smu_i2c = &adev->pm.smu_i2c[i];
3176-
struct i2c_adapter *control = &smu_i2c->adapter;
3177-
3178-
i2c_del_adapter(control);
3179-
}
31803165
adev->pm.ras_eeprom_i2c_bus = NULL;
31813166
adev->pm.fru_eeprom_i2c_bus = NULL;
31823167
}

0 commit comments

Comments
 (0)