From patchwork Wed Oct 5 16:57:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 678543 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 3sq2BD2g3Mz9s3s for ; Thu, 6 Oct 2016 04:01:40 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C8D90B3888; Wed, 5 Oct 2016 18:59:50 +0200 (CEST) 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 dws7OzyyZ57M; Wed, 5 Oct 2016 18:59:50 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 04A32B3839; Wed, 5 Oct 2016 18:59:32 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1234AA774E for ; Wed, 5 Oct 2016 18:59:26 +0200 (CEST) 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 6RH8S1zu-MCn for ; Wed, 5 Oct 2016 18:59:25 +0200 (CEST) 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-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by theia.denx.de (Postfix) with ESMTPS id 1D3A0A7711 for ; Wed, 5 Oct 2016 18:59:09 +0200 (CEST) Received: by mail-pf0-f196.google.com with SMTP id 190so6104110pfv.1 for ; Wed, 05 Oct 2016 09:59:08 -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=KKwsWRw2/dlq0+QPKgfGInWQmsK7hOqGSMI7epoBdko=; b=B+nQ4pFWTQpsvgCKfn08VBAuI+J9aigPRua9i3x/5UxMycLMYsYjfTg7yX/HkJfHeo IQn0r8CoJ72lJz6WQm2v5AdGIhZmOHRmpYI8IwhepI5OLi7FqlCpfDP2yKyJjYQUdk7U v1EgFUOjnM4hs+FvEgNpqMJH/n56erDvzSV7x+UuZUTSIlotn1vnTQmXyKc8BUJc1fbk SZP0FhQz4ioxvresjebM+BH4+wUiA41QGgB0U0KXpJa3uLQrG9mm8N5/q7BA0gP1Aq0J xELMYVVm/ka15yxkqooaBq28bQhc5b3JdA7RwA8wlzf8V78fJG22pyYOiwVHUzk04ca/ IRDw== X-Gm-Message-State: AA6/9Rk/WbNhzckww47Kf2KdpbGxuf1/veQvMavH+OugCxDb/+0gSSoadFy5/HKbv2szcQ== X-Received: by 10.98.51.66 with SMTP id z63mr17545882pfz.22.1475686747580; Wed, 05 Oct 2016 09:59:07 -0700 (PDT) Received: from Mr.J ([49.204.230.134]) by smtp.gmail.com with ESMTPSA id l82sm9803278pfk.85.2016.10.05.09.59.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Oct 2016 09:59:06 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Wed, 5 Oct 2016 22:27:57 +0530 Message-Id: <1475686682-28576-12-git-send-email-jteki@openedev.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475686682-28576-1-git-send-email-jteki@openedev.com> References: <1475686682-28576-1-git-send-email-jteki@openedev.com> Cc: Jagan Teki , Tom Rini Subject: [U-Boot] [PATCH RFC v8 11/16] 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 --- 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);