Skip to content

Commit 3364c0e

Browse files
dabros-janwsakernel
authored andcommitted
i2c: designware: Remove code duplication
Simplify code by moving common part to one function. Signed-off-by: Jan Dabros <[email protected]> Suggested-by: Andy Shevchenko <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Jarkko Nikula <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 8b6d8d0 commit 3364c0e

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

drivers/i2c/busses/i2c-designware-amdpsp.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,28 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
214214
PSP_I2C_REQ_RETRY_DELAY_US,
215215
PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
216216
0, req);
217-
if (ret)
217+
if (ret) {
218+
dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
219+
(i2c_req_type == PSP_I2C_REQ_ACQUIRE) ?
220+
"release" : "acquire");
218221
goto cleanup;
222+
}
219223

220224
ret = status;
221-
if (ret)
225+
if (ret) {
226+
dev_err(psp_i2c_dev, "PSP communication error\n");
222227
goto cleanup;
228+
}
223229

224230
dev_dbg(psp_i2c_dev, "Request accepted by PSP after %ums\n",
225231
jiffies_to_msecs(jiffies - start));
226232

227233
cleanup:
234+
if (ret) {
235+
dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n");
236+
psp_i2c_mbox_fail = true;
237+
}
238+
228239
kfree(req);
229240
return ret;
230241
}
@@ -249,16 +260,8 @@ static int psp_acquire_i2c_bus(void)
249260
}
250261

251262
status = psp_send_i2c_req(PSP_I2C_REQ_ACQUIRE);
252-
if (status) {
253-
if (status == -ETIMEDOUT)
254-
dev_err(psp_i2c_dev, "Timed out waiting for PSP to release I2C bus\n");
255-
else
256-
dev_err(psp_i2c_dev, "PSP communication error\n");
257-
258-
dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n");
259-
psp_i2c_mbox_fail = true;
263+
if (status)
260264
goto cleanup;
261-
}
262265

263266
psp_i2c_sem_acquired = jiffies;
264267
psp_i2c_access_count++;
@@ -294,16 +297,8 @@ static void psp_release_i2c_bus(void)
294297

295298
/* Send a release command to PSP */
296299
status = psp_send_i2c_req(PSP_I2C_REQ_RELEASE);
297-
if (status) {
298-
if (status == -ETIMEDOUT)
299-
dev_err(psp_i2c_dev, "Timed out waiting for PSP to acquire I2C bus\n");
300-
else
301-
dev_err(psp_i2c_dev, "PSP communication error\n");
302-
303-
dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n");
304-
psp_i2c_mbox_fail = true;
300+
if (status)
305301
goto cleanup;
306-
}
307302

308303
dev_dbg(psp_i2c_dev, "PSP semaphore held for %ums\n",
309304
jiffies_to_msecs(jiffies - psp_i2c_sem_acquired));

0 commit comments

Comments
 (0)