From: Jan Dabros <jsd@semihalf.com>
To: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com
Cc: wsa@kernel.org, upstream@semihalf.com, jsd@semihalf.com
Subject: [PATCH -next] i2c: designware: Add helper to remove redundancy
Date: Thu, 10 Mar 2022 15:22:36 +0100 [thread overview]
Message-ID: <20220310142236.192811-1-jsd@semihalf.com> (raw)
Simplify code by adding an extra static function for sending I2C
requests and verifying results.
Signed-off-by: Jan Dabros <jsd@semihalf.com>
---
drivers/i2c/busses/i2c-designware-amdpsp.c | 44 ++++++++++++----------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c
index c64e459afb5c..cc758792f150 100644
--- a/drivers/i2c/busses/i2c-designware-amdpsp.c
+++ b/drivers/i2c/busses/i2c-designware-amdpsp.c
@@ -229,6 +229,26 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
return ret;
}
+static int psp_send_i2c_req_check_err(enum psp_i2c_req_type request)
+{
+ int status;
+
+ status = psp_send_i2c_req(request);
+ if (status) {
+ if (status == -ETIMEDOUT)
+ dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
+ (request == PSP_I2C_REQ_ACQUIRE) ?
+ "release" : "acquire");
+ 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;
+ }
+
+ return status;
+}
+
static int psp_acquire_i2c_bus(void)
{
int status;
@@ -248,17 +268,9 @@ static int psp_acquire_i2c_bus(void)
goto cleanup;
};
- 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;
+ status = psp_send_i2c_req_check_err(PSP_I2C_REQ_ACQUIRE);
+ if (status)
goto cleanup;
- }
psp_i2c_sem_acquired = jiffies;
psp_i2c_access_count++;
@@ -293,17 +305,9 @@ static void psp_release_i2c_bus(void)
goto cleanup;
/* 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;
+ status = psp_send_i2c_req_check_err(PSP_I2C_REQ_RELEASE);
+ if (status)
goto cleanup;
- }
dev_dbg(psp_i2c_dev, "PSP semaphore held for %ums\n",
jiffies_to_msecs(jiffies - psp_i2c_sem_acquired));
--
2.35.1.616.g0bdcbb4464-goog
next reply other threads:[~2022-03-10 14:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-10 14:22 Jan Dabros [this message]
2022-03-10 14:52 ` [PATCH -next] i2c: designware: Add helper to remove redundancy Jarkko Nikula
2022-03-10 21:57 ` Jan Dąbroś
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220310142236.192811-1-jsd@semihalf.com \
--to=jsd@semihalf.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jarkko.nikula@linux.intel.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=upstream@semihalf.com \
--cc=wsa@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox