summaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJan Dabros <jsd@semihalf.com>2022-03-14 10:03:23 +0100
committerWolfram Sang <wsa@kernel.org>2022-03-18 11:38:43 +0100
commit3364c0ef8732694084f8238ffd9c62819209fd7f (patch)
tree2eff830d2c0760e4685c227ce4e653c7b3a1e89e /drivers/i2c
parent8b6d8d00a46a12a4baa08d547d4231e50a558254 (diff)
downloadlinux-3364c0ef8732694084f8238ffd9c62819209fd7f.tar.bz2
i2c: designware: Remove code duplication
Simplify code by moving common part to one function. Signed-off-by: Jan Dabros <jsd@semihalf.com> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-designware-amdpsp.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c
index 3844695e6bf3..9b37f2b95abc 100644
--- a/drivers/i2c/busses/i2c-designware-amdpsp.c
+++ b/drivers/i2c/busses/i2c-designware-amdpsp.c
@@ -214,17 +214,28 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
PSP_I2C_REQ_RETRY_DELAY_US,
PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
0, req);
- if (ret)
+ if (ret) {
+ dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
+ (i2c_req_type == PSP_I2C_REQ_ACQUIRE) ?
+ "release" : "acquire");
goto cleanup;
+ }
ret = status;
- if (ret)
+ if (ret) {
+ dev_err(psp_i2c_dev, "PSP communication error\n");
goto cleanup;
+ }
dev_dbg(psp_i2c_dev, "Request accepted by PSP after %ums\n",
jiffies_to_msecs(jiffies - start));
cleanup:
+ if (ret) {
+ dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n");
+ psp_i2c_mbox_fail = true;
+ }
+
kfree(req);
return ret;
}
@@ -249,16 +260,8 @@ static int psp_acquire_i2c_bus(void)
}
status = psp_send_i2c_req(PSP_I2C_REQ_ACQUIRE);
- if (status) {
- if (status == -ETIMEDOUT)
- dev_err(psp_i2c_dev, "Timed out waiting for PSP to release I2C bus\n");
- else
- dev_err(psp_i2c_dev, "PSP communication error\n");
-
- dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n");
- psp_i2c_mbox_fail = true;
+ if (status)
goto cleanup;
- }
psp_i2c_sem_acquired = jiffies;
psp_i2c_access_count++;
@@ -294,16 +297,8 @@ static void psp_release_i2c_bus(void)
/* Send a release command to PSP */
status = psp_send_i2c_req(PSP_I2C_REQ_RELEASE);
- if (status) {
- if (status == -ETIMEDOUT)
- dev_err(psp_i2c_dev, "Timed out waiting for PSP to acquire I2C bus\n");
- else
- dev_err(psp_i2c_dev, "PSP communication error\n");
-
- dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n");
- psp_i2c_mbox_fail = true;
+ if (status)
goto cleanup;
- }
dev_dbg(psp_i2c_dev, "PSP semaphore held for %ums\n",
jiffies_to_msecs(jiffies - psp_i2c_sem_acquired));