From patchwork Mon Jun 2 13:38:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 4282481 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AC7639F1D6 for ; Mon, 2 Jun 2014 13:50:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 380CD203DC for ; Mon, 2 Jun 2014 13:50:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E3F320340 for ; Mon, 2 Jun 2014 13:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754351AbaFBNui (ORCPT ); Mon, 2 Jun 2014 09:50:38 -0400 Received: from winston.telenet-ops.be ([195.130.137.75]:56550 "EHLO winston.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754645AbaFBNuh (ORCPT ); Mon, 2 Jun 2014 09:50:37 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [195.130.137.88]) by winston.telenet-ops.be (Postfix) with ESMTP id 83F361BD420 for ; Mon, 2 Jun 2014 15:38:32 +0200 (CEST) Received: from ayla.of.borg ([84.193.72.141]) by michel.telenet-ops.be with bizsmtp id 9ReY1o00T32ts5g06ReYgJ; Mon, 02 Jun 2014 15:38:32 +0200 Received: from geert by ayla.of.borg with local (Exim 4.76) (envelope-from ) id 1WrSRc-0007jE-6t; Mon, 02 Jun 2014 15:38:32 +0200 From: Geert Uytterhoeven To: Mark Brown Cc: Yoshihiro Shimoda , Magnus Damm , linux-spi@vger.kernel.org, linux-sh@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 17/18] spi: rspi: Extract rspi_common_transfer() Date: Mon, 2 Jun 2014 15:38:19 +0200 Message-Id: <1401716301-29612-18-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1401716301-29612-1-git-send-email-geert+renesas@glider.be> References: <1401716301-29612-1-git-send-email-geert+renesas@glider.be> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Extract the common parts of rspi_transfer_one(), rspi_rz_transfer_one(), and qspi_transfer_out_in() into the new function rspi_common_transfer(). Signed-off-by: Geert Uytterhoeven --- drivers/spi/spi-rspi.c | 61 ++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c index 4bc4138e002b..10112745bb17 100644 --- a/drivers/spi/spi-rspi.c +++ b/drivers/spi/spi-rspi.c @@ -586,12 +586,32 @@ static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi, return __rspi_can_dma(rspi, xfer); } +static int rspi_common_transfer(struct rspi_data *rspi, + struct spi_transfer *xfer) +{ + int ret; + + if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) { + /* rx_buf can be NULL on RSPI on SH in TX-only Mode */ + return rspi_dma_transfer(rspi, &xfer->tx_sg, + xfer->rx_buf ? &xfer->rx_sg : NULL); + } + + ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len); + if (ret < 0) + return ret; + + /* Wait for the last transmission */ + rspi_wait_for_tx_empty(rspi); + + return 0; +} + static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, struct spi_transfer *xfer) { struct rspi_data *rspi = spi_master_get_devdata(master); u8 spcr; - int ret; spcr = rspi_read8(rspi, RSPI_SPCR); if (xfer->rx_buf) { @@ -602,18 +622,7 @@ static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, } rspi_write8(rspi, spcr, RSPI_SPCR); - if (master->can_dma && __rspi_can_dma(rspi, xfer)) - return rspi_dma_transfer(rspi, &xfer->tx_sg, - xfer->rx_buf ? &xfer->rx_sg : NULL); - - ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len); - if (ret < 0) - return ret; - - /* Wait for the last transmission */ - rspi_wait_for_tx_empty(rspi); - - return 0; + return rspi_common_transfer(rspi, xfer); } static int rspi_rz_transfer_one(struct spi_master *master, @@ -625,37 +634,15 @@ static int rspi_rz_transfer_one(struct spi_master *master, rspi_rz_receive_init(rspi); - if (master->can_dma && __rspi_can_dma(rspi, xfer)) - return rspi_dma_transfer(rspi, &xfer->tx_sg, &xfer->rx_sg); - - ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len); - if (ret < 0) - return ret; - - /* Wait for the last transmission */ - rspi_wait_for_tx_empty(rspi); - - return 0; + return rspi_common_transfer(rspi, xfer); } static int qspi_transfer_out_in(struct rspi_data *rspi, struct spi_transfer *xfer) { - int ret; - qspi_receive_init(rspi); - if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) - return rspi_dma_transfer(rspi, &xfer->tx_sg, &xfer->rx_sg); - - ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len); - if (ret < 0) - return ret; - - /* Wait for the last transmission */ - rspi_wait_for_tx_empty(rspi); - - return 0; + return rspi_common_transfer(rspi, xfer); } static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer)