diff mbox series

[v2,2/2] i2c: i2c-qcom-geni: Simplify tx/rx functions

Message ID 20180920180323.217377-3-swboyd@chromium.org (mailing list archive)
State Not Applicable, archived
Delegated to: Andy Gross
Headers show
Series Fix qcom geni i2c DMA handling | expand

Commit Message

Stephen Boyd Sept. 20, 2018, 6:03 p.m. UTC
We never really look at the 'ret' local variable in these functions, so
let's remove it to make way for shorter and simpler code. Furthermore,
we can shorten some lines by adding two local variables for the SE and
the message length so that everything fits in 80 columns. And kernel
style is to leave the return statement by itself, detached from the rest
of the function.

Cc: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
Cc: Sagar Dharia <sdharia@codeaurora.org>
Cc: Girish Mahadevan <girishm@codeaurora.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/i2c/busses/i2c-qcom-geni.c | 54 ++++++++++++++----------------
 1 file changed, 25 insertions(+), 29 deletions(-)

Comments

Doug Anderson Sept. 20, 2018, 8:22 p.m. UTC | #1
Hi,
On Thu, Sep 20, 2018 at 11:03 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
> We never really look at the 'ret' local variable in these functions, so
> let's remove it to make way for shorter and simpler code. Furthermore,
> we can shorten some lines by adding two local variables for the SE and
> the message length so that everything fits in 80 columns. And kernel
> style is to leave the return statement by itself, detached from the rest
> of the function.
>
> Cc: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
> Cc: Sagar Dharia <sdharia@codeaurora.org>
> Cc: Girish Mahadevan <girishm@codeaurora.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  drivers/i2c/busses/i2c-qcom-geni.c | 54 ++++++++++++++----------------
>  1 file changed, 25 insertions(+), 29 deletions(-)

I didn't hate the old code, but you're right that this looks a little better.

Reviewed-by: Douglas Anderson <dianders@chromium.org>

NOTE: now that you're cleaning it up, I'd personally go even further
and totally get rid of the "mode" local variable.  Basically, just:

dma_buf = i2c_get_dma_safe_msg_buf(msg, 32);
if (dma_buf)
  geni_se_select_mode(se, GENI_SE_DMA);
else
  geni_se_select_mode(se, GENI_SE_FIFO);

...elsewhere just continue to use "dma_buf" being NULL to mean FIFO if
you have to fall back to the FIFO case you set dma_buf to NULL after
calling i2c_put_dma_safe_msg_buf() to indicate to later code that
you're in FIFO mode.

I prototyped this up and the net-net is one fewer line of code and
also the nice consistency that you never hold dma_buf in a pointer
after you've freed it.

-Doug
Stephen Boyd Sept. 20, 2018, 10:18 p.m. UTC | #2
Quoting Doug Anderson (2018-09-20 13:22:37)
> Hi,
> On Thu, Sep 20, 2018 at 11:03 AM Stephen Boyd <swboyd@chromium.org> wrote:
> >
> > We never really look at the 'ret' local variable in these functions, so
> > let's remove it to make way for shorter and simpler code. Furthermore,
> > we can shorten some lines by adding two local variables for the SE and
> > the message length so that everything fits in 80 columns. And kernel
> > style is to leave the return statement by itself, detached from the rest
> > of the function.
> >
> > Cc: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
> > Cc: Sagar Dharia <sdharia@codeaurora.org>
> > Cc: Girish Mahadevan <girishm@codeaurora.org>
> > Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> > ---
> >  drivers/i2c/busses/i2c-qcom-geni.c | 54 ++++++++++++++----------------
> >  1 file changed, 25 insertions(+), 29 deletions(-)
> 
> I didn't hate the old code, but you're right that this looks a little better.
> 
> Reviewed-by: Douglas Anderson <dianders@chromium.org>
> 
> NOTE: now that you're cleaning it up, I'd personally go even further
> and totally get rid of the "mode" local variable.  Basically, just:
> 
> dma_buf = i2c_get_dma_safe_msg_buf(msg, 32);
> if (dma_buf)
>   geni_se_select_mode(se, GENI_SE_DMA);
> else
>   geni_se_select_mode(se, GENI_SE_FIFO);

Sure that's fine. I'll resend this one patch with that squashed in.
Wolfram Sang Sept. 24, 2018, 10:13 p.m. UTC | #3
> Sure that's fine. I'll resend this one patch with that squashed in.

Waiting for this resend.
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index 9f2eb02481d3..1215bb21c9f1 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -368,6 +368,8 @@  static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 	enum geni_se_xfer_mode mode;
 	unsigned long time_left = XFER_TIMEOUT;
 	void *dma_buf;
+	struct geni_se *se = &gi2c->se;
+	size_t len = msg->len;
 
 	gi2c->cur = msg;
 	mode = GENI_SE_FIFO;
@@ -375,19 +377,14 @@  static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 	if (dma_buf)
 		mode = GENI_SE_DMA;
 
-	geni_se_select_mode(&gi2c->se, mode);
-	writel_relaxed(msg->len, gi2c->se.base + SE_I2C_RX_TRANS_LEN);
-	geni_se_setup_m_cmd(&gi2c->se, I2C_READ, m_param);
-	if (mode == GENI_SE_DMA) {
-		int ret;
-
-		ret = geni_se_rx_dma_prep(&gi2c->se, dma_buf, msg->len,
-								&rx_dma);
-		if (ret) {
-			mode = GENI_SE_FIFO;
-			geni_se_select_mode(&gi2c->se, mode);
-			i2c_put_dma_safe_msg_buf(dma_buf, msg, false);
-		}
+	geni_se_select_mode(se, mode);
+	writel_relaxed(len, se->base + SE_I2C_RX_TRANS_LEN);
+	geni_se_setup_m_cmd(se, I2C_READ, m_param);
+
+	if (dma_buf && geni_se_rx_dma_prep(se, dma_buf, len, &rx_dma)) {
+		mode = GENI_SE_FIFO;
+		geni_se_select_mode(se, mode);
+		i2c_put_dma_safe_msg_buf(dma_buf, msg, false);
 	}
 
 	time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
@@ -398,9 +395,10 @@  static int geni_i2c_rx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 	if (mode == GENI_SE_DMA) {
 		if (gi2c->err)
 			geni_i2c_rx_fsm_rst(gi2c);
-		geni_se_rx_dma_unprep(&gi2c->se, rx_dma, msg->len);
+		geni_se_rx_dma_unprep(se, rx_dma, len);
 		i2c_put_dma_safe_msg_buf(dma_buf, msg, !gi2c->err);
 	}
+
 	return gi2c->err;
 }
 
@@ -411,6 +409,8 @@  static int geni_i2c_tx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 	enum geni_se_xfer_mode mode;
 	unsigned long time_left;
 	void *dma_buf;
+	struct geni_se *se = &gi2c->se;
+	size_t len = msg->len;
 
 	gi2c->cur = msg;
 	mode = GENI_SE_FIFO;
@@ -418,23 +418,18 @@  static int geni_i2c_tx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 	if (dma_buf)
 		mode = GENI_SE_DMA;
 
-	geni_se_select_mode(&gi2c->se, mode);
-	writel_relaxed(msg->len, gi2c->se.base + SE_I2C_TX_TRANS_LEN);
-	geni_se_setup_m_cmd(&gi2c->se, I2C_WRITE, m_param);
-	if (mode == GENI_SE_DMA) {
-		int ret;
-
-		ret = geni_se_tx_dma_prep(&gi2c->se, dma_buf, msg->len,
-								&tx_dma);
-		if (ret) {
-			mode = GENI_SE_FIFO;
-			geni_se_select_mode(&gi2c->se, mode);
-			i2c_put_dma_safe_msg_buf(dma_buf, msg, false);
-		}
+	geni_se_select_mode(se, mode);
+	writel_relaxed(len, se->base + SE_I2C_TX_TRANS_LEN);
+	geni_se_setup_m_cmd(se, I2C_WRITE, m_param);
+
+	if (dma_buf && geni_se_tx_dma_prep(se, dma_buf, len, &tx_dma)) {
+		mode = GENI_SE_FIFO;
+		geni_se_select_mode(se, mode);
+		i2c_put_dma_safe_msg_buf(dma_buf, msg, false);
 	}
 
 	if (mode == GENI_SE_FIFO) /* Get FIFO IRQ */
-		writel_relaxed(1, gi2c->se.base + SE_GENI_TX_WATERMARK_REG);
+		writel_relaxed(1, se->base + SE_GENI_TX_WATERMARK_REG);
 
 	time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT);
 	if (!time_left)
@@ -444,9 +439,10 @@  static int geni_i2c_tx_one_msg(struct geni_i2c_dev *gi2c, struct i2c_msg *msg,
 	if (mode == GENI_SE_DMA) {
 		if (gi2c->err)
 			geni_i2c_tx_fsm_rst(gi2c);
-		geni_se_tx_dma_unprep(&gi2c->se, tx_dma, msg->len);
+		geni_se_tx_dma_unprep(se, tx_dma, len);
 		i2c_put_dma_safe_msg_buf(dma_buf, msg, !gi2c->err);
 	}
+
 	return gi2c->err;
 }