From patchwork Fri Jan 10 08:08:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 309180 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 148152C0078 for ; Fri, 10 Jan 2014 19:08:41 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 935B14ABAC; Fri, 10 Jan 2014 09:08:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6QpzIRa5rqxa; Fri, 10 Jan 2014 09:08:39 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7BC944AB47; Fri, 10 Jan 2014 09:08:34 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A73F84AB47 for ; Fri, 10 Jan 2014 09:08:28 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1wBPF7zNsnew for ; Fri, 10 Jan 2014 09:08:22 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by theia.denx.de (Postfix) with ESMTPS id 323E54AB3D for ; Fri, 10 Jan 2014 09:08:16 +0100 (CET) Received: by mail-pa0-f52.google.com with SMTP id kx10so581712pab.11 for ; Fri, 10 Jan 2014 00:08:14 -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=emzFZHRSn72rSHbsIEut/nqEyd2KdS2OUCG432zgy7g=; b=IiKGY92mTJgnQlpTEoUZF0PzNeCftr5101Y7bx0r7ZaH9ZSLo7UxMDWZEYyHDLzSov j1O5iRRdWc/KDx9YcZiwpsXngcmS+SzP2EYdU0GxqAKaj4Np79masvuTjpTzirbgm/kj BRj+zESz+XSTyoHcqEvBzdBu2jp1S/3nkzDhEt6RegpDu4+kYrReKoNPaNFHagsuRn6p 696ZRBbkqYJKYa/Mnwmt2XVr7cHl5DxgS3eMDB8Vnas6vIS8PqbwYBGs8vJFRXhcsZ9Z O48oEgvTSzLTyiod/cd7nwXB0Se1dVP3+x79enAYQbxzVPajVP2CpwZzX/ccgq08kBu3 c3/A== X-Gm-Message-State: ALoCoQmEP88utt5wmSmYQOyy0SxTQWOLjazIOO/CvH/Atkp17pz1kZZdwIEGJgS5wSbIjy5Eo7Wc X-Received: by 10.68.139.100 with SMTP id qx4mr9481808pbb.144.1389341294839; Fri, 10 Jan 2014 00:08:14 -0800 (PST) Received: from [192.168.0.102] (218-164-101-147.dynamic.hinet.net. [218.164.101.147]) by mx.google.com with ESMTPSA id dq3sm15273946pbc.35.2014.01.10.00.08.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Jan 2014 00:08:13 -0800 (PST) Message-ID: <1389341288.25856.2.camel@phoenix> From: Axel Lin To: u-boot@lists.denx.de Date: Fri, 10 Jan 2014 16:08:08 +0800 X-Mailer: Evolution 3.6.4-0ubuntu1 Mime-Version: 1.0 Cc: Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH] spi: oc_tiny_spi: Refactor to simplify spi_xfer implementation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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, This path is similar to the patch I sent for spi-oc-tiny.c linux driver. I'd appreciate if you can review and test this patch. Regards, Axel drivers/spi/oc_tiny_spi.c | 85 ++++++----------------------------------------- 1 file changed, 11 insertions(+), 74 deletions(-) diff --git a/drivers/spi/oc_tiny_spi.c b/drivers/spi/oc_tiny_spi.c index 4de5d00..a8c1dfd 100644 --- a/drivers/spi/oc_tiny_spi.c +++ b/drivers/spi/oc_tiny_spi.c @@ -158,85 +158,22 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, spi_cs_activate(slave); /* we need to tighten the transfer loop */ - if (txp && rxp) { - writeb(*txp++, ®s->txdata); - if (bytes > 1) { - writeb(*txp++, ®s->txdata); - for (i = 2; i < bytes; i++) { - u8 rx, tx = *txp++; - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXR)) + writeb(txp ? *txp++ : CONFIG_TINY_SPI_IDLE_VAL, ®s->txdata); + for (i = 1; i < bytes; i++) { + writeb(txp ? *txp++ : CONFIG_TINY_SPI_IDLE_VAL, ®s->txdata); + + if (rxp || (i != bytes - 1)) { + while (!(readb(®s->status) & TINY_SPI_STATUS_TXR)) ; - rx = readb(®s->txdata); - writeb(tx, ®s->txdata); - *rxp++ = rx; - } - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXR)) - ; - *rxp++ = readb(®s->txdata); } - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXE)) - ; - *rxp++ = readb(®s->rxdata); - } else if (rxp) { - writeb(CONFIG_TINY_SPI_IDLE_VAL, ®s->txdata); - if (bytes > 1) { - writeb(CONFIG_TINY_SPI_IDLE_VAL, - ®s->txdata); - for (i = 2; i < bytes; i++) { - u8 rx; - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXR)) - ; - rx = readb(®s->txdata); - writeb(CONFIG_TINY_SPI_IDLE_VAL, - ®s->txdata); - *rxp++ = rx; - } - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXR)) - ; + + if (rxp) *rxp++ = readb(®s->txdata); - } - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXE)) + } + while (!(readb(®s->status) & TINY_SPI_STATUS_TXE)) ; + if (rxp) *rxp++ = readb(®s->rxdata); - } else if (txp) { - writeb(*txp++, ®s->txdata); - if (bytes > 1) { - writeb(*txp++, ®s->txdata); - for (i = 2; i < bytes; i++) { - u8 tx = *txp++; - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXR)) - ; - writeb(tx, ®s->txdata); - } - } - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXE)) - ; - } else { - writeb(CONFIG_TINY_SPI_IDLE_VAL, ®s->txdata); - if (bytes > 1) { - writeb(CONFIG_TINY_SPI_IDLE_VAL, - ®s->txdata); - for (i = 2; i < bytes; i++) { - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXR)) - ; - writeb(CONFIG_TINY_SPI_IDLE_VAL, - ®s->txdata); - } - } - while (!(readb(®s->status) & - TINY_SPI_STATUS_TXE)) - ; - } - done: if (flags & SPI_XFER_END) spi_cs_deactivate(slave);