From patchwork Wed Sep 7 20:54:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9319923 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 8888C60CF5 for ; Wed, 7 Sep 2016 20:56:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72EB829427 for ; Wed, 7 Sep 2016 20:56:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67B5629429; Wed, 7 Sep 2016 20:56:17 +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 EAE5D2942A for ; Wed, 7 Sep 2016 20:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757118AbcIGU4J (ORCPT ); Wed, 7 Sep 2016 16:56:09 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33614 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757333AbcIGUzy (ORCPT ); Wed, 7 Sep 2016 16:55:54 -0400 Received: by mail-wm0-f65.google.com with SMTP id b187so852838wme.0 for ; Wed, 07 Sep 2016 13:55:53 -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=K5WOv3wsNrw7GQLapCt8pa+lZJVWWejV0BpUuNsZn6Y=; b=qm8U/fVgZTbYVlVKct+KTgeNtZ9+sOpQ2WpqCWyiVYVDYmXZY+Fcl4oFdqDihYyoVy 7G3PamW4Yq/R9QYGA3jzbH6WrZwmAfAjZhB6DV4n9TX4FSCeSOzuxtHNudNSZH1ZMBRD uTc/gsYZYIW0ER+LaEsT+PiwdrFu2I5x3qGLUHOOKV2UCDWH5ahM7J7tBj1AJ/AG6vfj YzZ/AHi7TuKjgqqpOd01/f5jzdJ6fAwaOOOqv0d64PAKazk+wQr3/7yZMGxFhBYOD+la ugspYcLC8Uv5kXfBiHReiVZAEGzbywUNtknbU4kVq5o+Cd1demyaqxhFMf8hP6t4uXvH vQtg== 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=K5WOv3wsNrw7GQLapCt8pa+lZJVWWejV0BpUuNsZn6Y=; b=Vho+OChzHzUUEDiBcVqajFg264ceQmSdY4wMpFnpH/u0ZD67gKm8Th4R7wz1Gwg3Eh kfQg0k9ehCpH2zKTs1YbkBJjE4+N7elVNbhgI3E31V0R/bALqGsbliUqCh9aNQFk9t5k MQ83EacW9gHxOuN3sTwvMmf1wGQVeQBCaGpPs8p8MMdHzV5jHjfB1sRT610f609n7flQ L1lcGUt5WFqC1cqsq+7KvzfQcOuRjk2QinMC9X4EdaN2b2E1cUURJF1JQTXlO2sMs/BS 8ahVXU9V96ajdKWULgmvLsXRu5x7RRGe1fo1iOdv+OVN1K7QVMuAnYVAItTdur3mr02L ErjQ== X-Gm-Message-State: AE9vXwNL2p5pKlICTpKTEEITvdBDOuS3Vs1zFnDycgk6je+gMT3qBPlj4VrXtsIfsHee6A== X-Received: by 10.194.27.164 with SMTP id u4mr29523604wjg.45.1473281753019; Wed, 07 Sep 2016 13:55:53 -0700 (PDT) Received: from ?IPv6:2003:62:5f43:9500:6565:4488:ad4:60db? (p200300625F439500656544880AD460DB.dip0.t-ipconnect.de. [2003:62:5f43:9500:6565:4488:ad4:60db]) by smtp.googlemail.com with ESMTPSA id n7sm28202316wjs.34.2016.09.07.13.55.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Sep 2016 13:55:52 -0700 (PDT) From: Heiner Kallweit Subject: [PATCH v3 13/15] spi: fsl-espi: factor out handling of read data To: Mark Brown References: Cc: "linux-spi@vger.kernel.org" Message-ID: Date: Wed, 7 Sep 2016 22:54:18 +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 v3: - new numbering --- 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: