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 03/15] spi: dw: update SPI_CTRLR0 register
Date: Mon, 9 Jan 2023 20:06:10 +0300 [thread overview]
Message-ID: <20230109170610.6ndmqi57leb5scm7@mobilestation> (raw)
In-Reply-To: <20221212180732.79167-4-sudip.mukherjee@sifive.com>
On Mon, Dec 12, 2022 at 06:07:20PM +0000, Sudip Mukherjee wrote:
> If the SPI transfer is being done in enhanced mode then SPI_CTRLR0
> register needs to be updated to mention the instruction length, address
> length, address and instruction transfer format, wait cycles. And, we
> also need to enable clock stretching.
>
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@sifive.com>
> ---
> drivers/spi/spi-dw-core.c | 14 +++++++++++++-
> drivers/spi/spi-dw.h | 11 +++++++++++
> 2 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c
> index 8c47a4d14b666..d59401f16c47a 100644
> --- a/drivers/spi/spi-dw-core.c
> +++ b/drivers/spi/spi-dw-core.c
> @@ -320,7 +320,7 @@ void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
> {
> struct dw_spi_chip_data *chip = spi_get_ctldata(spi);
> u32 cr0 = chip->cr0;
I suggest to update the dw_spi_update_config() semantic to accepting
optional eSPI configs by means of passing an additional argument
struct dw_spi_enh_cfg *ecfg. If it's null, then no need in updating
the SPI_CTRLR0 register.
> - u32 speed_hz;
> + u32 speed_hz, spi_ctrlr0;
Just reuse the cr0 variable.
> u16 clk_div;
>
> /* CTRLR0[ 4/3: 0] or CTRLR0[ 20: 16] Data Frame Size */
> @@ -365,6 +365,18 @@ void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
> dw_writel(dws, DW_SPI_RX_SAMPLE_DLY, chip->rx_sample_dly);
> dws->cur_rx_sample_dly = chip->rx_sample_dly;
> }
> +
> + if (cfg->spi_frf != DW_SPI_CTRLR0_SPI_FRF_STD_SPI) {
> + spi_ctrlr0 = DW_SPI_SPI_CTRLR0_CLK_STRETCH_EN;
> + spi_ctrlr0 |= FIELD_PREP(DW_SPI_SPI_CTRLR0_WAIT_CYCLE_MASK,
> + cfg->wait_c);
> + spi_ctrlr0 |= FIELD_PREP(DW_SPI_SPI_CTRLR0_INST_L_MASK,
> + cfg->inst_l);
> + spi_ctrlr0 |= FIELD_PREP(DW_SPI_SPI_CTRLR0_ADDR_L_MASK,
> + cfg->addr_l);
> + spi_ctrlr0 |= cfg->trans_t;
Should be also handled by the FIELD_PREP() macro.
> + dw_writel(dws, DW_SPI_SPI_CTRLR0, spi_ctrlr0);
> + }
> }
> EXPORT_SYMBOL_NS_GPL(dw_spi_update_config, SPI_DW_CORE);
>
> diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
> index 414a415deb42a..f29d89d05f34b 100644
> --- a/drivers/spi/spi-dw.h
> +++ b/drivers/spi/spi-dw.h
> @@ -63,6 +63,7 @@
> #define DW_SPI_DR 0x60
> #define DW_SPI_RX_SAMPLE_DLY 0xf0
<-+
> #define DW_SPI_CS_OVERRIDE 0xf4 |
|
> +#define DW_SPI_SPI_CTRLR0 0xf4 -+
Please replace SPI_CTRLR0 with ENH_CTRLR0 and move the macro
definition to where the arrow points to.
>
> /* Bit fields in CTRLR0 (DWC APB SSI) */
> #define DW_PSSI_CTRLR0_DFS_MASK GENMASK(3, 0)
> @@ -126,6 +127,12 @@
> #define DW_SPI_DMACR_RDMAE BIT(0)
> #define DW_SPI_DMACR_TDMAE BIT(1)
>
> +/* Bit fields in SPI_CTRLR0 */
> +#define DW_SPI_SPI_CTRLR0_CLK_STRETCH_EN BIT(30)
> +#define DW_SPI_SPI_CTRLR0_WAIT_CYCLE_MASK GENMASK(15, 11)
> +#define DW_SPI_SPI_CTRLR0_INST_L_MASK GENMASK(9, 8)
> +#define DW_SPI_SPI_CTRLR0_ADDR_L_MASK GENMASK(5, 2)
First add DW_SPI_ENH_CTRLR0_TRANS_T_MASK macro too. Second please
replace SPI_CTRLR0 with ENH_CTRLR0.
> +
> /* Mem/DMA operations helpers */
> #define DW_SPI_WAIT_RETRIES 5
> #define DW_SPI_BUF_SIZE \
> @@ -141,6 +148,10 @@ struct dw_spi_cfg {
> u32 ndf;
> u32 freq;
> u8 spi_frf;
> + u8 trans_t;
> + u8 inst_l;
> + u8 addr_l;
> + u8 wait_c;
Please move these to a separate structure:
struct dw_spi_enh_cfg {
u8 wait_l;
u8 inst_l;
u8 addr_l;
u8 trans_t;
};
Thus we'll be able to add an optional argument to the
dw_spi_update_config() method.
-Serge(y)
> };
>
> struct dw_spi;
> --
> 2.30.2
>
next prev parent reply other threads:[~2023-01-09 17:07 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 [this message]
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
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=20230109170610.6ndmqi57leb5scm7@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).