Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp640010imm; Thu, 4 Oct 2018 00:29:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV63jf7ub/fZ3Cy4gGVP4cHMFw1cj2/t12Ex9LbV9Ft/nD6YbKvbAjJPJQdaxejLL9CAV84/F X-Received: by 2002:a63:2251:: with SMTP id t17-v6mr4488797pgm.275.1538638154247; Thu, 04 Oct 2018 00:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538638154; cv=none; d=google.com; s=arc-20160816; b=hkm+MnuXtk9XvYwF7rrJlOh2zsE2a+qgTIl0jFW9x4rUFHkGDfEo1CmtjodrsCevpY GXFwZV7YG6zoE7YUWmRzg3Fd0S8fg/2CduiSsBAJeomu5IIvSNa3dmF2m0PvIP7bmsFm 3qXv4P8RvewMhQwr9SJsbbmaxN3v/i7Xp8rNBuLGE/b03Dgbj2GtakKbZLnGBdmU9Vh8 CC79JftYc+R5GLgxMZ6gUbYT9rvs4QuIhGqNZy0J3oqa0FoTFJOm6gGZ1KIzL5EcGjH4 r1yIIELuEMTegS8KdfvsUAK58KR5oZiHmGpTvBYKcIQMbKvZ18esSCwfecpXCvgDJHtE 03Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature; bh=nBrO/am1h8ObpTyE5KsGkLNtk90DBk2KLx45qFa9k48=; b=psiqyUkVsYw/taFl2sZGGxj/eumA0JLFVbFbUI0dsfkSYIRJ8YbyFrfJiIv7ZF7TrV eur4dSU/B4aI03plj3tFkBuwl5JqRmCrGX+0IAVjhm868uV1bpSJXmtrK6ITHI1lAZTt 8EHD0DgQy4AK0xh5fz54svSozJwNXIymrzsYBCvFrSlKJotV6yhDf1X4fCTau1mpFJjw +gW8kxE7tZYuF9JWntlSYAZlYPlrULo6OiSv5K8M3kz9ba5g+KtV/pol90NzsS5q/aTg TO3tuWgKzxKAByy11YvtxkBQe3Q9JBmLoqpJxGnfkWkY1Tu29OXq78aj9IKoiKBpM52D or4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="h4si3o/d"; dkim=pass header.i=@codeaurora.org header.s=default header.b=fLyo44Eb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3-v6si4341905pld.281.2018.10.04.00.28.58; Thu, 04 Oct 2018 00:29:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="h4si3o/d"; dkim=pass header.i=@codeaurora.org header.s=default header.b=fLyo44Eb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727354AbeJDOUn (ORCPT + 99 others); Thu, 4 Oct 2018 10:20:43 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:34288 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbeJDOUn (ORCPT ); Thu, 4 Oct 2018 10:20:43 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 43D946079B; Thu, 4 Oct 2018 07:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1538638131; bh=HjrXyEOQR0dCIHda/ch3XFMzUZ9v01Lx6GEhabta3js=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=h4si3o/d1/ak7+En6JPc7qBlfrujGh6dYV2xh3XJAaGmuY5qLiY/h+eL8NG4LbQ8o 5T1eO/EpIntqyb9k8Fa4sRVGI/xnQCOic6MDiQOEyRNy1wLmvPbeicbYnzHmTwMfmJ gKoPdE0y/0Y2zblt1fVzhaeK7rOjTNGmKz/0vLCE= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 498F36021C; Thu, 4 Oct 2018 07:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1538638130; bh=HjrXyEOQR0dCIHda/ch3XFMzUZ9v01Lx6GEhabta3js=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fLyo44EbkndiILetHUfJKz6er17fRq2mOb4ckUsiDTbEKI/eUpiF5ZwSwUr9Rn69d i1h5MLmxqqBZCsD+OGR1zdZ/tf61WSrcmToDavz/HRmDmewsbyp4Tih5NufWyseOoD hkPjx/9sRq1osmleKh8aWN0LeTiBuEIQS34jH1mY= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 04 Oct 2018 12:58:50 +0530 From: alokc@codeaurora.org To: Stephen Boyd Cc: Wolfram Sang , linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-arm-msm@vger.kernel.org, Karthikeyan Ramasubramanian , Sagar Dharia , Girish Mahadevan , Doug Anderson , linux-i2c-owner@vger.kernel.org Subject: Re: [PATCH v3 2/3] i2c: i2c-qcom-geni: Simplify tx/rx functions In-Reply-To: <20180924235235.182649-2-swboyd@chromium.org> References: <20180924235235.182649-1-swboyd@chromium.org> <20180924235235.182649-2-swboyd@chromium.org> Message-ID: <71abf26e927bce446cfd47ca9879444a@codeaurora.org> X-Sender: alokc@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-09-25 05:22, Stephen Boyd 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 testing > the > 'dma_buf' local variable in lieu of the 'mode' local variable. And > kernel style is to leave the return statement by itself, detached from > the rest of the function. > > Cc: Karthikeyan Ramasubramanian > Cc: Sagar Dharia > Cc: Girish Mahadevan > Cc: Doug Anderson > Signed-off-by: Stephen Boyd > --- changes looks more clean now. Reviewed-by: Alok Chauhan > drivers/i2c/busses/i2c-qcom-geni.c | 79 ++++++++++++++---------------- > 1 file changed, 36 insertions(+), 43 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-qcom-geni.c > b/drivers/i2c/busses/i2c-qcom-geni.c > index 9f2eb02481d3..0b466835cf40 100644 > --- a/drivers/i2c/busses/i2c-qcom-geni.c > +++ b/drivers/i2c/busses/i2c-qcom-geni.c > @@ -365,29 +365,24 @@ static int geni_i2c_rx_one_msg(struct > geni_i2c_dev *gi2c, struct i2c_msg *msg, > u32 m_param) > { > dma_addr_t rx_dma; > - enum geni_se_xfer_mode mode; > - unsigned long time_left = XFER_TIMEOUT; > + 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; > dma_buf = i2c_get_dma_safe_msg_buf(msg, 32); > 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, GENI_SE_DMA); > + else > + geni_se_select_mode(se, GENI_SE_FIFO); > + > + 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)) { > + geni_se_select_mode(se, GENI_SE_FIFO); > + i2c_put_dma_safe_msg_buf(dma_buf, msg, false); > + dma_buf = NULL; > } > > time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT); > @@ -395,12 +390,13 @@ static int geni_i2c_rx_one_msg(struct > geni_i2c_dev *gi2c, struct i2c_msg *msg, > geni_i2c_abort_xfer(gi2c); > > gi2c->cur_rd = 0; > - if (mode == GENI_SE_DMA) { > + if (dma_buf) { > 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; > } > > @@ -408,45 +404,41 @@ static int geni_i2c_tx_one_msg(struct > geni_i2c_dev *gi2c, struct i2c_msg *msg, > u32 m_param) > { > dma_addr_t tx_dma; > - 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; > dma_buf = i2c_get_dma_safe_msg_buf(msg, 32); > 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, GENI_SE_DMA); > + else > + geni_se_select_mode(se, GENI_SE_FIFO); > + > + 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)) { > + geni_se_select_mode(se, GENI_SE_FIFO); > + i2c_put_dma_safe_msg_buf(dma_buf, msg, false); > + dma_buf = NULL; > } > > - if (mode == GENI_SE_FIFO) /* Get FIFO IRQ */ > - writel_relaxed(1, gi2c->se.base + SE_GENI_TX_WATERMARK_REG); > + if (!dma_buf) /* Get FIFO IRQ */ > + writel_relaxed(1, se->base + SE_GENI_TX_WATERMARK_REG); > > time_left = wait_for_completion_timeout(&gi2c->done, XFER_TIMEOUT); > if (!time_left) > geni_i2c_abort_xfer(gi2c); > > gi2c->cur_wr = 0; > - if (mode == GENI_SE_DMA) { > + if (dma_buf) { > 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; > } > > @@ -474,6 +466,7 @@ static int geni_i2c_xfer(struct i2c_adapter *adap, > > m_param |= ((msgs[i].addr << SLV_ADDR_SHFT) & SLV_ADDR_MSK); > > + gi2c->cur = &msgs[i]; > if (msgs[i].flags & I2C_M_RD) > ret = geni_i2c_rx_one_msg(gi2c, &msgs[i], m_param); > else -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,a Linux Foundation Collaborative Project