From patchwork Thu Aug 25 04:46:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9298667 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 B1659608A7 for ; Thu, 25 Aug 2016 04:55:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A04BC291C5 for ; Thu, 25 Aug 2016 04:55:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9519D291CB; Thu, 25 Aug 2016 04:55:57 +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 2AFF2291CF for ; Thu, 25 Aug 2016 04:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756388AbcHYEzk (ORCPT ); Thu, 25 Aug 2016 00:55:40 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35750 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753877AbcHYExS (ORCPT ); Thu, 25 Aug 2016 00:53:18 -0400 Received: by mail-wm0-f66.google.com with SMTP id i5so5639820wmg.2 for ; Wed, 24 Aug 2016 21:53:18 -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=iOzEYczEyQmbLuQcF0JiCBtvFpQK+aHyzy2PWnkOgZI=; b=hmiYEsLWCNaOILDlUb4n+WwuiaSLCZ0x/q3mp/9dooiNoS6Lkhjghflac1ldN4yf7J jiAq59dyZ3YPYC0tSOu7MMkU1/9C0vZxLS6CiNwh3SXHmhNTtubM4VdayNCApskJHxGf p0ljG2ppwUrIyr/EyQAzJmot/AbdI4YnA4NSspHeUoprDK69bEMRL8k8i0EgmQfd2S3T S7M913GuQyP12ic3Rh5rPewqTAlfPMcZFsFfkRjYJBzK9QSvj6EvpgMuLRt6KDeptdy2 M0+5AWUqwRO4GjJgIeZ3sfrA57A2C6fnoN+WdCJcLukl1kRKqzxpDtgF5bdWOVs/l0SL /Now== 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=iOzEYczEyQmbLuQcF0JiCBtvFpQK+aHyzy2PWnkOgZI=; b=acVL6/XnLx+ez7QH96GRVlv8FVyxIK4aSfhfAu3xlOK+LBYK2pCB1PxJnDjQlFByNF m+Trg/UABIzRQgeiERYFZ2RnlqwHFMr/kfDYCocQmsPcAYrmt9CYg6B5d0IhFVhvqkoN DkvnY0AL65Ha4rigp102Rdj7VPf8X0b0XQsiLfA5AkpAYdCaiC12CJzYn7RgVrlqyvRE S/1EOrXa8LQrcHO1el05TFuaZW1p+rr7sRuurCLz3iDy2YtHo8liN5eUWnqxgaX3Zcz8 dJDauk+WMYPc43ZAiC95LkF2fgHNZXCzTascS6HMVs1yRL1ETSdBsM800MALMgQ8BF9W GFIw== X-Gm-Message-State: AE9vXwMpzXSJ33Zpb6tLONhfP9eRE2u0TUGs7HbceMOOWxcfNwViWSe5drwQBSsQNfsOag== X-Received: by 10.28.199.1 with SMTP id x1mr6259244wmf.0.1472100797318; Wed, 24 Aug 2016 21:53:17 -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 c139sm36795951wme.4.2016.08.24.21.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Aug 2016 21:53:16 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH 08/23] spi: fsl-espi: factor out filling the local buffer To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: <41a045ab-2629-658f-cccd-23f7182a4bc2@gmail.com> Date: Thu, 25 Aug 2016 06:46:26 +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 Better structure the code by factoring out filling the local buffer. Signed-off-by: Heiner Kallweit --- drivers/spi/spi-fsl-espi.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 494a7bf..c3aa6f0 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c @@ -85,6 +85,26 @@ struct fsl_espi_transfer { #define AUTOSUSPEND_TIMEOUT 2000 +static unsigned int 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) { + memcpy(buf, t->tx_buf, t->len); + if (!t->rx_buf) + tx_only += t->len; + } else + memset(buf, 0, t->len); + buf += t->len; + } + + return tx_only; +} + static void fsl_espi_change_mode(struct spi_device *spi) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master); @@ -301,16 +321,9 @@ static void fsl_espi_cmd_trans(struct spi_message *m, struct fsl_espi_transfer *trans, u8 *rx_buff) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); - struct spi_transfer *t; - int i = 0; struct fsl_espi_transfer *espi_trans = trans; - list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->tx_buf) { - memcpy(mspi->local_buf + i, t->tx_buf, t->len); - i += t->len; - } - } + fsl_espi_copy_to_buf(m, mspi); espi_trans->tx_buf = espi_trans->rx_buf = mspi->local_buf; fsl_espi_do_trans(m, espi_trans); @@ -322,18 +335,9 @@ static void fsl_espi_rw_trans(struct spi_message *m, struct fsl_espi_transfer *trans, u8 *rx_buff) { struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); - struct spi_transfer *t; - unsigned int tx_only = 0; - int i = 0; + unsigned int tx_only; - list_for_each_entry(t, &m->transfers, transfer_list) { - if (t->tx_buf) { - memcpy(mspi->local_buf + i, t->tx_buf, t->len); - i += t->len; - if (!t->rx_buf) - tx_only += t->len; - } - } + tx_only = fsl_espi_copy_to_buf(m, mspi); trans->tx_buf = trans->rx_buf = mspi->local_buf; fsl_espi_do_trans(m, trans); @@ -350,14 +354,11 @@ static void fsl_espi_rw_trans(struct spi_message *m, static int fsl_espi_do_one_msg(struct spi_master *master, struct spi_message *m) { - struct mpc8xxx_spi *mspi = spi_master_get_devdata(master); struct spi_transfer *t; u8 *rx_buf = NULL; unsigned int xfer_len = 0; struct fsl_espi_transfer espi_trans; - memset(mspi->local_buf, 0, SPCOM_TRANLEN_MAX); - list_for_each_entry(t, &m->transfers, transfer_list) { if (t->rx_buf) rx_buf = t->rx_buf;