[U-Boot] [PATCH 03/16] spi: Add non DM version of SPI_MEM

Jagan Teki jagan at amarulasolutions.com
Mon Jan 28 06:57:05 UTC 2019


On Wed, Dec 12, 2018 at 11:08 PM Vignesh R <vigneshr at ti.com> wrote:
>
> Add non DM version of SPI_MEM to support easy migration to new SPI NOR
> framework. This can be removed once DM_SPI conversion is complete.
>
> Signed-off-by: Vignesh R <vigneshr at ti.com>
> ---
>  drivers/spi/Kconfig        |  4 +-
>  drivers/spi/Makefile       |  1 +
>  drivers/spi/spi-mem-nodm.c | 89 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 92 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/spi/spi-mem-nodm.c
>
> diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> index a7bb5b35c294..5ee855fc5319 100644
> --- a/drivers/spi/Kconfig
> +++ b/drivers/spi/Kconfig
> @@ -16,8 +16,6 @@ config DM_SPI
>           typically use driver-private data instead of extending the
>           spi_slave structure.
>
> -if DM_SPI
> -
>  config SPI_MEM
>         bool "SPI memory extension"
>         help
> @@ -25,6 +23,8 @@ config SPI_MEM
>           This extension is meant to simplify interaction with SPI memories
>           by providing an high-level interface to send memory-like commands.
>
> +if DM_SPI
> +
>  config ALTERA_SPI
>         bool "Altera SPI driver"
>         help
> diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
> index 392a92579578..32ba3b61f70d 100644
> --- a/drivers/spi/Makefile
> +++ b/drivers/spi/Makefile
> @@ -11,6 +11,7 @@ obj-$(CONFIG_SOFT_SPI) += soft_spi.o
>  obj-$(CONFIG_SPI_MEM) += spi-mem.o
>  else
>  obj-y += spi.o
> +obj-$(CONFIG_SPI_MEM) += spi-mem-nodm.o
>  obj-$(CONFIG_SOFT_SPI) += soft_spi_legacy.o
>  endif
>
> diff --git a/drivers/spi/spi-mem-nodm.c b/drivers/spi/spi-mem-nodm.c
> new file mode 100644
> index 000000000000..4d91761f56d3
> --- /dev/null
> +++ b/drivers/spi/spi-mem-nodm.c
> @@ -0,0 +1,89 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
> + */
> +
> +#include <spi.h>
> +#include <spi-mem.h>
> +
> +int spi_mem_exec_op(struct spi_slave *slave,
> +                   const struct spi_mem_op *op)
> +{
> +       unsigned int pos = 0;
> +       const u8 *tx_buf = NULL;
> +       u8 *rx_buf = NULL;
> +       u8 *op_buf;
> +       int op_len;
> +       u32 flag;
> +       int ret;
> +       int i;
> +
> +       if (op->data.nbytes) {
> +               if (op->data.dir == SPI_MEM_DATA_IN)
> +                       rx_buf = op->data.buf.in;
> +               else
> +                       tx_buf = op->data.buf.out;
> +       }
> +
> +       op_len = sizeof(op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes;
> +       op_buf = calloc(1, op_len);
> +
> +       ret = spi_claim_bus(slave);
> +       if (ret < 0)
> +               return ret;
> +
> +       op_buf[pos++] = op->cmd.opcode;
> +
> +       if (op->addr.nbytes) {
> +               for (i = 0; i < op->addr.nbytes; i++)
> +                       op_buf[pos + i] = op->addr.val >>
> +                               (8 * (op->addr.nbytes - i - 1));
> +
> +               pos += op->addr.nbytes;
> +       }
> +
> +       if (op->dummy.nbytes)
> +               memset(op_buf + pos, 0xff, op->dummy.nbytes);
> +
> +       /* 1st transfer: opcode + address + dummy cycles */
> +       flag = SPI_XFER_BEGIN;
> +       /* Make sure to set END bit if no tx or rx data messages follow */
> +       if (!tx_buf && !rx_buf)
> +               flag |= SPI_XFER_END;
> +
> +       ret = spi_xfer(slave, op_len * 8, op_buf, NULL, flag);
> +       if (ret)
> +               return ret;
> +
> +       /* 2nd transfer: rx or tx data path */
> +       if (tx_buf || rx_buf) {
> +               ret = spi_xfer(slave, op->data.nbytes * 8, tx_buf,
> +                              rx_buf, SPI_XFER_END);
> +               if (ret)
> +                       return ret;
> +       }
> +
> +       spi_release_bus(slave);
> +
> +       for (i = 0; i < pos; i++)
> +               debug("%02x ", op_buf[i]);
> +       debug("| [%dB %s] ",
> +             tx_buf || rx_buf ? op->data.nbytes : 0,
> +             tx_buf || rx_buf ? (tx_buf ? "out" : "in") : "-");
> +       for (i = 0; i < op->data.nbytes; i++)
> +               debug("%02x ", tx_buf ? tx_buf[i] : rx_buf[i]);
> +       debug("[ret %d]\n", ret);
> +
> +       free(op_buf);
> +
> +       if (ret < 0)
> +               return ret;
> +
> +       return 0;
> +}
> +
> +int spi_mem_adjust_op_size(struct spi_slave *slave,
> +                          struct spi_mem_op *op)
> +{
> +       return 0;

Does it not return data size of SPI mem, or not need for non-dm?


More information about the U-Boot mailing list