From patchwork Wed Feb 10 19:08:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 581564 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 49AE7140325 for ; Thu, 11 Feb 2016 06:13:20 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0BC9BA7600; Wed, 10 Feb 2016 20:11:50 +0100 (CET) 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 H1dxDe-242pR; Wed, 10 Feb 2016 20:11:49 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BCFB5A75CD; Wed, 10 Feb 2016 20:11:37 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EA466A7532 for ; Wed, 10 Feb 2016 20:11:31 +0100 (CET) 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 ConrNqgUYKjj for ; Wed, 10 Feb 2016 20:11:31 +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-f67.google.com (mail-pa0-f67.google.com [209.85.220.67]) by theia.denx.de (Postfix) with ESMTPS id D2C64A74DA for ; Wed, 10 Feb 2016 20:11:14 +0100 (CET) Received: by mail-pa0-f67.google.com with SMTP id fl4so1314506pad.2 for ; Wed, 10 Feb 2016 11:11: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:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BHuQJXoKdZvfAJlHq7Ujd8zV7iNljCl2iYSscCseILU=; b=mkf6fgb8t0DIM7ayN7NRSXhGEGXQuB1BRZMQYV6be9XFo8Jp20R72Se8KJ08XPRZTc wUG0hkHgjFM3d3k+DKBScUwIGZ2nvnPQUq5mBkYfKuxV/jUivcz+PvBS90g0Q3fMLQrP oyeVvAmTOxLmQ4TPc/kO+vya+SNixIafH75UKUWws5YOgTMSTyrD7X5ogB7IzHnZpvB0 E8RiSgdMKrB1Eap50RU9rUqHSdklcokWx1M2CXU71VLt+9isOiQH9NEIGqxUec2+V+mV UGcTdhdJYxLddMW7JJBzDMi7PaLC79OdQ1fx21R57x0VjBHMoGzL8dXcAtonrKSKoWmw CD1Q== X-Gm-Message-State: AG10YORZnswqoMQBnucR8XeT+xZweTWGC0HKqUx3i14Pt1dUhSGTRwt4Ppf3NRIDOz6mIw== X-Received: by 10.66.187.237 with SMTP id fv13mr27620334pac.42.1455131473608; Wed, 10 Feb 2016 11:11:13 -0800 (PST) Received: from localhost.localdomain ([123.236.183.254]) by smtp.gmail.com with ESMTPSA id n78sm6915903pfb.53.2016.02.10.11.11.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Feb 2016 11:11:12 -0800 (PST) From: Jagan Teki To: u-boot@lists.denx.de Date: Thu, 11 Feb 2016 00:38:10 +0530 Message-Id: <1455131307-25406-16-git-send-email-jteki@openedev.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455131307-25406-1-git-send-email-jteki@openedev.com> References: <1455131307-25406-1-git-send-email-jteki@openedev.com> Cc: Tom Rini , Michal Simek , Siva Durga Prasad Paladugu , Jagan Teki Subject: [U-Boot] [PATCH v5 15/32] spi: Rename spi_read_then_write to spi_write_then_read X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Since spi_read_then_write moved into spi layer, the meaning of data transfer is also change from read_then_write to write_then_read, this means first spi will write the opcode through and then read the respective buffer. Cc: Simon Glass Cc: Bin Meng Cc: Mugunthan V N Cc: Michal Simek Cc: Siva Durga Prasad Paladugu Signed-off-by: Jagan Teki --- drivers/mtd/spi-nor/m25p80.c | 8 ++++---- drivers/spi/spi-uclass.c | 19 +++++++++---------- drivers/spi/spi.c | 19 +++++++++---------- include/spi.h | 23 +++++++++++++++++++---- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/drivers/mtd/spi-nor/m25p80.c b/drivers/mtd/spi-nor/m25p80.c index 4aefe93..7e2702d 100644 --- a/drivers/mtd/spi-nor/m25p80.c +++ b/drivers/mtd/spi-nor/m25p80.c @@ -39,7 +39,7 @@ static int m25p80_read_reg(struct spi_nor *nor, u8 cmd, u8 *val, int len) if (nor->flags & SNOR_F_U_PAGE) spi->flags |= SPI_XFER_U_PAGE; - ret = spi_read_then_write(spi, &cmd, 1, NULL, val, len); + ret = spi_write_then_read(spi, &cmd, 1, NULL, val, len); if (ret < 0) { debug("m25p80: error %d reading register %x\n", ret, cmd); return ret; @@ -65,7 +65,7 @@ static int m25p80_write_reg(struct spi_nor *nor, u8 cmd, u8 *buf, int len) if (nor->flags & SNOR_F_U_PAGE) spi->flags |= SPI_XFER_U_PAGE; - ret = spi_read_then_write(spi, &cmd, 1, buf, NULL, len); + ret = spi_write_then_read(spi, &cmd, 1, buf, NULL, len); if (ret < 0) { debug("m25p80: error %d writing register %x\n", ret, cmd); return ret; @@ -119,7 +119,7 @@ static int m25p80_read(struct spi_nor *nor, const u8 *cmd, size_t cmd_len, if (nor->flags & SNOR_F_U_PAGE) spi->flags |= SPI_XFER_U_PAGE; - ret = spi_read_then_write(spi, cmd, cmd_len, NULL, data, data_len); + ret = spi_write_then_read(spi, cmd, cmd_len, NULL, data, data_len); if (ret < 0) { debug("m25p80: error %d reading %x\n", ret, *cmd); return ret; @@ -146,7 +146,7 @@ static int m25p80_write(struct spi_nor *nor, const u8 *cmd, size_t cmd_len, if (nor->flags & SNOR_F_U_PAGE) spi->flags |= SPI_XFER_U_PAGE; - ret = spi_read_then_write(spi, cmd, cmd_len, data, NULL, data_len); + ret = spi_write_then_read(spi, cmd, cmd_len, data, NULL, data_len); if (ret < 0) { debug("m25p80: error %d writing %x\n", ret, *cmd); return ret; diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 7728eac..0dfdd8b 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -95,26 +95,25 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, return spi_get_ops(bus)->xfer(dev, bitlen, dout, din, flags); } -int spi_read_then_write(struct spi_slave *spi, const u8 *cmd, - size_t cmd_len, const u8 *data_out, - u8 *data_in, size_t data_len) +int spi_write_then_read(struct spi_slave *slave, const u8 *opcode, + size_t n_opcode, const u8 *txbuf, u8 *rxbuf, + size_t n_buf) { unsigned long flags = SPI_XFER_BEGIN; int ret; - if (data_len == 0) + if (n_buf == 0) flags |= SPI_XFER_END; - ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, flags); + ret = spi_xfer(slave, n_opcode * 8, opcode, NULL, flags); if (ret) { debug("spi: failed to send command (%zu bytes): %d\n", - cmd_len, ret); - } else if (data_len != 0) { - ret = spi_xfer(spi, data_len * 8, data_out, data_in, - SPI_XFER_END); + n_opcode, ret); + } else if (n_buf != 0) { + ret = spi_xfer(slave, n_buf * 8, txbuf, rxbuf, SPI_XFER_END); if (ret) debug("spi: failed to transfer %zu bytes of data: %d\n", - data_len, ret); + n_buf, ret); } return ret; diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index a050386..c8051f9 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -39,26 +39,25 @@ void *spi_do_alloc_slave(int offset, int size, unsigned int bus, return ptr; } -int spi_read_then_write(struct spi_slave *spi, const u8 *cmd, - size_t cmd_len, const u8 *data_out, - u8 *data_in, size_t data_len) +int spi_write_then_read(struct spi_slave *slave, const u8 *opcode, + size_t n_opcode, const u8 *txbuf, u8 *rxbuf, + size_t n_buf) { unsigned long flags = SPI_XFER_BEGIN; int ret; - if (data_len == 0) + if (n_buf == 0) flags |= SPI_XFER_END; - ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, flags); + ret = spi_xfer(slave, n_opcode * 8, opcode, NULL, flags); if (ret) { debug("spi: failed to send command (%zu bytes): %d\n", - cmd_len, ret); - } else if (data_len != 0) { - ret = spi_xfer(spi, data_len * 8, data_out, data_in, - SPI_XFER_END); + n_opcode, ret); + } else if (n_buf != 0) { + ret = spi_xfer(slave, n_buf * 8, txbuf, rxbuf, SPI_XFER_END); if (ret) debug("spi: failed to transfer %zu bytes of data: %d\n", - data_len, ret); + n_buf, ret); } return ret; diff --git a/include/spi.h b/include/spi.h index 19589aa..dd0b11b 100644 --- a/include/spi.h +++ b/include/spi.h @@ -265,10 +265,25 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen); int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, void *din, unsigned long flags); -/* spi_write_then_read - SPI synchronous read followed by write */ -int spi_read_then_write(struct spi_slave *spi, const u8 *cmd, - size_t cmd_len, const u8 *data_out, - u8 *data_in, size_t data_len); +/** + * spi_write_then_read - SPI synchronous write followed by read + * + * This performs a half duplex transaction in which the first transaction + * is to send the opcode and if the length of buf is non-zero then it start + * the second transaction as tx or rx based on the need from respective slave. + * + * @slave: slave device with which opcode/data will be exchanged + * @opcode: opcode used for specific transfer + * @n_opcode: size of opcode, in bytes + * @txbuf: buffer into which data to be written + * @rxbuf: buffer into which data will be read + * @n_buf: size of buf (whether it's [tx|rx]buf), in bytes + * + * Returns: 0 on success, not 0 on failure + */ +int spi_write_then_read(struct spi_slave *slave, const u8 *opcode, + size_t n_opcode, const u8 *txbuf, u8 *rxbuf, + size_t n_buf); /* Copy memory mapped data */ void spi_flash_copy_mmap(void *data, void *offset, size_t len);