From patchwork Sun Oct 30 18:23:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 689017 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 3t6Qtg5Fnhz9t17 for ; Mon, 31 Oct 2016 05:26:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3C9B5A75BA; Sun, 30 Oct 2016 19:25:57 +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 Chl56YXxT7kS; Sun, 30 Oct 2016 19:25:57 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9B54AA75F0; Sun, 30 Oct 2016 19:25:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CBD6AB381C for ; Sun, 30 Oct 2016 19:25:28 +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 gzPulBLQsdwM for ; Sun, 30 Oct 2016 19:25:28 +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-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by theia.denx.de (Postfix) with ESMTPS id 3FB16A75AC for ; Sun, 30 Oct 2016 19:25:21 +0100 (CET) Received: by mail-pf0-f193.google.com with SMTP id y68so780338pfb.1 for ; Sun, 30 Oct 2016 11:25:21 -0700 (PDT) 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=5gAjDNcuSi6YQWf8Vo5bT6XM3Fe3ZeRel8JMlkFJmRI=; b=cQNLbY6IJx8ldOM1ryeWDj/iwCbQfcyZIreWoCoRUn4tulDEcbCGcpekAKSdR48Rbn pnqhaajOYVF/O0so3mO0cy0LJRCd30eclzH0/T1brJjJVo05z9wz/clQ8Iksvs1KvGwF Y5FhuVLnh1kvavGiveSeHqoc80ueCxdBKJuwgTalXHGQCet/dYEqNW5P6uOFao6/rOb9 RqWXjk4BvP9bd0H3BwrBU3mvhPeLXFwAdupb/x5Ct3zFBOa4gdUEVP2E1WQZ9bYYvP4d BGt4F51b/uGXC2yyEehFgqr+YTC/j50aI3E5FsTWEK465ElIOuZD4ZEj9H4dVwfIL40Q JVHQ== X-Gm-Message-State: ABUngvcXp0lck0LPug+AJojPQHSdtdQfiajKsnewdHk6Ysl3YxUpbDo/nZe0hwbfzCJQ7w== X-Received: by 10.98.11.71 with SMTP id t68mr2266272pfi.136.1477851919441; Sun, 30 Oct 2016 11:25:19 -0700 (PDT) Received: from Mr.J ([49.204.230.134]) by smtp.gmail.com with ESMTPSA id k7sm31357901pan.8.2016.10.30.11.25.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Oct 2016 11:25:18 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Sun, 30 Oct 2016 23:53:43 +0530 Message-Id: <1477851833-23960-12-git-send-email-jagan@openedev.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477851833-23960-1-git-send-email-jagan@openedev.com> References: <1477851833-23960-1-git-send-email-jagan@openedev.com> Cc: Tom Rini , Stefan Roese , Jagan Teki Subject: [U-Boot] [PATCH v9 11/21] spi: Add 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" Add support for SPI synchronous write followed by read, this is common interface call from spi-nor to spi drivers. Signed-off-by: Jagan Teki Reviewed-by: Simon Glass --- drivers/spi/spi-uclass.c | 24 ++++++++++++++++++++++++ include/spi.h | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index d9c49e4..bb33fd8 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -108,6 +108,30 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, return dm_spi_xfer(slave->dev, bitlen, dout, din, flags); } +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 (n_buf == 0) + flags |= SPI_XFER_END; + + ret = spi_xfer(slave, n_opcode * 8, opcode, NULL, flags); + if (ret) { + debug("spi: failed to send command (%zu bytes): %d\n", + 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", + n_buf, ret); + } + + return ret; +} + static int spi_child_post_bind(struct udevice *dev) { struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev); diff --git a/include/spi.h b/include/spi.h index 4c17983..336ac99 100644 --- a/include/spi.h +++ b/include/spi.h @@ -258,6 +258,26 @@ 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 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);