From: Serge Semin <fancer.lancer@gmail.com>
To: Sudip Mukherjee <sudip.mukherjee@sifive.com>
Cc: Serge Semin <Sergey.Semin@baikalelectronics.ru>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
greentime.hu@sifive.com, jude.onyenegecha@sifive.com,
william.salmon@sifive.com, adnan.chowdhury@sifive.com,
ben.dooks@sifive.com, linux-spi@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
jeegar.lakhani@sifive.com
Subject: Re: [PATCH 09/11] spi: dw: prepare the transfer routine for enhanced mode
Date: Sat, 27 Aug 2022 02:19:22 +0300 [thread overview]
Message-ID: <20220826231922.4jr73tzpt3vwpxyd@mobilestation> (raw)
In-Reply-To: <20220802175755.6530-10-sudip.mukherjee@sifive.com>
On Tue, Aug 02, 2022 at 06:57:53PM +0100, Sudip Mukherjee wrote:
> The transfer routine of dual/quad/octal is similar to standard SPI mode
> except that we do not need to worry about CS being de-asserted and we
> will be writing the address to a single FIFO location.
Please redesign this patch to having the IRQ-based transfers. For
instance you can just create a new dw_spi_enh_write_then_read() method
which would initialize the IRQs, set up a custom
dw_spi_enh_transfer_handler() method as transfer_handler (or perhaps
re-use the already available dw_spi_transfer_handler() method?) and
initiate the transfer by writing the command and address data to the
Tx FIFO.
Feel free to create some preparation patches if it's needed to reach the
goal.
-Sergey
>
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@sifive.com>
> ---
> drivers/spi/spi-dw-core.c | 141 +++++++++++++++++++++++++++++++++-----
> 1 file changed, 125 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
> index 2564a2276572..d6afa75e7023 100644
> --- a/drivers/spi/spi-dw-core.c
> +++ b/drivers/spi/spi-dw-core.c
> @@ -712,6 +712,28 @@ static int dw_spi_wait_mem_op_done(struct dw_spi *dws)
> return 0;
> }
>
> +static void ext_transfer_delay(struct dw_spi *dws)
> +{
> + struct spi_delay delay;
> + unsigned long ns, us;
> + u32 nents;
> +
> + nents = dw_readl(dws, DW_SPI_TXFLR);
> + ns = NSEC_PER_SEC / dws->current_freq * nents;
> + ns *= dws->n_bytes * BITS_PER_BYTE;
> + if (ns <= NSEC_PER_USEC) {
> + delay.unit = SPI_DELAY_UNIT_NSECS;
> + delay.value = ns;
> + } else {
> + us = DIV_ROUND_UP(ns, NSEC_PER_USEC);
> + delay.unit = SPI_DELAY_UNIT_USECS;
> + delay.value = clamp_val(us, 0, USHRT_MAX);
> + }
> + /* wait until there is some space in TX FIFO */
> + while (!(dw_readl(dws, DW_SPI_SR) & DW_SPI_SR_TF_NOT_FULL))
> + spi_delay_exec(&delay, NULL);
> +}
> +
> static void dw_spi_stop_mem_op(struct dw_spi *dws, struct spi_device *spi)
> {
> dw_spi_enable_chip(dws, 0);
> @@ -719,6 +741,82 @@ static void dw_spi_stop_mem_op(struct dw_spi *dws, struct spi_device *spi)
> dw_spi_enable_chip(dws, 1);
> }
>
> +static int enhanced_transfer(struct dw_spi *dws, struct spi_device *spi,
> + const struct spi_mem_op *op)
> +{
> + u32 max, txw = 0, rxw;
> + bool cs_done = false;
> + void *buf = dws->tx;
> + int ret;
> +
> + /* Send cmd as 32 bit value */
> + if (buf) {
> + txw = *(u32 *)(buf);
> + dw_write_io_reg(dws, DW_SPI_DR, txw);
> + buf += 4;
> + dws->tx_len--;
> + if (op->addr.nbytes) {
> + /*
> + * Send address as 32 bit value if address
> + * is present in the instruction.
> + */
> + txw = *(u32 *)(buf);
> + dw_write_io_reg(dws, DW_SPI_DR, txw);
> + buf += 4;
> + dws->tx_len--;
> + }
> + }
> +
> + do {
> + max = min_t(u32, dws->tx_len, dws->fifo_len -
> + dw_readl(dws, DW_SPI_TXFLR));
> + while (max--) {
> + if (buf) {
> + txw = *(u8 *)(buf);
> + buf += dws->n_bytes;
> + }
> + dw_write_io_reg(dws, DW_SPI_DR, txw);
> + --dws->tx_len;
> + }
> + /* Enable CS after filling up FIFO */
> + if (!cs_done) {
> + dw_spi_set_cs(spi, false);
> + cs_done = true;
> + }
> + ext_transfer_delay(dws);
> + if (!dws->tx_len && !dws->rx_len) {
> + /*
> + * We only need to wait for done if there is
> + * nothing to receive and there is nothing more
> + * to transmit. If we are receiving, then the
> + * wait cycles will make sure we wait.
> + */
> + ret = dw_spi_wait_mem_op_done(dws);
> + if (ret)
> + return ret;
> + }
> + } while (dws->tx_len);
> +
> + buf = dws->rx;
> + while (dws->rx_len) {
> + max = dw_spi_rx_max(dws);
> +
> + while (max--) {
> + rxw = dw_read_io_reg(dws, DW_SPI_DR);
> + if (buf) {
> + *(u8 *)(buf) = rxw;
> + buf += dws->n_bytes;
> + }
> + --dws->rx_len;
> + }
> +
> + ret = dw_spi_check_status(dws, true);
> + if (ret)
> + return ret;
> + }
> + return 0;
> +}
> +
> static void update_spi_ctrl0(struct dw_spi *dws, const struct spi_mem_op *op, bool enable)
> {
> u32 spi_ctrlr0;
> @@ -846,25 +944,36 @@ static int dw_spi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op)
> * manually restricting the SPI bus frequency using the
> * dws->max_mem_freq parameter.
> */
> - local_irq_save(flags);
> - preempt_disable();
> + if (!enhanced_spi) {
> + local_irq_save(flags);
> + preempt_disable();
>
> - ret = dw_spi_write_then_read(dws, mem->spi);
> + ret = dw_spi_write_then_read(dws, mem->spi);
>
> - local_irq_restore(flags);
> - preempt_enable();
> + local_irq_restore(flags);
> + preempt_enable();
>
> - /*
> - * Wait for the operation being finished and check the controller
> - * status only if there hasn't been any run-time error detected. In the
> - * former case it's just pointless. In the later one to prevent an
> - * additional error message printing since any hw error flag being set
> - * would be due to an error detected on the data transfer.
> - */
> - if (!ret) {
> - ret = dw_spi_wait_mem_op_done(dws);
> - if (!ret)
> - ret = dw_spi_check_status(dws, true);
> + /*
> + * Wait for the operation being finished and check the
> + * controller status only if there hasn't been any
> + * run-time error detected. In the former case it's
> + * just pointless. In the later one to prevent an
> + * additional error message printing since any hw error
> + * flag being set would be due to an error detected on
> + * the data transfer.
> + */
> + if (!ret) {
> + ret = dw_spi_wait_mem_op_done(dws);
> + if (!ret)
> + ret = dw_spi_check_status(dws, true);
> + }
> + } else {
> + /*
> + * We donot need to disable IRQs as clock stretching will
> + * be enabled in enhanced mode which will prevent CS
> + * from being de-assert.
> + */
> + ret = enhanced_transfer(dws, mem->spi, op);
> }
>
> dw_spi_stop_mem_op(dws, mem->spi);
> --
> 2.30.2
>
next prev parent reply other threads:[~2022-08-26 23:19 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 17:57 [PATCH 00/11] Add support for enhanced SPI for Designware SPI controllers Sudip Mukherjee
2022-08-02 17:57 ` [PATCH 01/11] spi: dw: define capability for enhanced spi Sudip Mukherjee
2022-08-02 18:47 ` Mark Brown
2022-08-03 17:34 ` Sudip Mukherjee
2022-08-03 17:40 ` Mark Brown
2022-08-26 18:16 ` Serge Semin
2022-08-02 17:57 ` [PATCH 02/11] spi: dw: add check for support of dual/quad/octal Sudip Mukherjee
2022-08-26 21:36 ` Serge Semin
2022-08-02 17:57 ` [PATCH 03/11] spi: dw: define spi_frf for dual/quad/octal modes Sudip Mukherjee
2022-08-26 22:03 ` Serge Semin
2022-08-26 22:22 ` Serge Semin
2022-08-02 17:57 ` [PATCH 04/11] spi: dw: use TMOD_RO to read in enhanced spi modes Sudip Mukherjee
2022-08-02 19:13 ` Mark Brown
2022-08-03 17:35 ` Sudip Mukherjee
2022-08-26 22:12 ` Serge Semin
2022-08-02 17:57 ` [PATCH 05/11] spi: dw: define SPI_CTRLR0 register and its fields Sudip Mukherjee
2022-08-26 22:19 ` Serge Semin
2022-08-02 17:57 ` [PATCH 06/11] spi: dw: update SPI_CTRLR0 register Sudip Mukherjee
2022-08-26 22:50 ` Serge Semin
2022-08-02 17:57 ` [PATCH 07/11] spi: dw: update NDF while writing in enhanced spi mode Sudip Mukherjee
2022-08-26 22:54 ` Serge Semin
2022-08-02 17:57 ` [PATCH 08/11] spi: dw: update buffer for " Sudip Mukherjee
2022-08-26 23:05 ` Serge Semin
2022-08-02 17:57 ` [PATCH 09/11] spi: dw: prepare the transfer routine for enhanced mode Sudip Mukherjee
2022-08-26 23:19 ` Serge Semin [this message]
2022-08-02 17:57 ` [PATCH 10/11] spi: dw-apb-ssi: add generic 1.03a version Sudip Mukherjee
2022-08-03 6:35 ` Krzysztof Kozlowski
2022-08-26 23:23 ` Serge Semin
2022-08-26 23:33 ` Serge Semin
2022-08-02 17:57 ` [PATCH 11/11] spi: dw: initialize dwc-ssi-1.03a controller Sudip Mukherjee
2022-08-26 23:31 ` Serge Semin
2022-08-03 18:56 ` [PATCH 00/11] Add support for enhanced SPI for Designware SPI controllers Serge Semin
2022-08-04 9:43 ` Sudip Mukherjee
2022-08-21 20:37 ` Serge Semin
2022-08-26 18:03 ` Serge Semin
2022-08-30 8:48 ` Sudip Mukherjee
2022-09-02 23:03 ` Serge Semin
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=20220826231922.4jr73tzpt3vwpxyd@mobilestation \
--to=fancer.lancer@gmail.com \
--cc=Sergey.Semin@baikalelectronics.ru \
--cc=adnan.chowdhury@sifive.com \
--cc=ben.dooks@sifive.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=greentime.hu@sifive.com \
--cc=jeegar.lakhani@sifive.com \
--cc=jude.onyenegecha@sifive.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=sudip.mukherjee@sifive.com \
--cc=william.salmon@sifive.com \
/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;
as well as URLs for NNTP newsgroup(s).