linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serge Semin <fancer.lancer@gmail.com>
To: Sudip Mukherjee <sudip.mukherjee@sifive.com>
Cc: Mark Brown <broonie@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	jude.onyenegecha@sifive.com, ben.dooks@sifive.com,
	jeegar.lakhani@sifive.com, linux-spi@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 13/15] spi: dw: detect enhanced spi mode
Date: Tue, 10 Jan 2023 15:20:53 +0300	[thread overview]
Message-ID: <20230110122053.a4x2oyb5fbjoenia@mobilestation> (raw)
In-Reply-To: <20221212180732.79167-14-sudip.mukherjee@sifive.com>

On Mon, Dec 12, 2022 at 06:07:30PM +0000, Sudip Mukherjee wrote:
> All the SSI controllers supporting enhanced spi modes might not support
> all the three dual or quad or octal modes. Detect the modes that are
> supported and finally enable the DW_SPI_CAP_EMODE capability which will
> start using all the enhanced spi functions that has been added.
> 
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@sifive.com>
> ---
>  drivers/spi/spi-dw-core.c | 68 +++++++++++++++++++++++++++++++++++++--
>  1 file changed, 66 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
> index cef56acd8d8fd..9e806d5878beb 100644
> --- a/drivers/spi/spi-dw-core.c
> +++ b/drivers/spi/spi-dw-core.c
> @@ -1143,6 +1143,69 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
>  		dw_writel(dws, DW_SPI_CS_OVERRIDE, 0xF);
>  }
>  
> +static u16 detect_enh_mode(struct dw_spi *dws)
> +{

> +	u16 mode = 0;
> +	u32 tmp_spi_ctrlr0, tmp_ctrlr0, tmpdual, tmpquad, tmpoct;
> +
> +	if (dw_spi_ver_is_ge(dws, HSSI, 103A)) {
> +		tmpdual = FIELD_PREP(DW_HSSI_CTRLR0_SPI_FRF_MASK,
> +				     DW_SPI_CTRLR0_SPI_FRF_DUAL_SPI);
> +		tmpquad = FIELD_PREP(DW_HSSI_CTRLR0_SPI_FRF_MASK,
> +				     DW_SPI_CTRLR0_SPI_FRF_QUAD_SPI);
> +		tmpoct = FIELD_PREP(DW_HSSI_CTRLR0_SPI_FRF_MASK,
> +				    DW_SPI_CTRLR0_SPI_FRF_OCT_SPI);
> +	} else if (dw_spi_ver_is_ge(dws, PSSI, 400A)) {
> +		tmpdual = FIELD_PREP(DW_PSSI_CTRLR0_SPI_FRF_MASK,
> +				     DW_SPI_CTRLR0_SPI_FRF_DUAL_SPI);
> +		tmpquad = FIELD_PREP(DW_PSSI_CTRLR0_SPI_FRF_MASK,
> +				     DW_SPI_CTRLR0_SPI_FRF_QUAD_SPI);
> +		tmpoct = FIELD_PREP(DW_PSSI_CTRLR0_SPI_FRF_MASK,
> +				    DW_SPI_CTRLR0_SPI_FRF_OCT_SPI);

Seems too complicated. What about calculating the IP-core specific
offset and mask here and use them afterwards to create the test CTRLR0
CSR data?

> +	} else {
> +		return DW_SPI_CTRLR0_SPI_FRF_STD_SPI;
> +	}
> +
> +	tmp_ctrlr0 = dw_readl(dws, DW_SPI_CTRLR0);
> +	tmp_spi_ctrlr0 = dw_readl(dws, DW_SPI_SPI_CTRLR0);
> +	dw_spi_enable_chip(dws, 0);
> +

> +	/* test clock stretching */
> +	dw_writel(dws, DW_SPI_SPI_CTRLR0, DW_SPI_SPI_CTRLR0_CLK_STRETCH_EN);
> +	if ((DW_SPI_SPI_CTRLR0_CLK_STRETCH_EN & dw_readl(dws, DW_SPI_SPI_CTRLR0)) !=
> +	    DW_SPI_SPI_CTRLR0_CLK_STRETCH_EN)
> +		/*
> +		 * If clock stretching is not enabled then do not use
> +		 * enhanced mode.
> +		 */
> +		goto disable_enh;
> +

Clock stretching is eSPI-specific feature. So it should be checked
after making sure that the eSPI is available.

> +	/* test dual mode */
> +	dw_writel(dws, DW_SPI_CTRLR0, tmpdual);
> +	if ((tmpdual & dw_readl(dws, DW_SPI_CTRLR0)) == tmpdual)
> +		mode |= SPI_TX_DUAL | SPI_RX_DUAL;
> +
> +	/* test quad mode */
> +	dw_writel(dws, DW_SPI_CTRLR0, tmpquad);
> +	if ((tmpquad & dw_readl(dws, DW_SPI_CTRLR0)) == tmpquad)
> +		mode |= SPI_TX_QUAD | SPI_RX_QUAD;
> +
> +	/* test octal mode */
> +	dw_writel(dws, DW_SPI_CTRLR0, tmpoct);
> +	if ((tmpoct & dw_readl(dws, DW_SPI_CTRLR0)) == tmpoct)
> +		mode |= SPI_TX_OCTAL | SPI_RX_OCTAL;

Are you sure that writing a non-supported mode causes having the
CTRLR0.SPI_FRF field unupdated? What eSPI-modes do your hardware
support?

> +
> +	if (mode)
> +		dws->caps |= DW_SPI_CAP_EMODE;
> +
> +disable_enh:
> +	dw_writel(dws, DW_SPI_CTRLR0, tmp_ctrlr0);
> +	dw_writel(dws, DW_SPI_SPI_CTRLR0, tmp_spi_ctrlr0);
> +	dw_spi_enable_chip(dws, 1);
> +
> +	return mode;

Move all the above to the dw_spi_hw_init() method where all the
auto-detections is implemented.

-Serge(y)

> +}
> +
>  int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
>  {
>  	struct spi_controller *master;
> @@ -1172,10 +1235,11 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
>  		goto err_free_master;
>  	}
>  
> -	dw_spi_init_mem_ops(dws);
> -
>  	master->use_gpio_descriptors = true;
>  	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
> +	master->mode_bits |= detect_enh_mode(dws);
> +	dw_spi_init_mem_ops(dws);
> +
>  	if (dws->caps & DW_SPI_CAP_DFS32)
>  		master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
>  	else
> -- 
> 2.30.2
> 

  reply	other threads:[~2023-01-10 12:23 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12 18:07 [PATCH v2 00/15] Add support for enhanced SPI for Designware SPI controllers Sudip Mukherjee
2022-12-12 18:07 ` [PATCH v2 01/15] spi: dw: Introduce spi_frf and STD_SPI Sudip Mukherjee
2023-01-09 16:43   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 02/15] spi: dw: update NDF while using enhanced spi mode Sudip Mukherjee
2023-01-09 16:52   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 03/15] spi: dw: update SPI_CTRLR0 register Sudip Mukherjee
2023-01-09 17:06   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 04/15] spi: dw: add check for support of enhanced spi Sudip Mukherjee
2023-01-09 17:34   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 05/15] spi: dw: Introduce enhanced mem_op Sudip Mukherjee
2023-01-10 11:10   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 06/15] spi: dw: Introduce dual/quad/octal spi Sudip Mukherjee
2023-01-10 11:40   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 07/15] spi: dw: send cmd and addr to start the spi transfer Sudip Mukherjee
2023-01-10 11:42   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 08/15] spi: dw: update irq setup to use multiple handler Sudip Mukherjee
2023-01-10 11:46   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 09/15] spi: dw: use irq handler for enhanced spi Sudip Mukherjee
2023-01-10 12:08   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 10/15] spi: dw: Calculate Receive FIFO Threshold Level Sudip Mukherjee
2022-12-12 18:07 ` [PATCH v2 11/15] spi: dw: adjust size of mem_op Sudip Mukherjee
2022-12-12 18:07 ` [PATCH v2 12/15] spi: dw: Add retry for enhanced spi mode Sudip Mukherjee
2023-01-10 12:10   ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 13/15] spi: dw: detect " Sudip Mukherjee
2023-01-10 12:20   ` Serge Semin [this message]
2022-12-12 18:07 ` [PATCH v2 14/15] spi: dt-bindings: snps,dw-ahb-ssi: Add generic dw-ahb-ssi version Sudip Mukherjee
2022-12-13 16:32   ` Rob Herring
2022-12-13 16:59     ` Mark Brown
2022-12-13 17:47       ` Sudip Mukherjee
2022-12-13 18:29         ` Serge Semin
2022-12-12 18:07 ` [PATCH v2 15/15] spi: dw: initialize dwc-ssi controller Sudip Mukherjee
2022-12-18 17:45 ` [PATCH v2 00/15] Add support for enhanced SPI for Designware SPI controllers Serge Semin
2023-01-04 22:20   ` Serge Semin
2023-01-09 16:25     ` Serge Semin
2023-01-19 16:26       ` Sudip Mukherjee
2023-01-19 16:37         ` 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=20230110122053.a4x2oyb5fbjoenia@mobilestation \
    --to=fancer.lancer@gmail.com \
    --cc=ben.dooks@sifive.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --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 \
    /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).