From patchwork Wed Feb 10 19:08:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 581563 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 B4F80140325 for ; Thu, 11 Feb 2016 06:13:05 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2FD07A75E4; Wed, 10 Feb 2016 20:11:44 +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 q_RDdpZ1UpZX; Wed, 10 Feb 2016 20:11:43 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B2CE8A75F6; Wed, 10 Feb 2016 20:11:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2FA0DA75B6 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 srpQInkuSFGo 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 62471A75BF for ; Wed, 10 Feb 2016 20:11:10 +0100 (CET) Received: by mail-pa0-f67.google.com with SMTP id yy13so1321673pab.1 for ; Wed, 10 Feb 2016 11:11:10 -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=suM0EC2A7gkKGL4Ev7UqySr4Plc4pL5TXyib4J5OCZk=; b=ZtsJOWNChTODD6BL9PUsToYGtvMqFqrA958mo45VzTUNkchYWCNKUXB2cngglIVzsb /9gp4S1Xiu1NlbdSz78MNCIicA2JPICPZL80ZwtxrM+JFRah+SzuN3XtxAFiWithIczw PmA/mQIAuB/8jVD7r6OoS+TWiXC4DWYF5pwCG0cgsw9N2QHiQ0crNEA1Mg6+pijLkLL3 DGLzdikMkXyClngys1ZLpQ2OgK+AQwfQa/8dRo2r97MdlMZS8t5vBPGPIL0NhC7oJuZI Z9QfWUfExr2DjWp2y5R+BweCk68waB7nQ0wFJkSwO+6kkIOxyaj+CZKnYzHQAheeznF+ SzzA== X-Gm-Message-State: AG10YOQ/P0CgMfE5htlucDoh8Po9yVT2iH/IU96sljKtlj8arXV35+C9gfHJRRXCax9RPw== X-Received: by 10.66.237.35 with SMTP id uz3mr60558492pac.96.1455131469108; Wed, 10 Feb 2016 11:11:09 -0800 (PST) Received: from localhost.localdomain ([123.236.183.254]) by smtp.gmail.com with ESMTPSA id n78sm6915903pfb.53.2016.02.10.11.11.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Feb 2016 11:11:08 -0800 (PST) From: Jagan Teki To: u-boot@lists.denx.de Date: Thu, 11 Feb 2016 00:38:09 +0530 Message-Id: <1455131307-25406-15-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 14/32] mtd: spi-nor: Move spi_read_then_write to spi layer 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 is doing spi operations like setting up commands, tx and rx through spi_xfer, So it is meanfull to have this definition at spi layer and flash layer should use this whenever required. 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 | 25 ------------------------- drivers/spi/spi-uclass.c | 25 +++++++++++++++++++++++++ drivers/spi/spi.c | 25 +++++++++++++++++++++++++ include/spi.h | 5 +++++ 4 files changed, 55 insertions(+), 25 deletions(-) diff --git a/drivers/mtd/spi-nor/m25p80.c b/drivers/mtd/spi-nor/m25p80.c index f0340a5..4aefe93 100644 --- a/drivers/mtd/spi-nor/m25p80.c +++ b/drivers/mtd/spi-nor/m25p80.c @@ -24,31 +24,6 @@ struct m25p { #endif }; -static 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) -{ - unsigned long flags = SPI_XFER_BEGIN; - int ret; - - if (data_len == 0) - flags |= SPI_XFER_END; - - ret = spi_xfer(spi, cmd_len * 8, cmd, NULL, flags); - if (ret) { - debug("SF: 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); - if (ret) - debug("SF: Failed to transfer %zu bytes of data: %d\n", - data_len, ret); - } - - return ret; -} - static int m25p80_read_reg(struct spi_nor *nor, u8 cmd, u8 *val, int len) { struct m25p *flash = nor->priv; diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index 677c020..7728eac 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -95,6 +95,31 @@ 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) +{ + unsigned long flags = SPI_XFER_BEGIN; + int ret; + + if (data_len == 0) + flags |= SPI_XFER_END; + + ret = spi_xfer(spi, cmd_len * 8, cmd, 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); + if (ret) + debug("spi: failed to transfer %zu bytes of data: %d\n", + data_len, ret); + } + + return ret; +} + static int spi_post_bind(struct udevice *dev) { /* Scan the bus for devices */ diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 7d81fbd..a050386 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -39,6 +39,31 @@ 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) +{ + unsigned long flags = SPI_XFER_BEGIN; + int ret; + + if (data_len == 0) + flags |= SPI_XFER_END; + + ret = spi_xfer(spi, cmd_len * 8, cmd, 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); + if (ret) + debug("spi: failed to transfer %zu bytes of data: %d\n", + data_len, ret); + } + + return ret; +} + #ifdef CONFIG_OF_SPI struct spi_slave *spi_base_setup_slave_fdt(const void *blob, int busnum, int node) diff --git a/include/spi.h b/include/spi.h index 4b88d39..19589aa 100644 --- a/include/spi.h +++ b/include/spi.h @@ -265,6 +265,11 @@ 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); + /* Copy memory mapped data */ void spi_flash_copy_mmap(void *data, void *offset, size_t len);