From patchwork Thu Aug 25 04:51:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9298655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07A1A60757 for ; Thu, 25 Aug 2016 04:55:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC632291C0 for ; Thu, 25 Aug 2016 04:55:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0DF5291C1; Thu, 25 Aug 2016 04:55:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E71A291CA for ; Thu, 25 Aug 2016 04:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755795AbcHYEyn (ORCPT ); Thu, 25 Aug 2016 00:54:43 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34095 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754706AbcHYExf (ORCPT ); Thu, 25 Aug 2016 00:53:35 -0400 Received: by mail-wm0-f66.google.com with SMTP id q128so5639177wma.1 for ; Wed, 24 Aug 2016 21:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=W3/vj04gPU9YeaOWoxQ4jaVINGR1G80fVBihzjAh+Fg=; b=LZMhiA4Z538Bb5EKSHwfiX+Ew9v3TLlqvcl8vD/lR2Cj9b1R9LICH6csWS2zxw4Itj a4/8bBIzrN6LH9xB0nC97Nh/DguSRcDIrj2VB0tkmVVf24//ok/p9ubZGkBwQIsCQolB vdoxHv1q1XJYUjQpqvkQb5zGTJaFB6yTKl62SwkSrGhoBAIgK8e4FfgP8zjOFzqesbeI pJoPM2lQbomFkmGyfHK+tnQJmXGNVdgp4cXFGMr3hplVaud1G8ZFe5Ae7tGssD25rzU1 ImnYCIBmVebWC1WDvsSMLoB3Tn/oepEAr9DJoZ6PRCislYdXL8NBtSfr+j1ki7A/pCY4 2FSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=W3/vj04gPU9YeaOWoxQ4jaVINGR1G80fVBihzjAh+Fg=; b=ZV1CRPQoN/g/KWRzNoDmvOnmUk8Kogvsu99GqH5fpvrcQjzBWgXkjz1y5Hlo1VbAcC t70vo17VnGY0ikKdtMSozuj7V1Vc77+FOnxSI/6j5pgCqG8Ew8X81ziXMzjd2IYl/Vq1 if2RrBPMWglULez9fbLy5IHCKGTRiuFTp9HuEMsgSJ7gx6WxviRLRXa/B4kOMDPtJcGm 8oVGXmXaJn/VjxYusvP2in8O7U6H4of77zYUNyzw40sAMkYuNHIL9frVWZUSuJ0EB3hx Pka7AtYEZ2UHbJwGjtVUAeT79Zuv83HH3ykZ33/Q67hf1MWNZUeqm0vMmJ8A46KbpPqC 9VRw== X-Gm-Message-State: AE9vXwMgeXTW1rOoNAnLVght2lG+fSnmqg7OYPQ5MmZ4G0InWNve2dI4VHjXzjtH3H+BQg== X-Received: by 10.28.100.215 with SMTP id y206mr5717211wmb.115.1472100813557; Wed, 24 Aug 2016 21:53:33 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:9500:dd82:2805:e44f:720e? (p200300625F439500DD822805E44F720E.dip0.t-ipconnect.de. [2003:62:5f43:9500:dd82:2805:e44f:720e]) by smtp.googlemail.com with ESMTPSA id a9sm13141628wjf.16.2016.08.24.21.53.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Aug 2016 21:53:33 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH 20/23] spi: fsl-espi: factor out handling of read data To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: <555ee506-ca82-40f5-0429-a1147a08a583@gmail.com> Date: Thu, 25 Aug 2016 06:51:33 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Factor out copying read data to the read buffers in the original message to a new function fsl_espi_copy_from_buf. This also allows to simplify fsl_espi_copy_to_buf. Signed-off-by: Heiner Kallweit --- drivers/spi/spi-fsl-espi.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 56f3a3d..d348a66 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -77,24 +77,32 @@ struct fsl_espi_reg { #define AUTOSUSPEND_TIMEOUT 2000 -static unsigned int fsl_espi_copy_to_buf(struct spi_message *m, - struct mpc8xxx_spi *mspi) +static void fsl_espi_copy_to_buf(struct spi_message *m, + struct mpc8xxx_spi *mspi) { - unsigned int tx_only = 0; struct spi_transfer *t; u8 *buf = mspi->local_buf; list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->tx_buf) { + if (t->tx_buf) memcpy(buf, t->tx_buf, t->len); - if (!t->rx_buf) - tx_only += t->len; - } else + else memset(buf, 0, t->len); buf += t->len; } +} + +static void fsl_espi_copy_from_buf(struct spi_message *m, + struct mpc8xxx_spi *mspi) +{ + struct spi_transfer *t; + u8 *buf = mspi->local_buf; - return tx_only; + list_for_each_entry(t, &m->transfers, transfer_list) { + if (t->rx_buf) + memcpy(t->rx_buf, buf, t->len); + buf += t->len; + } } static int fsl_espi_check_message(struct spi_message *m) @@ -288,20 +296,17 @@ static int fsl_espi_do_trans(struct spi_message *m, struct spi_transfer *trans) return ret; } -static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans, - u8 *rx_buff) +static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); - unsigned int tx_only; int ret; - tx_only = fsl_espi_copy_to_buf(m, mspi); + fsl_espi_copy_to_buf(m, mspi); ret = fsl_espi_do_trans(m, trans); - /* If there is at least one RX byte then copy it to rx_buff */ - if (!ret && rx_buff && trans->len > tx_only) - memcpy(rx_buff, trans->rx_buf + tx_only, trans->len - tx_only); + if (!ret) + fsl_espi_copy_from_buf(m, mspi); return ret; } @@ -310,7 +315,6 @@ static int fsl_espi_do_one_msg(struct spi_master *master, struct spi_message *m) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); - u8 *rx_buf = NULL; unsigned int delay_usecs = 0, xfer_len = 0; struct spi_transfer *t, trans = {}; int ret; @@ -320,8 +324,6 @@ static int fsl_espi_do_one_msg(struct spi_master *master, goto out; list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->rx_buf) - rx_buf = t->rx_buf; if ((t->tx_buf) || (t->rx_buf)) xfer_len += t->len; if (t->delay_usecs > delay_usecs) @@ -337,7 +339,7 @@ static int fsl_espi_do_one_msg(struct spi_master *master, trans.delay_usecs = delay_usecs; trans.tx_buf = trans.rx_buf = mspi->local_buf; - ret = fsl_espi_trans(m, &trans, rx_buf); + ret = fsl_espi_trans(m, &trans); m->actual_length = ret ? 0 : trans.len; out: