From patchwork Wed Jan 8 08:00:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3452381 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 03BFFC02DC for ; Wed, 8 Jan 2014 08:00:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D71D020103 for ; Wed, 8 Jan 2014 08:00:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A305B20109 for ; Wed, 8 Jan 2014 08:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755069AbaAHIAR (ORCPT ); Wed, 8 Jan 2014 03:00:17 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:59108 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755503AbaAHIAM (ORCPT ); Wed, 8 Jan 2014 03:00:12 -0500 Received: by mail-pa0-f50.google.com with SMTP id kp14so1523144pab.23 for ; Wed, 08 Jan 2014 00:00:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=Sa4qaH6yyA0jV2+lRnKDte+lSz7aQ7IjP1iH1B30ma0=; b=DZBefIhrlt7MeWLfNPbCAAxTJHO+ddvZL0pvaiP26L932HBDL2VTnHgqPdu7xU1Lwx rJkhQgmVzV/chnaS52BjD7C9jbO5PvPmBb/Ksx/WtubRhkLxsPQmUEHFhc2lQ1HehO8E qdCaPKi7+hy+X1zCqym3E5Dov8FFJOSCXLWejai9npW0PzC0Xb2FRlPuBup0xMO2/fCK PlfXcRO0evy1LzktzSF9BGepoaWrFEaf0yxbCZuflumA/wVMjRoq0gpSDyM9l9AO6K+K BVHgQhv5Qrpkb9gzrSKuFjUOYV5AuMMoRPGp8EWWxKQ94QRT0TjooqjeGpB0tKaSzciD thtQ== X-Gm-Message-State: ALoCoQmyBy4fAdwHy76dFadu15A27b9efXU3SkppNPSHQqsDripDjTAp+dqpNXy60QZ95G324W02 X-Received: by 10.68.133.229 with SMTP id pf5mr141230756pbb.115.1389168012243; Wed, 08 Jan 2014 00:00:12 -0800 (PST) Received: from [192.168.1.102] (111-240-64-237.dynamic.hinet.net. [111.240.64.237]) by mx.google.com with ESMTPSA id ju10sm272362pbd.33.2014.01.08.00.00.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 00:00:11 -0800 (PST) Message-ID: <1389168004.28019.1.camel@phoenix> Subject: [PATCH RFT] spi: oc-tiny: Simplify tiny_spi_txrx_bufs implementation when irq is not used From: Axel Lin To: Mark Brown Cc: Thomas Chou , linux-spi@vger.kernel.org Date: Wed, 08 Jan 2014 16:00:04 +0800 X-Mailer: Evolution 3.6.4-0ubuntu1 Mime-Version: 1.0 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.0 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 Currently we have similar code for (txp && rxp), (txp && !rxp), (!rxp & txp), and (!txp && !rxp) cases. This patch refactors the code a bit to avoid duplicate similar code. Signed-off-by: Axel Lin --- Hi Thomas, I don't have this hardware, so please test this path if you think it is ok. I think there is no functional change with this patch. Thanks, Axel drivers/spi/spi-oc-tiny.c | 62 +++++++++-------------------------------------- 1 file changed, 11 insertions(+), 51 deletions(-) diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c index 91c6685..f7c896e 100644 --- a/drivers/spi/spi-oc-tiny.c +++ b/drivers/spi/spi-oc-tiny.c @@ -153,62 +153,22 @@ static int tiny_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t) } wait_for_completion(&hw->done); - } else if (txp && rxp) { - /* we need to tighten the transfer loop */ - writeb(*txp++, hw->base + TINY_SPI_TXDATA); - if (t->len > 1) { - writeb(*txp++, hw->base + TINY_SPI_TXDATA); - for (i = 2; i < t->len; i++) { - u8 rx, tx = *txp++; - tiny_spi_wait_txr(hw); - rx = readb(hw->base + TINY_SPI_TXDATA); - writeb(tx, hw->base + TINY_SPI_TXDATA); - *rxp++ = rx; - } - tiny_spi_wait_txr(hw); - *rxp++ = readb(hw->base + TINY_SPI_TXDATA); - } - tiny_spi_wait_txe(hw); - *rxp++ = readb(hw->base + TINY_SPI_RXDATA); - } else if (rxp) { - writeb(0, hw->base + TINY_SPI_TXDATA); - if (t->len > 1) { - writeb(0, - hw->base + TINY_SPI_TXDATA); - for (i = 2; i < t->len; i++) { - u8 rx; - tiny_spi_wait_txr(hw); - rx = readb(hw->base + TINY_SPI_TXDATA); - writeb(0, hw->base + TINY_SPI_TXDATA); - *rxp++ = rx; - } - tiny_spi_wait_txr(hw); - *rxp++ = readb(hw->base + TINY_SPI_TXDATA); - } - tiny_spi_wait_txe(hw); - *rxp++ = readb(hw->base + TINY_SPI_RXDATA); - } else if (txp) { - writeb(*txp++, hw->base + TINY_SPI_TXDATA); - if (t->len > 1) { - writeb(*txp++, hw->base + TINY_SPI_TXDATA); - for (i = 2; i < t->len; i++) { - u8 tx = *txp++; - tiny_spi_wait_txr(hw); - writeb(tx, hw->base + TINY_SPI_TXDATA); - } - } - tiny_spi_wait_txe(hw); } else { - writeb(0, hw->base + TINY_SPI_TXDATA); - if (t->len > 1) { - writeb(0, hw->base + TINY_SPI_TXDATA); - for (i = 2; i < t->len; i++) { + /* we need to tighten the transfer loop */ + writeb(txp ? *txp++ : 0, hw->base + TINY_SPI_TXDATA); + for (i = 1; i < t->len; i++) { + writeb(txp ? *txp++ : 0, hw->base + TINY_SPI_TXDATA); + + if (rxp || (i != t->len - 1)) tiny_spi_wait_txr(hw); - writeb(0, hw->base + TINY_SPI_TXDATA); - } + if (rxp) + *rxp++ = readb(hw->base + TINY_SPI_TXDATA); } tiny_spi_wait_txe(hw); + if (rxp) + *rxp++ = readb(hw->base + TINY_SPI_RXDATA); } + return t->len; }