From: Jagan Teki <jteki@openedev.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 19/76] spi: Rename spi_read_then_write to spi_write_then_read
Date: Mon, 15 Feb 2016 02:18:18 +0530 [thread overview]
Message-ID: <1455482955-19053-19-git-send-email-jteki@openedev.com> (raw)
In-Reply-To: <1455482955-19053-1-git-send-email-jteki@openedev.com>
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 <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Mugunthan V N <mugunthanvnm@ti.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
Signed-off-by: Jagan Teki <jteki@openedev.com>
---
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);
--
1.9.1
next prev parent reply other threads:[~2016-02-14 20:48 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-14 20:48 [U-Boot] [PATCH v6 01/76] mtd: Add m25p80 driver Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 02/76] mtd: Add Kconfig entry for MTD_M25P80 Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 03/76] mtd: Add SPI-NOR core support Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 04/76] doc: device-tree-bindings: jedec, spi-nor Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 05/76] mtd: spi-nor: Add Kconfig entry for MTD_SPI_NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 06/76] mtd: spi-nor: Add kconfig for MTD_SPI_NOR_USE_4K_SECTORS Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 07/76] mtd: spi-nor: Add MTD support Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 08/76] mtd: spi-nor: Add spi_nor support in m25p80 Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 09/76] mtd: spi-nor: Add dm spi-nor probing Jagan Teki
2016-02-15 9:15 ` Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 10/76] mtd: spi-nor: Add spi_flash_probe for mtd-dm-spi-nor Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 11/76] mtd: spi-nor: Add spi_flash_free " Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 12/76] mtd: spi-nor: m25p80: Add spi_nor support for non-dm Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 13/76] sf: Rename erase_size to erasesize Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 14/76] sf: Use erasesize instead of sector_size Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 15/76] sf: Use uint64_t for flash->size Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 16/76] spi_flash: Use mtd_info operation for SPI-NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 17/76] spi_flash: Use spi_flash_t instead of struct spi_flash Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 18/76] mtd: spi-nor: Move spi_read_then_write to spi layer Jagan Teki
2016-02-14 20:48 ` Jagan Teki [this message]
2016-02-14 20:48 ` [U-Boot] [PATCH v6 20/76] mtd: spi-nor: Rename SPI_FLASH_BAR to SPI_NOR_BAR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 21/76] mtd: spi-nor: Add Kconfig entry for SPI_NOR_BAR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 22/76] mtd: spi-nor: Copy spl files from drivers/mtd/spi Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 23/76] mtd: spi-nor: spl: Follow ascending order of include headers Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 24/76] mtd: spi-nor: fsl_espi_spl: Use mtd_info Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 25/76] mtd: spi-nor: spi_spl_load: " Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 26/76] mtd: spi-nor: Add flash vendor Kconfig entries Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 27/76] arm: zynq: Kconfig: Select MTD uclass Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 28/76] arm: zynq: Kconfig: Drop DM_SPI_FLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 29/76] defconfigs: zynq_microzed: Drop CONFIG_SPI_FLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 30/76] defconfig: zynq_microzed: Enable CONFIG_MTD_M25P80 Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 31/76] defconfig: zynq_microzed: Enable CONFIG_MTD_SPI_NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 32/76] spl: Add CONFIG_SPL_SPI_NOR_SUPPORT Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 33/76] configs: zynq: Use CONFIG_SPL_SPI_NOR_SUPPORT Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 34/76] configs: zynq: Use CONFIG_SPL_MTD_SUPPORT Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 35/76] mtd: spi-nor: Copy sf_dataflash Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 36/76] mtd: dataflash: Remove unneeded spi data Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 37/76] mtd: dataflash: Move flash id detection into jedec_probe Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 38/76] mtd: dataflash: Fix add_dataflash return logic Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 39/76] mtd: dataflash: Add UCLASS_MTD support Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 40/76] mtd: dataflash: Use spi_write_then_read Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 41/76] mtd: dataflash: Drop sf_internal.h Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 42/76] mtd: dataflash: Minor cleanups Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 43/76] mtd: Rename sf_dataflash.c to mtd_dataflash.c Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 44/76] mtd: spi-nor: Add Kconfig entry for mtd_dataflash Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 45/76] mtd: dataflash: Add MTD_DATAFLASH_WRITE_VERIFY Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 46/76] mtd: spi-nor: Add kconfig MTD_DATAFLASH_WRITE_VERIFY Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 47/76] configs: ls1021aqds: Drop DM_SPI_FLASH and DATAFLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 48/76] defconfig: ls1021aqds_qspi: Enable SPI-NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 49/76] defconfig: ls1021aqds_qspi: Enable CONFIG_MTD_DATAFLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 50/76] mtd: spi-nor: Copy sandbox Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 51/76] mtd: spi-nor: sandbox: Use spi-nor header Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 52/76] mtd: spi-nor: Add SPI_NOR_SANBOX Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 53/76] sandbox: kconfig: Drop DM_SPI_FLASH Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 54/76] sandbox: kconfig: Select MTD uclass Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 55/76] defconfigs: sandbox: Enable SPI-NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 56/76] mtd: sandbox: Use CONFIG_MTD_SPI_NOR Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 57/76] defconfigs: sandbox: Enable SPI_NOR_SANDBOX Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 58/76] spi_flash: Use spi_flash_t Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 59/76] mtd: spi-nor: Add CONFIG_SPI_NOR_MISC Jagan Teki
2016-02-14 20:48 ` [U-Boot] [PATCH v6 60/76] config: Enable SPI-NOR framework Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 61/76] spi-nor: Use CONFIG_MTD_SPI_NOR Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 62/76] configs: " Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 63/76] configs: Use CONFIG_SPI_NOR_BAR Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 64/76] configs: spi-nor: Add new flash vendor configs Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 65/76] configs: Use CONFIG_SPI_NOR_MISC Jagan Teki
2016-02-17 8:53 ` Bin Meng
2016-02-17 9:05 ` Jagan Teki
2016-02-17 9:09 ` Bin Meng
2016-02-17 9:31 ` Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 66/76] spi: Drop mode_rx Jagan Teki
2016-02-15 11:16 ` Bin Meng
2016-02-15 13:07 ` Jagan Teki
2016-02-16 1:08 ` Bin Meng
2016-02-14 20:49 ` [U-Boot] [PATCH v6 67/76] spi: Drop SPI_RX_FAST Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 68/76] configs: Enable MTD uclass in missing configs Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 69/76] configs: Drop CONFIG_SPI_FLASH_MTD Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 70/76] uclass: Replace UCLASS_SPI_FLASH with UCLASS_MTD Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 71/76] uclass: Drop UCLASS_SPI_FLASH Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 72/76] configs: Use CONFIG_SPL_SPI_NOR_SUPPORT Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 73/76] configs: Enable CONFIG_SPL_MTD_SUPPORT Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 74/76] sf: Drop entire spi-flash framework Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 75/76] MAINTAINERS: Add myself as SPI NOR maintainer Jagan Teki
2016-02-14 20:49 ` [U-Boot] [PATCH v6 76/76] configs: CONFIG_MTD_SPI_NOR_USE_4K_SECTORS Jagan Teki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455482955-19053-19-git-send-email-jteki@openedev.com \
--to=jteki@openedev.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox