From patchwork Fri Sep 2 21:22:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9311699 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 E28F160772 for ; Fri, 2 Sep 2016 21:23:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D25AF2983D for ; Fri, 2 Sep 2016 21:23:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C769729848; Fri, 2 Sep 2016 21:23:10 +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=-5.8 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 6BFEA2983D for ; Fri, 2 Sep 2016 21:23:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752226AbcIBVXJ (ORCPT ); Fri, 2 Sep 2016 17:23:09 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35479 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbcIBVXJ (ORCPT ); Fri, 2 Sep 2016 17:23:09 -0400 Received: by mail-wm0-f68.google.com with SMTP id c133so4383469wmd.2 for ; Fri, 02 Sep 2016 14:23:08 -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=YscvMvHUvc5yQzLXCHBuTex1WINl3tgiKKl47GNTLA/my+fu7jf0z0DV6c/h1dG+w8 c4CZ+ml7wGGkF1CwnILNMiZf44x8i2ZiVCcD6GjRwNKpasfI/pqOF7eZRK71R94mPxYR cQtleONc0Uh162c5L5y0FdkG2hHpkORZk1D+atxUHkzS2jDy3uxnfzvEwDNHGoF8luKy 7qspl66Lln2DRb6l1vLk0EaYOtWICv4RcueEL0gG+rfOzLHiizON0PU/wkLTIFaLrCVE PDpaDr33/qOQ1eAAzAY9t32MYBE5GvpxruPW/UNAlQ938WHAssEirGiMi3zCVGEfYhpV VmLQ== 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=iGO3GmxrH/elQCIPD99Bn7ExNEVabWGieEx4xVpr3oWVwRr5NiP8fXKyRMoYav+dsm MZnNB08uiHYOaOGWcyQkMSOYkSft876HR3y2oA5HUykwfVWMU/l0Qfn4KILlu+xB4i9e dc2JXisnoTqNpGtVwVsE9tE7fcy1TR8hiu6lBomJUjVwr3mHPR/tI3DVQ41F30pyZs7v NaAnVLs3NjeUfVPwZo2EMH9p79UklD746o7T5KkG//CmPKEscyKmJJ+PZY//Xoz5prK8 zZGfqdyFSmimy8IFqHkTE1O8FvtOstCHnGxS/VwHfhinC4SBEn3866pSa9mZ6pUzR1B4 SOcA== X-Gm-Message-State: AE9vXwOupiKrMlrGZWjp/R1HPWZKbf67McaL/A3nc/R0DqYFMEkcaqktqvER5pmwAFRtkg== X-Received: by 10.28.207.197 with SMTP id f188mr5169104wmg.69.1472851387300; Fri, 02 Sep 2016 14:23:07 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:9500:39ed:a1fb:9a43:e02d? (p200300625F43950039EDA1FB9A43E02D.dip0.t-ipconnect.de. [2003:62:5f43:9500:39ed:a1fb:9a43:e02d]) by smtp.googlemail.com with ESMTPSA id q65sm5356159wmd.24.2016.09.02.14.23.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Sep 2016 14:23:06 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v2 21/23] spi: fsl-espi: factor out handling of read data To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: <23b15e58-4833-7180-5c5d-81af382c54c0@gmail.com> Date: Fri, 2 Sep 2016 23:22:36 +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: