From patchwork Sun Sep 4 08:02:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9312431 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 A6835600CA for ; Sun, 4 Sep 2016 08:08:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 982BC287DA for ; Sun, 4 Sep 2016 08:08:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D0CD28925; Sun, 4 Sep 2016 08:08:09 +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=-4.4 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 306B4287DA for ; Sun, 4 Sep 2016 08:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752219AbcIDIIC (ORCPT ); Sun, 4 Sep 2016 04:08:02 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35473 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752472AbcIDIHp (ORCPT ); Sun, 4 Sep 2016 04:07:45 -0400 Received: by mail-wm0-f65.google.com with SMTP id c133so8695759wmd.2 for ; Sun, 04 Sep 2016 01:07:44 -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=AqwmuaiB+8BBrBvdunru2cWHz+LlYd3Xk8hWeix0DnI=; b=AIalDHpbP3qMPrRVU4YP79Xnp6eEasQ7Ra+3P66leokGUlpMUYd25n4PGD00SA8pO+ TP7s770u9o5zEDhUUQOCnvE57gv5zHJ39Nn1PrW630VPlO4dT/CBJ9AiIr/98kTGF4dB kVhcJxSCTviTKq13cSEzayyD8oNNw3oszae9eu3GtPncJ1wcQBLS6Z6WJrOUGYZz7RUZ wBw4GgO+HzaBUNAVC+uJCa6X5QigAnXk/ulZnAM4PQZaGocfQVJ67/qNSf+LQ274Lj7e VOeX+xVClSoxU/rUI7FPgMirFVkl5elTX7hekGI00Lt8apSoivrgISCv4iyqkOHpZoKB Kaew== 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=AqwmuaiB+8BBrBvdunru2cWHz+LlYd3Xk8hWeix0DnI=; b=HidK1Yy6Qt/hxwplNUysvScooQviX9PRfaPLIQEvghsf0OEU2p3UOpctK8Q3Ivkpzs P1SIZ3CPeYjbZMKYgpWqzwzhrLHwATAlwRER32hZSvmaMLvyAAYBKBLEX4M6dy1CeEnn liLQL2VV07SZvO+1XgSVS9kSpd6REfzYAaI+9K7S2EBVW909ZOnF6ponVVtytuHtGKqu b3To0ZYSMB4S6j6k3NcMKrcABiCt0Du3LliKtp0OOvE9bd3CELE+xzkV9AaiC2Otu/OI FvlfVK3X1Z0Mv66MISzc42yo0nc+L8Ffh9uxM5afFZPmzeK8TbbZD3Km55LyoOLAIhOn 1t/g== X-Gm-Message-State: AE9vXwMickK4IhlahaYVPrVi8+ITGHEv4c4Ivl9fmexgwNPEb/5Ppq7IOYSUFy1k+TcfyQ== X-Received: by 10.28.191.14 with SMTP id p14mr10813584wmf.39.1472976463382; Sun, 04 Sep 2016 01:07:43 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:9500:c1f5:c528:a3d:f8c4? (p200300625F439500C1F5C5280A3DF8C4.dip0.t-ipconnect.de. [2003:62:5f43:9500:c1f5:c528:a3d:f8c4]) by smtp.googlemail.com with ESMTPSA id v189sm12957446wmv.12.2016.09.04.01.07.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Sep 2016 01:07:43 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 16/18] spi: fsl-espi: factor out handling of read data To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: <73825492-8cd9-7608-0675-8f954ae69b62@gmail.com> Date: Sun, 4 Sep 2016 10:02:24 +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 --- v2: - rebased --- drivers/spi/spi-fsl-espi.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 79c89bf..88935a3 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -77,25 +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) @@ -287,20 +294,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; } @@ -309,7 +313,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; @@ -319,8 +322,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 +338,7 @@ static int fsl_espi_do_one_msg(struct spi_master *master, trans.tx_buf = mspi->local_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: