linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse
@ 2025-05-16 13:32 Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 01/22] spi: sh-msiof: Drop comma after OF match table sentinel Geert Uytterhoeven
                   ` (23 more replies)
  0 siblings, 24 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

	Hi all,

This patch series (A) improves single transfer sizes in the MSIOF
driver, using two methods:
  - By increasing the assumed FIFO sizes, impacting both PIO and DMA
    transfers,
  - By using two groups, impacting DMA transfers,
and (B) lets the recently-introduced MSIOF I2S drive reuse the SPI
driver's register definitions.  All of this is covered with a thick
sauce of fixes for (harmless) bugs, cleanups, and refactorings.

Changes compared to v1[1]:
  - Make include/linux/spi/sh_msiof.h self-contained,
  - Add Tested-by for the sound part.

Note that the driver uses the limitations as specified in the hardware
documentation.  For discovering the actual FIFO sizes, I wrote some
crude test code that can be found at [2].

This is based on spi/for-next and sound-asoc/for-next, and has been
tested on a variery of R-Car SoCs.

Thanks for your comments!

[1] https://lore.kernel.org/cover.1746180072.git.geert+renesas@glider.be
[2] https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git/log/?h=topic/msiof-fifo

Geert Uytterhoeven (22):
  spi: sh-msiof: Drop comma after OF match table sentinel
  spi: sh-msiof: Remove unneeded compatible values
  spi: sh-msiof: Fix maximum DMA transfer size
  spi: sh-msiof: Complete using dev in sh_msiof_spi_probe()
  spi: sh-msiof: Use bool for boolean flags
  spi: sh-msiof: Make words/bits unsigned in sh_msiof_spi_txrx_once()
  spi: sh-msiof: Make words/fs unsigned in FIFO helpers
  spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion
  spi: sh-msiof: SITMDR2 and SIRMDR2 bitfield conversion
  spi: sh-msiof: SITSCR/SIRSCR bitfield conversion
  spi: sh-msiof: SICTR bitfield conversion
  spi: sh-msiof: SIFCTR bitfield conversion
  spi: sh-msiof: Correct SIMDR2_GRPMASK
  spi: sh-msiof: Add core support for dual-group transfers
  spi: sh-msiof: Correct RX FIFO size for R-Car Gen2
  spi: sh-msiof: Correct RX FIFO size for R-Car Gen3
  spi: sh-msiof: Increase TX FIFO size for R-Car V4H/V4M
  spi: sh-msiof: Simplify BRG's Division Ratio
  spi: sh-msiof: Double maximum DMA transfer size using two groups
  spi: sh-msiof: Document frame start sync pulse mode
  spi: sh-msiof: Move register definitions to <linux/spi/sh_msiof.h>
  ASoC: renesas: msiof: Convert to <linux/spi/sh_msiof.h>

 drivers/spi/spi-sh-msiof.c     | 357 +++++++++++++--------------------
 include/linux/spi/sh_msiof.h   | 125 ++++++++++++
 sound/soc/renesas/rcar/msiof.c |  94 +++------
 3 files changed, 287 insertions(+), 289 deletions(-)

-- 
2.43.0

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v2 01/22] spi: sh-msiof: Drop comma after OF match table sentinel
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 02/22] spi: sh-msiof: Remove unneeded compatible values Geert Uytterhoeven
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

It does not make sense to have a comma after a sentinel, as any new
elements must be added before the sentinel.

Add a comment to clarify the purpose of the empty element.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index d9e3d83fc7e84e03..325bd5890b78884d 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -1101,7 +1101,7 @@ static const struct of_device_id sh_msiof_match[] __maybe_unused = {
 	{ .compatible = "renesas,rcar-gen3-msiof", .data = &rcar_gen3_data },
 	{ .compatible = "renesas,rcar-gen4-msiof", .data = &rcar_gen3_data },
 	{ .compatible = "renesas,sh-msiof",        .data = &sh_data }, /* Deprecated */
-	{},
+	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, sh_msiof_match);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 02/22] spi: sh-msiof: Remove unneeded compatible values
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 01/22] spi: sh-msiof: Drop comma after OF match table sentinel Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 03/22] spi: sh-msiof: Fix maximum DMA transfer size Geert Uytterhoeven
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

The Clock-Synchronized Serial Interfaces with FIFO (MSIOF) driver
matches against both SoC-specific and family-specific compatible values
to maintain backwards-compatibility with old DTBs predating the
introduction of the family-specific compatible values.

For RZ/G1, the SoC-specific compatible match entry can be removed from
the driver: their DT always had the family-specific compatible values,
and thus there was never a need to add the SoC-specific compatible
values to the driver.

For R-Car Gen2 and M3-W, the SoC-specific compatible match entries can
be removed, too, as there are a few points in time where DT
backwards-compatibility was broken for other reasons:
  - Legacy DT clock support is no longer supported since commit
    58256143cff7c2e0 ("clk: renesas: Remove R-Car Gen2 legacy DT clock
    support") in v5.5, and the addition of "renesas,rcar-gen2-msiof" to
    DTS in v4.11 predates the completion of the clock conversion in
    v4.15,
  - Legacy DT LVDS support is no longer supported since commit
    841281fe52a769fe ("drm: rcar-du: Drop LVDS device tree backward
    compatibility") in v5.18, and the addition of
    "renesas,rcar-gen3-msiof" in commit 8b51f97138ca22b6 ("arm64: dts:
    r8a7796: Use R-Car Gen 3 fallback binding for msiof nodes") in v4.11
    predates the LVDS conversion in commit 58e8ed2ee9abe718 ("arm64:
    dts: renesas: Convert to new LVDS DT bindings") in v4.20.

For R-Car H3, the SoC-specific compatible match entry cannot be removed,
as its purpose is to handle an SoC-specific quirk.

Suggested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
This is a resend of a patch that never received any comments.

v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 325bd5890b78884d..15e42af35f7e4230 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -1088,16 +1088,8 @@ static const struct sh_msiof_chipdata rcar_r8a7795_data = {
 
 static const struct of_device_id sh_msiof_match[] __maybe_unused = {
 	{ .compatible = "renesas,sh-mobile-msiof", .data = &sh_data },
-	{ .compatible = "renesas,msiof-r8a7743",   .data = &rcar_gen2_data },
-	{ .compatible = "renesas,msiof-r8a7745",   .data = &rcar_gen2_data },
-	{ .compatible = "renesas,msiof-r8a7790",   .data = &rcar_gen2_data },
-	{ .compatible = "renesas,msiof-r8a7791",   .data = &rcar_gen2_data },
-	{ .compatible = "renesas,msiof-r8a7792",   .data = &rcar_gen2_data },
-	{ .compatible = "renesas,msiof-r8a7793",   .data = &rcar_gen2_data },
-	{ .compatible = "renesas,msiof-r8a7794",   .data = &rcar_gen2_data },
 	{ .compatible = "renesas,rcar-gen2-msiof", .data = &rcar_gen2_data },
 	{ .compatible = "renesas,msiof-r8a7795",   .data = &rcar_r8a7795_data },
-	{ .compatible = "renesas,msiof-r8a7796",   .data = &rcar_gen3_data },
 	{ .compatible = "renesas,rcar-gen3-msiof", .data = &rcar_gen3_data },
 	{ .compatible = "renesas,rcar-gen4-msiof", .data = &rcar_gen3_data },
 	{ .compatible = "renesas,sh-msiof",        .data = &sh_data }, /* Deprecated */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 03/22] spi: sh-msiof: Fix maximum DMA transfer size
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 01/22] spi: sh-msiof: Drop comma after OF match table sentinel Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 02/22] spi: sh-msiof: Remove unneeded compatible values Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 04/22] spi: sh-msiof: Complete using dev in sh_msiof_spi_probe() Geert Uytterhoeven
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

The maximum amount of data to transfer in a single DMA request is
calculated from the FIFO sizes (which is technically not 100% correct,
but a simplification, as it is limited by the maximum word count values
in the Transmit and Control Data Registers).  However, in case there is
both data to transmit and to receive, the transmit limit is overwritten
by the receive limit.

Fix this by using the minimum applicable FIFO size instead.  Move the
calculation outside the loop, so it is not repeated for each individual
DMA transfer.

As currently tx_fifo_size is always equal to rx_fifo_size, this bug had
no real impact.

Fixes: fe78d0b7691c0274 ("spi: sh-msiof: Fix FIFO size to 64 word from 256 word")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 15e42af35f7e4230..cf93c2ca821f84fa 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -919,6 +919,7 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
 	void *rx_buf = t->rx_buf;
 	unsigned int len = t->len;
 	unsigned int bits = t->bits_per_word;
+	unsigned int max_wdlen = 256;
 	unsigned int bytes_per_word;
 	unsigned int words;
 	int n;
@@ -932,17 +933,17 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
 	if (!spi_controller_is_target(p->ctlr))
 		sh_msiof_spi_set_clk_regs(p, t);
 
+	if (tx_buf)
+		max_wdlen = min(max_wdlen, p->tx_fifo_size);
+	if (rx_buf)
+		max_wdlen = min(max_wdlen, p->rx_fifo_size);
+
 	while (ctlr->dma_tx && len > 15) {
 		/*
 		 *  DMA supports 32-bit words only, hence pack 8-bit and 16-bit
 		 *  words, with byte resp. word swapping.
 		 */
-		unsigned int l = 0;
-
-		if (tx_buf)
-			l = min(round_down(len, 4), p->tx_fifo_size * 4);
-		if (rx_buf)
-			l = min(round_down(len, 4), p->rx_fifo_size * 4);
+		unsigned int l = min(round_down(len, 4), max_wdlen * 4);
 
 		if (bits <= 8) {
 			copy32 = copy_bswap32;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 04/22] spi: sh-msiof: Complete using dev in sh_msiof_spi_probe()
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 03/22] spi: sh-msiof: Fix maximum DMA transfer size Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-19  1:39   ` Kuninori Morimoto
  2025-05-16 13:32 ` [PATCH v2 05/22] spi: sh-msiof: Use bool for boolean flags Geert Uytterhoeven
                   ` (19 subsequent siblings)
  23 siblings, 1 reply; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Commit c4887bd4b35b225f ("spi: sh-msiof: use dev in
sh_msiof_spi_probe()") forgot to convert one instance.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index cf93c2ca821f84fa..367622985fea2a04 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -1332,7 +1332,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
 		goto err1;
 	}
 
-	ret = devm_request_irq(dev, i, sh_msiof_spi_irq, 0, dev_name(&pdev->dev), p);
+	ret = devm_request_irq(dev, i, sh_msiof_spi_irq, 0, dev_name(dev), p);
 	if (ret) {
 		dev_err(dev, "unable to request irq\n");
 		goto err1;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 05/22] spi: sh-msiof: Use bool for boolean flags
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (3 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 04/22] spi: sh-msiof: Complete using dev in sh_msiof_spi_probe() Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 06/22] spi: sh-msiof: Make words/bits unsigned in sh_msiof_spi_txrx_once() Geert Uytterhoeven
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Use bools instead of integers for boolean flags, which allows us to
remove the "!!" idiom from several expressions.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 367622985fea2a04..11ef5c0a498d7c1f 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -348,11 +348,11 @@ static u32 sh_msiof_spi_get_dtdl_and_syncdl(struct sh_msiof_spi_priv *p)
 }
 
 static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,
-				      u32 cpol, u32 cpha,
-				      u32 tx_hi_z, u32 lsb_first, u32 cs_high)
+				      bool cpol, bool cpha, bool tx_hi_z,
+				      bool lsb_first, bool cs_high)
 {
+	bool edge;
 	u32 tmp;
-	int edge;
 
 	/*
 	 * CPOL CPHA     TSCKIZ RSCKIZ TEDG REDG
@@ -587,7 +587,8 @@ static int sh_msiof_prepare_message(struct spi_controller *ctlr,
 {
 	struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
 	const struct spi_device *spi = msg->spi;
-	u32 ss, cs_high;
+	bool cs_high;
+	u32 ss;
 
 	/* Configure pins before asserting CS */
 	if (spi_get_csgpiod(spi, 0)) {
@@ -595,12 +596,11 @@ static int sh_msiof_prepare_message(struct spi_controller *ctlr,
 		cs_high = p->native_cs_high;
 	} else {
 		ss = spi_get_chipselect(spi, 0);
-		cs_high = !!(spi->mode & SPI_CS_HIGH);
+		cs_high = spi->mode & SPI_CS_HIGH;
 	}
-	sh_msiof_spi_set_pin_regs(p, ss, !!(spi->mode & SPI_CPOL),
-				  !!(spi->mode & SPI_CPHA),
-				  !!(spi->mode & SPI_3WIRE),
-				  !!(spi->mode & SPI_LSB_FIRST), cs_high);
+	sh_msiof_spi_set_pin_regs(p, ss, spi->mode & SPI_CPOL,
+				  spi->mode & SPI_CPHA, spi->mode & SPI_3WIRE,
+				  spi->mode & SPI_LSB_FIRST, cs_high);
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 06/22] spi: sh-msiof: Make words/bits unsigned in sh_msiof_spi_txrx_once()
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (4 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 05/22] spi: sh-msiof: Use bool for boolean flags Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 07/22] spi: sh-msiof: Make words/fs unsigned in FIFO helpers Geert Uytterhoeven
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Make the words and bits parameters of sh_msiof_spi_txrx_once() unsigned,
as that matches what is passed by the caller.

This allows us to replace min_t() by the safer min().

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 11ef5c0a498d7c1f..fdb13dbc175249c4 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -677,16 +677,16 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p,
 				  void (*rx_fifo)(struct sh_msiof_spi_priv *,
 						  void *, int, int),
 				  const void *tx_buf, void *rx_buf,
-				  int words, int bits)
+				  unsigned int words, unsigned int bits)
 {
 	int fifo_shift;
 	int ret;
 
 	/* limit maximum word transfer to rx/tx fifo size */
 	if (tx_buf)
-		words = min_t(int, words, p->tx_fifo_size);
+		words = min(words, p->tx_fifo_size);
 	if (rx_buf)
-		words = min_t(int, words, p->rx_fifo_size);
+		words = min(words, p->rx_fifo_size);
 
 	/* the fifo contents need shifting */
 	fifo_shift = 32 - bits;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 07/22] spi: sh-msiof: Make words/fs unsigned in FIFO helpers
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (5 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 06/22] spi: sh-msiof: Make words/bits unsigned in sh_msiof_spi_txrx_once() Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 08/22] spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion Geert Uytterhoeven
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Make the words and fs parameters of the various FIFO filler and
emptier functions unsigned, as they can never be negative.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 84 +++++++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 33 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index fdb13dbc175249c4..7c15de08f4d8f131 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -412,140 +412,154 @@ static void sh_msiof_reset_str(struct sh_msiof_spi_priv *p)
 }
 
 static void sh_msiof_spi_write_fifo_8(struct sh_msiof_spi_priv *p,
-				      const void *tx_buf, int words, int fs)
+				      const void *tx_buf, unsigned int words,
+				      unsigned int fs)
 {
 	const u8 *buf_8 = tx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		sh_msiof_write(p, SITFDR, buf_8[k] << fs);
 }
 
 static void sh_msiof_spi_write_fifo_16(struct sh_msiof_spi_priv *p,
-				       const void *tx_buf, int words, int fs)
+				       const void *tx_buf, unsigned int words,
+				       unsigned int fs)
 {
 	const u16 *buf_16 = tx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		sh_msiof_write(p, SITFDR, buf_16[k] << fs);
 }
 
 static void sh_msiof_spi_write_fifo_16u(struct sh_msiof_spi_priv *p,
-					const void *tx_buf, int words, int fs)
+					const void *tx_buf, unsigned int words,
+					unsigned int fs)
 {
 	const u16 *buf_16 = tx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		sh_msiof_write(p, SITFDR, get_unaligned(&buf_16[k]) << fs);
 }
 
 static void sh_msiof_spi_write_fifo_32(struct sh_msiof_spi_priv *p,
-				       const void *tx_buf, int words, int fs)
+				       const void *tx_buf, unsigned int words,
+				       unsigned int fs)
 {
 	const u32 *buf_32 = tx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		sh_msiof_write(p, SITFDR, buf_32[k] << fs);
 }
 
 static void sh_msiof_spi_write_fifo_32u(struct sh_msiof_spi_priv *p,
-					const void *tx_buf, int words, int fs)
+					const void *tx_buf, unsigned int words,
+					unsigned int fs)
 {
 	const u32 *buf_32 = tx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		sh_msiof_write(p, SITFDR, get_unaligned(&buf_32[k]) << fs);
 }
 
 static void sh_msiof_spi_write_fifo_s32(struct sh_msiof_spi_priv *p,
-					const void *tx_buf, int words, int fs)
+					const void *tx_buf, unsigned int words,
+					unsigned int fs)
 {
 	const u32 *buf_32 = tx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		sh_msiof_write(p, SITFDR, swab32(buf_32[k] << fs));
 }
 
 static void sh_msiof_spi_write_fifo_s32u(struct sh_msiof_spi_priv *p,
-					 const void *tx_buf, int words, int fs)
+					 const void *tx_buf,
+					 unsigned int words, unsigned int fs)
 {
 	const u32 *buf_32 = tx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		sh_msiof_write(p, SITFDR, swab32(get_unaligned(&buf_32[k]) << fs));
 }
 
 static void sh_msiof_spi_read_fifo_8(struct sh_msiof_spi_priv *p,
-				     void *rx_buf, int words, int fs)
+				     void *rx_buf, unsigned int words,
+				     unsigned int fs)
 {
 	u8 *buf_8 = rx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		buf_8[k] = sh_msiof_read(p, SIRFDR) >> fs;
 }
 
 static void sh_msiof_spi_read_fifo_16(struct sh_msiof_spi_priv *p,
-				      void *rx_buf, int words, int fs)
+				      void *rx_buf, unsigned int words,
+				      unsigned int fs)
 {
 	u16 *buf_16 = rx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		buf_16[k] = sh_msiof_read(p, SIRFDR) >> fs;
 }
 
 static void sh_msiof_spi_read_fifo_16u(struct sh_msiof_spi_priv *p,
-				       void *rx_buf, int words, int fs)
+				       void *rx_buf, unsigned int words,
+				       unsigned int fs)
 {
 	u16 *buf_16 = rx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		put_unaligned(sh_msiof_read(p, SIRFDR) >> fs, &buf_16[k]);
 }
 
 static void sh_msiof_spi_read_fifo_32(struct sh_msiof_spi_priv *p,
-				      void *rx_buf, int words, int fs)
+				      void *rx_buf, unsigned int words,
+				      unsigned int fs)
 {
 	u32 *buf_32 = rx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		buf_32[k] = sh_msiof_read(p, SIRFDR) >> fs;
 }
 
 static void sh_msiof_spi_read_fifo_32u(struct sh_msiof_spi_priv *p,
-				       void *rx_buf, int words, int fs)
+				       void *rx_buf, unsigned int words,
+				       unsigned int fs)
 {
 	u32 *buf_32 = rx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		put_unaligned(sh_msiof_read(p, SIRFDR) >> fs, &buf_32[k]);
 }
 
 static void sh_msiof_spi_read_fifo_s32(struct sh_msiof_spi_priv *p,
-				       void *rx_buf, int words, int fs)
+				       void *rx_buf, unsigned int words,
+				       unsigned int fs)
 {
 	u32 *buf_32 = rx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		buf_32[k] = swab32(sh_msiof_read(p, SIRFDR) >> fs);
 }
 
 static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p,
-				       void *rx_buf, int words, int fs)
+				       void *rx_buf, unsigned int words,
+				       unsigned int fs)
 {
 	u32 *buf_32 = rx_buf;
-	int k;
+	unsigned int k;
 
 	for (k = 0; k < words; k++)
 		put_unaligned(swab32(sh_msiof_read(p, SIRFDR) >> fs), &buf_32[k]);
@@ -673,13 +687,15 @@ static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p,
 
 static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p,
 				  void (*tx_fifo)(struct sh_msiof_spi_priv *,
-						  const void *, int, int),
+						  const void *, unsigned int,
+						  unsigned int),
 				  void (*rx_fifo)(struct sh_msiof_spi_priv *,
-						  void *, int, int),
+						  void *, unsigned int,
+						  unsigned int),
 				  const void *tx_buf, void *rx_buf,
 				  unsigned int words, unsigned int bits)
 {
-	int fifo_shift;
+	unsigned int fifo_shift;
 	int ret;
 
 	/* limit maximum word transfer to rx/tx fifo size */
@@ -913,8 +929,10 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
 {
 	struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
 	void (*copy32)(u32 *, const u32 *, unsigned int);
-	void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int);
-	void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int);
+	void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, unsigned int,
+			unsigned int);
+	void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, unsigned int,
+			unsigned int);
 	const void *tx_buf = t->tx_buf;
 	void *rx_buf = t->rx_buf;
 	unsigned int len = t->len;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 08/22] spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (6 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 07/22] spi: sh-msiof: Make words/fs unsigned in FIFO helpers Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 09/22] spi: sh-msiof: SITMDR2 and SIRMDR2 " Geert Uytterhoeven
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Convert MSIOF Transmit and Receive Mode Register 1 field accesses to use
the FIELD_PREP() bitfield access macro.

This gets rid of explicit shifts.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 45 ++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 7c15de08f4d8f131..fb83b049690e0207 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -7,6 +7,7 @@
  * Copyright (C) 2014-2017 Glider bvba
  */
 
+#include <linux/bitfield.h>
 #include <linux/bitmap.h>
 #include <linux/clk.h>
 #include <linux/completion.h>
@@ -84,20 +85,19 @@ struct sh_msiof_spi_priv {
 
 /* SITMDR1 and SIRMDR1 */
 #define SIMDR1_TRMD		BIT(31)		/* Transfer Mode (1 = Master mode) */
-#define SIMDR1_SYNCMD_MASK	GENMASK(29, 28)	/* SYNC Mode */
-#define SIMDR1_SYNCMD_SPI	(2 << 28)	/*   Level mode/SPI */
-#define SIMDR1_SYNCMD_LR	(3 << 28)	/*   L/R mode */
-#define SIMDR1_SYNCAC_SHIFT	25		/* Sync Polarity (1 = Active-low) */
-#define SIMDR1_BITLSB_SHIFT	24		/* MSB/LSB First (1 = LSB first) */
-#define SIMDR1_DTDL_SHIFT	20		/* Data Pin Bit Delay for MSIOF_SYNC */
-#define SIMDR1_SYNCDL_SHIFT	16		/* Frame Sync Signal Timing Delay */
-#define SIMDR1_FLD_MASK		GENMASK(3, 2)	/* Frame Sync Signal Interval (0-3) */
-#define SIMDR1_FLD_SHIFT	2
+#define SIMDR1_SYNCMD		GENMASK(29, 28)	/* SYNC Mode */
+#define SIMDR1_SYNCMD_SPI	2U		/*   Level mode/SPI */
+#define SIMDR1_SYNCMD_LR	3U		/*   L/R mode */
+#define SIMDR1_SYNCAC		BIT(25)		/* Sync Polarity (1 = Active-low) */
+#define SIMDR1_BITLSB		BIT(24)		/* MSB/LSB First (1 = LSB first) */
+#define SIMDR1_DTDL		GENMASK(22, 20)	/* Data Pin Bit Delay for MSIOF_SYNC */
+#define SIMDR1_SYNCDL		GENMASK(18, 16)	/* Frame Sync Signal Timing Delay */
+#define SIMDR1_FLD		GENMASK(3, 2)	/* Frame Sync Signal Interval (0-3) */
 #define SIMDR1_XXSTP		BIT(0)		/* Transmission/Reception Stop on FIFO */
 /* SITMDR1 */
 #define SITMDR1_PCON		BIT(30)		/* Transfer Signal Connection */
-#define SITMDR1_SYNCCH_MASK	GENMASK(27, 26)	/* Sync Signal Channel Select */
-#define SITMDR1_SYNCCH_SHIFT	26		/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
+#define SITMDR1_SYNCCH		GENMASK(27, 26)	/* Sync Signal Channel Select */
+						/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
 
 /* SITMDR2 and SIRMDR2 */
 #define SIMDR2_BITLEN1(i)	(((i) - 1) << 24) /* Data Size (8-32 bits) */
@@ -341,8 +341,9 @@ static u32 sh_msiof_spi_get_dtdl_and_syncdl(struct sh_msiof_spi_priv *p)
 		return 0;
 	}
 
-	val = sh_msiof_get_delay_bit(p->info->dtdl) << SIMDR1_DTDL_SHIFT;
-	val |= sh_msiof_get_delay_bit(p->info->syncdl) << SIMDR1_SYNCDL_SHIFT;
+	val = FIELD_PREP(SIMDR1_DTDL, sh_msiof_get_delay_bit(p->info->dtdl)) |
+	      FIELD_PREP(SIMDR1_SYNCDL,
+			 sh_msiof_get_delay_bit(p->info->syncdl));
 
 	return val;
 }
@@ -361,16 +362,18 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,
 	 *    1    0         11     11    0    0
 	 *    1    1         11     11    1    1
 	 */
-	tmp = SIMDR1_SYNCMD_SPI | 1 << SIMDR1_FLD_SHIFT | SIMDR1_XXSTP;
-	tmp |= !cs_high << SIMDR1_SYNCAC_SHIFT;
-	tmp |= lsb_first << SIMDR1_BITLSB_SHIFT;
+	tmp = FIELD_PREP(SIMDR1_SYNCMD, SIMDR1_SYNCMD_SPI) |
+	      FIELD_PREP(SIMDR1_FLD, 1) | SIMDR1_XXSTP |
+	      FIELD_PREP(SIMDR1_SYNCAC, !cs_high) |
+	      FIELD_PREP(SIMDR1_BITLSB, lsb_first);
 	tmp |= sh_msiof_spi_get_dtdl_and_syncdl(p);
 	if (spi_controller_is_target(p->ctlr)) {
 		sh_msiof_write(p, SITMDR1, tmp | SITMDR1_PCON);
 	} else {
 		sh_msiof_write(p, SITMDR1,
 			       tmp | SIMDR1_TRMD | SITMDR1_PCON |
-			       (ss < MAX_SS ? ss : 0) << SITMDR1_SYNCCH_SHIFT);
+			       FIELD_PREP(SITMDR1_SYNCCH,
+					  ss < MAX_SS ? ss : 0));
 	}
 	if (p->ctlr->flags & SPI_CONTROLLER_MUST_TX) {
 		/* These bits are reserved if RX needs TX */
@@ -579,12 +582,12 @@ static int sh_msiof_spi_setup(struct spi_device *spi)
 		return 0;
 
 	/* Configure native chip select mode/polarity early */
-	clr = SIMDR1_SYNCMD_MASK;
-	set = SIMDR1_SYNCMD_SPI;
+	clr = SIMDR1_SYNCMD;
+	set = FIELD_PREP(SIMDR1_SYNCMD, SIMDR1_SYNCMD_SPI);
 	if (spi->mode & SPI_CS_HIGH)
-		clr |= BIT(SIMDR1_SYNCAC_SHIFT);
+		clr |= SIMDR1_SYNCAC;
 	else
-		set |= BIT(SIMDR1_SYNCAC_SHIFT);
+		set |= SIMDR1_SYNCAC;
 	pm_runtime_get_sync(&p->pdev->dev);
 	tmp = sh_msiof_read(p, SITMDR1) & ~clr;
 	sh_msiof_write(p, SITMDR1, tmp | set | SIMDR1_TRMD | SITMDR1_PCON);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 09/22] spi: sh-msiof: SITMDR2 and SIRMDR2 bitfield conversion
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (7 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 08/22] spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 10/22] spi: sh-msiof: SITSCR/SIRSCR " Geert Uytterhoeven
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Convert MSIOF Transmit and Receive Mode Register 2 field accesses to use
the FIELD_PREP() bitfield access macro.

This gets rid of explicit shifts and custom field preparation macros.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index fb83b049690e0207..51a9e89364756af0 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -100,8 +100,8 @@ struct sh_msiof_spi_priv {
 						/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
 
 /* SITMDR2 and SIRMDR2 */
-#define SIMDR2_BITLEN1(i)	(((i) - 1) << 24) /* Data Size (8-32 bits) */
-#define SIMDR2_WDLEN1(i)	(((i) - 1) << 16) /* Word Count (1-64/256 (SH, A1))) */
+#define SIMDR2_BITLEN1		GENMASK(28, 24)	/* Data Size (8-32 bits) */
+#define SIMDR2_WDLEN1		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
 #define SIMDR2_GRPMASK1		BIT(0)		/* Group Output Mask 1 (SH, A1) */
 
 /* SITSCR and SIRSCR */
@@ -397,7 +397,8 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
 				       const void *tx_buf, void *rx_buf,
 				       u32 bits, u32 words)
 {
-	u32 dr2 = SIMDR2_BITLEN1(bits) | SIMDR2_WDLEN1(words);
+	u32 dr2 = FIELD_PREP(SIMDR2_BITLEN1, bits - 1) |
+		  FIELD_PREP(SIMDR2_WDLEN1, words - 1);
 
 	if (tx_buf || (p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
 		sh_msiof_write(p, SITMDR2, dr2);
@@ -931,6 +932,7 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
 				 struct spi_transfer *t)
 {
 	struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
+	unsigned int max_wdlen = FIELD_MAX(SIMDR2_WDLEN1) + 1;
 	void (*copy32)(u32 *, const u32 *, unsigned int);
 	void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, unsigned int,
 			unsigned int);
@@ -940,7 +942,6 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
 	void *rx_buf = t->rx_buf;
 	unsigned int len = t->len;
 	unsigned int bits = t->bits_per_word;
-	unsigned int max_wdlen = 256;
 	unsigned int bytes_per_word;
 	unsigned int words;
 	int n;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 10/22] spi: sh-msiof: SITSCR/SIRSCR bitfield conversion
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (8 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 09/22] spi: sh-msiof: SITMDR2 and SIRMDR2 " Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 11/22] spi: sh-msiof: SICTR " Geert Uytterhoeven
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Convert MSIOF Transmit and Receive Clock Select Register field accesses
to use the FIELD_PREP() bitfield access macro.

This gets rid of explicit shifts and custom field preparation macros.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 51a9e89364756af0..9bddf85dd9c7f2a1 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -105,15 +105,14 @@ struct sh_msiof_spi_priv {
 #define SIMDR2_GRPMASK1		BIT(0)		/* Group Output Mask 1 (SH, A1) */
 
 /* SITSCR and SIRSCR */
-#define SISCR_BRPS_MASK		GENMASK(12, 8)	/* Prescaler Setting (1-32) */
-#define SISCR_BRPS(i)		(((i) - 1) << 8)
-#define SISCR_BRDV_MASK		GENMASK(2, 0)	/* Baud Rate Generator's Division Ratio */
-#define SISCR_BRDV_DIV_2	0
-#define SISCR_BRDV_DIV_4	1
-#define SISCR_BRDV_DIV_8	2
-#define SISCR_BRDV_DIV_16	3
-#define SISCR_BRDV_DIV_32	4
-#define SISCR_BRDV_DIV_1	7
+#define SISCR_BRPS		GENMASK(12, 8)	/* Prescaler Setting (1-32) */
+#define SISCR_BRDV		GENMASK(2, 0)	/* Baud Rate Generator's Division Ratio */
+#define SISCR_BRDV_DIV_2	0U
+#define SISCR_BRDV_DIV_4	1U
+#define SISCR_BRDV_DIV_8	2U
+#define SISCR_BRDV_DIV_16	3U
+#define SISCR_BRDV_DIV_32	4U
+#define SISCR_BRDV_DIV_1	7U
 
 /* SICTR */
 #define SICTR_TSCKIZ_MASK	GENMASK(31, 30)	/* Transmit Clock I/O Polarity Select */
@@ -299,7 +298,8 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
 
 	t->effective_speed_hz = parent_rate / (brps << div_pow);
 
-	scr = sh_msiof_spi_div_array[div_pow] | SISCR_BRPS(brps);
+	scr = FIELD_PREP(SISCR_BRDV, sh_msiof_spi_div_array[div_pow]) |
+	      FIELD_PREP(SISCR_BRPS, brps - 1);
 	sh_msiof_write(p, SITSCR, scr);
 	if (!(p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
 		sh_msiof_write(p, SIRSCR, scr);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 11/22] spi: sh-msiof: SICTR bitfield conversion
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (9 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 10/22] spi: sh-msiof: SITSCR/SIRSCR " Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 12/22] spi: sh-msiof: SIFCTR " Geert Uytterhoeven
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Convert MSIOF Control Register field accesses to use the FIELD_PREP()
bitfield access macro.

This gets rid of explicit shifts.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 9bddf85dd9c7f2a1..4f582ecc524fe5fa 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -115,18 +115,18 @@ struct sh_msiof_spi_priv {
 #define SISCR_BRDV_DIV_1	7U
 
 /* SICTR */
-#define SICTR_TSCKIZ_MASK	GENMASK(31, 30)	/* Transmit Clock I/O Polarity Select */
+#define SICTR_TSCKIZ		GENMASK(31, 30)	/* Transmit Clock I/O Polarity Select */
 #define SICTR_TSCKIZ_SCK	BIT(31)		/*   Disable SCK when TX disabled */
-#define SICTR_TSCKIZ_POL_SHIFT	30		/*   Transmit Clock Polarity */
-#define SICTR_RSCKIZ_MASK	GENMASK(29, 28) /* Receive Clock Polarity Select */
+#define SICTR_TSCKIZ_POL	BIT(30)		/*   Transmit Clock Polarity */
+#define SICTR_RSCKIZ		GENMASK(29, 28) /* Receive Clock Polarity Select */
 #define SICTR_RSCKIZ_SCK	BIT(29)		/*   Must match CTR_TSCKIZ_SCK */
-#define SICTR_RSCKIZ_POL_SHIFT	28		/*   Receive Clock Polarity */
-#define SICTR_TEDG_SHIFT	27		/* Transmit Timing (1 = falling edge) */
-#define SICTR_REDG_SHIFT	26		/* Receive Timing (1 = falling edge) */
-#define SICTR_TXDIZ_MASK	GENMASK(23, 22)	/* Pin Output When TX is Disabled */
-#define SICTR_TXDIZ_LOW		(0 << 22)	/*   0 */
-#define SICTR_TXDIZ_HIGH	(1 << 22)	/*   1 */
-#define SICTR_TXDIZ_HIZ		(2 << 22)	/*   High-impedance */
+#define SICTR_RSCKIZ_POL	BIT(28)		/*   Receive Clock Polarity */
+#define SICTR_TEDG		BIT(27)		/* Transmit Timing (1 = falling edge) */
+#define SICTR_REDG		BIT(26)		/* Receive Timing (1 = falling edge) */
+#define SICTR_TXDIZ		GENMASK(23, 22)	/* Pin Output When TX is Disabled */
+#define SICTR_TXDIZ_LOW		0U		/*   0 */
+#define SICTR_TXDIZ_HIGH	1U		/*   1 */
+#define SICTR_TXDIZ_HIZ		2U		/*   High-impedance */
 #define SICTR_TSCKE		BIT(15)		/* Transmit Serial Clock Output Enable */
 #define SICTR_TFSE		BIT(14)		/* Transmit Frame Sync Signal Output Enable */
 #define SICTR_TXE		BIT(9)		/* Transmit Enable */
@@ -382,14 +382,15 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,
 	sh_msiof_write(p, SIRMDR1, tmp);
 
 	tmp = 0;
-	tmp |= SICTR_TSCKIZ_SCK | cpol << SICTR_TSCKIZ_POL_SHIFT;
-	tmp |= SICTR_RSCKIZ_SCK | cpol << SICTR_RSCKIZ_POL_SHIFT;
+	tmp |= SICTR_TSCKIZ_SCK | FIELD_PREP(SICTR_TSCKIZ_POL, cpol);
+	tmp |= SICTR_RSCKIZ_SCK | FIELD_PREP(SICTR_RSCKIZ_POL, cpol);
 
 	edge = cpol ^ !cpha;
 
-	tmp |= edge << SICTR_TEDG_SHIFT;
-	tmp |= edge << SICTR_REDG_SHIFT;
-	tmp |= tx_hi_z ? SICTR_TXDIZ_HIZ : SICTR_TXDIZ_LOW;
+	tmp |= FIELD_PREP(SICTR_TEDG, edge);
+	tmp |= FIELD_PREP(SICTR_REDG, edge);
+	tmp |= FIELD_PREP(SICTR_TXDIZ,
+			  tx_hi_z ? SICTR_TXDIZ_HIZ : SICTR_TXDIZ_LOW);
 	sh_msiof_write(p, SICTR, tmp);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 12/22] spi: sh-msiof: SIFCTR bitfield conversion
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (10 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 11/22] spi: sh-msiof: SICTR " Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 13/22] spi: sh-msiof: Correct SIMDR2_GRPMASK Geert Uytterhoeven
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Convert MSIOF FIFO Control Register field accesses to use the
FIELD_PREP() bitfield access macro.

This gets rid of explicit shifts and custom field preparation macros.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 48 ++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 4f582ecc524fe5fa..812e64ea5f79ce5e 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -135,30 +135,26 @@ struct sh_msiof_spi_priv {
 #define SICTR_RXRST		BIT(0)		/* Receive Reset */
 
 /* SIFCTR */
-#define SIFCTR_TFWM_MASK	GENMASK(31, 29)	/* Transmit FIFO Watermark */
-#define SIFCTR_TFWM_64		(0UL << 29)	/*  Transfer Request when 64 empty stages */
-#define SIFCTR_TFWM_32		(1UL << 29)	/*  Transfer Request when 32 empty stages */
-#define SIFCTR_TFWM_24		(2UL << 29)	/*  Transfer Request when 24 empty stages */
-#define SIFCTR_TFWM_16		(3UL << 29)	/*  Transfer Request when 16 empty stages */
-#define SIFCTR_TFWM_12		(4UL << 29)	/*  Transfer Request when 12 empty stages */
-#define SIFCTR_TFWM_8		(5UL << 29)	/*  Transfer Request when 8 empty stages */
-#define SIFCTR_TFWM_4		(6UL << 29)	/*  Transfer Request when 4 empty stages */
-#define SIFCTR_TFWM_1		(7UL << 29)	/*  Transfer Request when 1 empty stage */
-#define SIFCTR_TFUA_MASK	GENMASK(26, 20) /* Transmit FIFO Usable Area */
-#define SIFCTR_TFUA_SHIFT	20
-#define SIFCTR_TFUA(i)		((i) << SIFCTR_TFUA_SHIFT)
-#define SIFCTR_RFWM_MASK	GENMASK(15, 13)	/* Receive FIFO Watermark */
-#define SIFCTR_RFWM_1		(0 << 13)	/*  Transfer Request when 1 valid stages */
-#define SIFCTR_RFWM_4		(1 << 13)	/*  Transfer Request when 4 valid stages */
-#define SIFCTR_RFWM_8		(2 << 13)	/*  Transfer Request when 8 valid stages */
-#define SIFCTR_RFWM_16		(3 << 13)	/*  Transfer Request when 16 valid stages */
-#define SIFCTR_RFWM_32		(4 << 13)	/*  Transfer Request when 32 valid stages */
-#define SIFCTR_RFWM_64		(5 << 13)	/*  Transfer Request when 64 valid stages */
-#define SIFCTR_RFWM_128		(6 << 13)	/*  Transfer Request when 128 valid stages */
-#define SIFCTR_RFWM_256		(7 << 13)	/*  Transfer Request when 256 valid stages */
-#define SIFCTR_RFUA_MASK	GENMASK(12, 4)	/* Receive FIFO Usable Area (0x40 = full) */
-#define SIFCTR_RFUA_SHIFT	4
-#define SIFCTR_RFUA(i)		((i) << SIFCTR_RFUA_SHIFT)
+#define SIFCTR_TFWM		GENMASK(31, 29)	/* Transmit FIFO Watermark */
+#define SIFCTR_TFWM_64		0U		/*  Transfer Request when 64 empty stages */
+#define SIFCTR_TFWM_32		1U		/*  Transfer Request when 32 empty stages */
+#define SIFCTR_TFWM_24		2U		/*  Transfer Request when 24 empty stages */
+#define SIFCTR_TFWM_16		3U		/*  Transfer Request when 16 empty stages */
+#define SIFCTR_TFWM_12		4U		/*  Transfer Request when 12 empty stages */
+#define SIFCTR_TFWM_8		5U		/*  Transfer Request when 8 empty stages */
+#define SIFCTR_TFWM_4		6U		/*  Transfer Request when 4 empty stages */
+#define SIFCTR_TFWM_1		7U		/*  Transfer Request when 1 empty stage */
+#define SIFCTR_TFUA		GENMASK(26, 20) /* Transmit FIFO Usable Area */
+#define SIFCTR_RFWM		GENMASK(15, 13)	/* Receive FIFO Watermark */
+#define SIFCTR_RFWM_1		0U		/*  Transfer Request when 1 valid stages */
+#define SIFCTR_RFWM_4		1U		/*  Transfer Request when 4 valid stages */
+#define SIFCTR_RFWM_8		2U		/*  Transfer Request when 8 valid stages */
+#define SIFCTR_RFWM_16		3U		/*  Transfer Request when 16 valid stages */
+#define SIFCTR_RFWM_32		4U		/*  Transfer Request when 32 valid stages */
+#define SIFCTR_RFWM_64		5U		/*  Transfer Request when 64 valid stages */
+#define SIFCTR_RFWM_128		6U		/*  Transfer Request when 128 valid stages */
+#define SIFCTR_RFWM_256		7U		/*  Transfer Request when 256 valid stages */
+#define SIFCTR_RFUA		GENMASK(12, 4)	/* Receive FIFO Usable Area (0x40 = full) */
 
 /* SISTR */
 #define SISTR_TFEMP		BIT(29) /* Transmit FIFO Empty */
@@ -811,7 +807,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
 	}
 
 	/* 1 stage FIFO watermarks for DMA */
-	sh_msiof_write(p, SIFCTR, SIFCTR_TFWM_1 | SIFCTR_RFWM_1);
+	sh_msiof_write(p, SIFCTR,
+		       FIELD_PREP(SIFCTR_TFWM, SIFCTR_TFWM_1) |
+		       FIELD_PREP(SIFCTR_RFWM, SIFCTR_RFWM_1));
 
 	/* setup msiof transfer mode registers (32-bit words) */
 	sh_msiof_spi_set_mode_regs(p, tx, rx, 32, len / 4);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 13/22] spi: sh-msiof: Correct SIMDR2_GRPMASK
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (11 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 12/22] spi: sh-msiof: SIFCTR " Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 14/22] spi: sh-msiof: Add core support for dual-group transfers Geert Uytterhoeven
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

The Group Output Mask is not a single bit, but a bit field, containing
one bit for each of the four possible groups.  Correct the definition.

Note that this change has no direct impact, as the driver only uses
the first group.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 812e64ea5f79ce5e..57f27040b0fc78d7 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -102,7 +102,7 @@ struct sh_msiof_spi_priv {
 /* SITMDR2 and SIRMDR2 */
 #define SIMDR2_BITLEN1		GENMASK(28, 24)	/* Data Size (8-32 bits) */
 #define SIMDR2_WDLEN1		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
-#define SIMDR2_GRPMASK1		BIT(0)		/* Group Output Mask 1 (SH, A1) */
+#define SIMDR2_GRPMASK		GENMASK(3, 0)	/* Group Output Mask 1-4 (SH, A1) */
 
 /* SITSCR and SIRSCR */
 #define SISCR_BRPS		GENMASK(12, 8)	/* Prescaler Setting (1-32) */
@@ -400,7 +400,7 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
 	if (tx_buf || (p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
 		sh_msiof_write(p, SITMDR2, dr2);
 	else
-		sh_msiof_write(p, SITMDR2, dr2 | SIMDR2_GRPMASK1);
+		sh_msiof_write(p, SITMDR2, dr2 | SIMDR2_GRPMASK);
 
 	if (rx_buf)
 		sh_msiof_write(p, SIRMDR2, dr2);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 14/22] spi: sh-msiof: Add core support for dual-group transfers
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (12 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 13/22] spi: sh-msiof: Correct SIMDR2_GRPMASK Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 15/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen2 Geert Uytterhoeven
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

All MSIOF variants support transferring data of multiple (2 or 4)
groups.  Add definitions for the register bits related to multiple
groups, and enhance sh_msiof_spi_set_mode_regs() to accept a second
group size.

For now the second group is unused.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 57f27040b0fc78d7..ea9277ab87f66cd5 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -100,10 +100,15 @@ struct sh_msiof_spi_priv {
 						/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
 
 /* SITMDR2 and SIRMDR2 */
+#define SIMDR2_GRP		GENMASK(31, 30)	/* Group Count */
 #define SIMDR2_BITLEN1		GENMASK(28, 24)	/* Data Size (8-32 bits) */
 #define SIMDR2_WDLEN1		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
 #define SIMDR2_GRPMASK		GENMASK(3, 0)	/* Group Output Mask 1-4 (SH, A1) */
 
+/* SITMDR3 and SIRMDR3 */
+#define SIMDR3_BITLEN2		GENMASK(28, 24)	/* Data Size (8-32 bits) */
+#define SIMDR3_WDLEN2		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
+
 /* SITSCR and SIRSCR */
 #define SISCR_BRPS		GENMASK(12, 8)	/* Prescaler Setting (1-32) */
 #define SISCR_BRDV		GENMASK(2, 0)	/* Baud Rate Generator's Division Ratio */
@@ -392,10 +397,11 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,
 
 static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
 				       const void *tx_buf, void *rx_buf,
-				       u32 bits, u32 words)
+				       u32 bits, u32 words1, u32 words2)
 {
-	u32 dr2 = FIELD_PREP(SIMDR2_BITLEN1, bits - 1) |
-		  FIELD_PREP(SIMDR2_WDLEN1, words - 1);
+	u32 dr2 = FIELD_PREP(SIMDR2_GRP, words2 ? 1 : 0) |
+		  FIELD_PREP(SIMDR2_BITLEN1, bits - 1) |
+		  FIELD_PREP(SIMDR2_WDLEN1, words1 - 1);
 
 	if (tx_buf || (p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
 		sh_msiof_write(p, SITMDR2, dr2);
@@ -404,6 +410,15 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
 
 	if (rx_buf)
 		sh_msiof_write(p, SIRMDR2, dr2);
+
+	if (words2) {
+		u32 dr3 = FIELD_PREP(SIMDR3_BITLEN2, bits - 1) |
+			  FIELD_PREP(SIMDR3_WDLEN2, words2 - 1);
+
+		sh_msiof_write(p, SITMDR3, dr3);
+		if (rx_buf)
+			sh_msiof_write(p, SIRMDR3, dr3);
+	}
 }
 
 static void sh_msiof_reset_str(struct sh_msiof_spi_priv *p)
@@ -712,7 +727,7 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p,
 	sh_msiof_write(p, SIFCTR, 0);
 
 	/* setup msiof transfer mode registers */
-	sh_msiof_spi_set_mode_regs(p, tx_buf, rx_buf, bits, words);
+	sh_msiof_spi_set_mode_regs(p, tx_buf, rx_buf, bits, words, 0);
 	sh_msiof_write(p, SIIER, SIIER_TEOFE | SIIER_REOFE);
 
 	/* write tx fifo */
@@ -812,7 +827,7 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
 		       FIELD_PREP(SIFCTR_RFWM, SIFCTR_RFWM_1));
 
 	/* setup msiof transfer mode registers (32-bit words) */
-	sh_msiof_spi_set_mode_regs(p, tx, rx, 32, len / 4);
+	sh_msiof_spi_set_mode_regs(p, tx, rx, 32, len / 4, 0);
 
 	sh_msiof_write(p, SIIER, ier_bits);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 15/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen2
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (13 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 14/22] spi: sh-msiof: Add core support for dual-group transfers Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 16/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen3 Geert Uytterhoeven
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

According to Renesas Technical Updates TN-RCS-S068A/E, the MSIOF receive
FIFOs on R-Car Gen2 SoCs have room for 128 words of 32 bits.

Note that this change has no actual impact on the behavior of the
driver, as SPI_CONTROLLER_MUST_TX is set, and transfer size is currenty
limited to the minimum of the transmit and receive FIFO sizes.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index ea9277ab87f66cd5..8d18a26128d600f6 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -1099,7 +1099,7 @@ static const struct sh_msiof_chipdata rcar_gen2_data = {
 	.bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
 			      SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
 	.tx_fifo_size = 64,
-	.rx_fifo_size = 64,
+	.rx_fifo_size = 128,
 	.ctlr_flags = SPI_CONTROLLER_MUST_TX,
 	.min_div_pow = 0,
 };
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 16/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen3
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (14 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 15/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen2 Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 17/22] spi: sh-msiof: Increase TX FIFO size for R-Car V4H/V4M Geert Uytterhoeven
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

According to the R-Car Gen3 Hardware Manual Errata for Rev 0.55 of
September 28, 2017, the MSIOF receive FIFOs on R-Car Gen3 SoCs have room
for 256 words of 32 bits.

Note that this change has no actual impact on the behavior of the
driver, as SPI_CONTROLLER_MUST_TX is set, and transfer size is currenty
limited to the minimum of the transmit and receive FIFO sizes.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 8d18a26128d600f6..8afb7c1f64cd4486 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -1108,7 +1108,7 @@ static const struct sh_msiof_chipdata rcar_gen3_data = {
 	.bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
 			      SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
 	.tx_fifo_size = 64,
-	.rx_fifo_size = 64,
+	.rx_fifo_size = 256,
 	.ctlr_flags = SPI_CONTROLLER_MUST_TX,
 	.min_div_pow = 1,
 };
@@ -1117,7 +1117,7 @@ static const struct sh_msiof_chipdata rcar_r8a7795_data = {
 	.bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
 			      SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
 	.tx_fifo_size = 64,
-	.rx_fifo_size = 64,
+	.rx_fifo_size = 256,
 	.ctlr_flags = SPI_CONTROLLER_MUST_TX,
 	.min_div_pow = 1,
 	.flags = SH_MSIOF_FLAG_FIXED_DTDL_200,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 17/22] spi: sh-msiof: Increase TX FIFO size for R-Car V4H/V4M
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (15 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 16/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen3 Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 18/22] spi: sh-msiof: Simplify BRG's Division Ratio Geert Uytterhoeven
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

The MSIOF transmit FIFOs on R-Car V4H and V4M have 256 stages.
Add a new family-specific match entry to handle this.
Add quirk match entries for older R-Car Gen4 Socs (R-Car V3U and S4-8)
that have transmit FIFOs with only 64 stages, just like on R-Car Gen3.

Update the (unused) definition of SIFCTR_TFUA for consistency.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Alternatively, the family-specific match entry could keep referring to
rcar_gen3_data, and R-Car V4H and V4M could refer to the new entry.

Tested on White Hawk (R-Car V4H) and Gray Hawk Single (R-Car V4M) with
spi-loopback-test and external loopback, DMA and PIO, and a logic
analyzer.

v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 8afb7c1f64cd4486..26e71fc8890fda6d 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -149,7 +149,7 @@ struct sh_msiof_spi_priv {
 #define SIFCTR_TFWM_8		5U		/*  Transfer Request when 8 empty stages */
 #define SIFCTR_TFWM_4		6U		/*  Transfer Request when 4 empty stages */
 #define SIFCTR_TFWM_1		7U		/*  Transfer Request when 1 empty stage */
-#define SIFCTR_TFUA		GENMASK(26, 20) /* Transmit FIFO Usable Area */
+#define SIFCTR_TFUA		GENMASK(28, 20) /* Transmit FIFO Usable Area */
 #define SIFCTR_RFWM		GENMASK(15, 13)	/* Receive FIFO Watermark */
 #define SIFCTR_RFWM_1		0U		/*  Transfer Request when 1 valid stages */
 #define SIFCTR_RFWM_4		1U		/*  Transfer Request when 4 valid stages */
@@ -1113,6 +1113,15 @@ static const struct sh_msiof_chipdata rcar_gen3_data = {
 	.min_div_pow = 1,
 };
 
+static const struct sh_msiof_chipdata rcar_gen4_data = {
+	.bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
+			      SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
+	.tx_fifo_size = 256,
+	.rx_fifo_size = 256,
+	.ctlr_flags = SPI_CONTROLLER_MUST_TX,
+	.min_div_pow = 1,
+};
+
 static const struct sh_msiof_chipdata rcar_r8a7795_data = {
 	.bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
 			      SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
@@ -1128,7 +1137,9 @@ static const struct of_device_id sh_msiof_match[] __maybe_unused = {
 	{ .compatible = "renesas,rcar-gen2-msiof", .data = &rcar_gen2_data },
 	{ .compatible = "renesas,msiof-r8a7795",   .data = &rcar_r8a7795_data },
 	{ .compatible = "renesas,rcar-gen3-msiof", .data = &rcar_gen3_data },
-	{ .compatible = "renesas,rcar-gen4-msiof", .data = &rcar_gen3_data },
+	{ .compatible = "renesas,msiof-r8a779a0",  .data = &rcar_gen3_data },
+	{ .compatible = "renesas,msiof-r8a779f0",  .data = &rcar_gen3_data },
+	{ .compatible = "renesas,rcar-gen4-msiof", .data = &rcar_gen4_data },
 	{ .compatible = "renesas,sh-msiof",        .data = &sh_data }, /* Deprecated */
 	{ /* sentinel */ }
 };
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 18/22] spi: sh-msiof: Simplify BRG's Division Ratio
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (16 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 17/22] spi: sh-msiof: Increase TX FIFO size for R-Car V4H/V4M Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 19/22] spi: sh-msiof: Double maximum DMA transfer size using two groups Geert Uytterhoeven
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

As FIELD_PREP() masks the value to be stored in the field, the Baud Rate
Generator's Division Ratio handling can be simplified from a look-up
table to a single subtraction.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Gcc 13.3.0 is not smart enough to consider all possible values of
div_pow in the current code, hence this works fine.
However, the simpler test loop

    for (unsigned int pow = 0; pow < 6; pow++)
	    pr_info("pow %u scr 0x%08lx\n", pow,
		    FIELD_PREP(SISCR_BRDV, (pow - 1)));

does trigger a "FIELD_PREP: value too large for the field" compile-time
assertion, unless an explicit "& FIELD_MAX(SISCR_BRDV)" is added.
Should we be pro-active and add an extra "& FIELD_MAX(SISCR_BRDV)" now,
to prepare for compilers becoming smarter?

v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 26e71fc8890fda6d..2b8c143b21219521 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -112,12 +112,6 @@ struct sh_msiof_spi_priv {
 /* SITSCR and SIRSCR */
 #define SISCR_BRPS		GENMASK(12, 8)	/* Prescaler Setting (1-32) */
 #define SISCR_BRDV		GENMASK(2, 0)	/* Baud Rate Generator's Division Ratio */
-#define SISCR_BRDV_DIV_2	0U
-#define SISCR_BRDV_DIV_4	1U
-#define SISCR_BRDV_DIV_8	2U
-#define SISCR_BRDV_DIV_16	3U
-#define SISCR_BRDV_DIV_32	4U
-#define SISCR_BRDV_DIV_1	7U
 
 /* SICTR */
 #define SICTR_TSCKIZ		GENMASK(31, 30)	/* Transmit Clock I/O Polarity Select */
@@ -256,11 +250,6 @@ static void sh_msiof_spi_reset_regs(struct sh_msiof_spi_priv *p)
 				  100);
 }
 
-static const u32 sh_msiof_spi_div_array[] = {
-	SISCR_BRDV_DIV_1, SISCR_BRDV_DIV_2, SISCR_BRDV_DIV_4,
-	SISCR_BRDV_DIV_8, SISCR_BRDV_DIV_16, SISCR_BRDV_DIV_32,
-};
-
 static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
 				      struct spi_transfer *t)
 {
@@ -299,7 +288,8 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
 
 	t->effective_speed_hz = parent_rate / (brps << div_pow);
 
-	scr = FIELD_PREP(SISCR_BRDV, sh_msiof_spi_div_array[div_pow]) |
+	/* div_pow == 0 maps to SISCR_BRDV_DIV_1 == all ones */
+	scr = FIELD_PREP(SISCR_BRDV, div_pow - 1) |
 	      FIELD_PREP(SISCR_BRPS, brps - 1);
 	sh_msiof_write(p, SITSCR, scr);
 	if (!(p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 19/22] spi: sh-msiof: Double maximum DMA transfer size using two groups
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (17 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 18/22] spi: sh-msiof: Simplify BRG's Division Ratio Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 20/22] spi: sh-msiof: Document frame start sync pulse mode Geert Uytterhoeven
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

The maximum DMA transfer size is limited by the maximum values that can
be written to the word count fields (WDLENx) in the Transmit and Control
Data Registers (SITDR2/SIRDR2).  As all MSIOF variants support
transferring data of multiple (two or four) groups, the maximum size can
be doubled by using two groups instead of one, thus reducing setup
overhead for very large SPI transfers.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Tested on R-Car M2-W, E3, V4H, and V4M with spi-loopback-test and a
logic analyzer.

v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 2b8c143b21219521..4d9a44118e1c9d6c 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -767,10 +767,12 @@ static void sh_msiof_dma_complete(void *arg)
 }
 
 static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
-			     void *rx, unsigned int len)
+			     void *rx, unsigned int len,
+			     unsigned int max_wdlen)
 {
 	u32 ier_bits = 0;
 	struct dma_async_tx_descriptor *desc_tx = NULL, *desc_rx = NULL;
+	unsigned int words1, words2;
 	dma_cookie_t cookie;
 	int ret;
 
@@ -817,7 +819,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
 		       FIELD_PREP(SIFCTR_RFWM, SIFCTR_RFWM_1));
 
 	/* setup msiof transfer mode registers (32-bit words) */
-	sh_msiof_spi_set_mode_regs(p, tx, rx, 32, len / 4, 0);
+	words1 = min(len / 4, max_wdlen);
+	words2 = len / 4 - words1;
+	sh_msiof_spi_set_mode_regs(p, tx, rx, 32, words1, words2);
 
 	sh_msiof_write(p, SIIER, ier_bits);
 
@@ -969,7 +973,7 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
 		 *  DMA supports 32-bit words only, hence pack 8-bit and 16-bit
 		 *  words, with byte resp. word swapping.
 		 */
-		unsigned int l = min(round_down(len, 4), max_wdlen * 4);
+		unsigned int l = min(round_down(len, 4), 2 * max_wdlen * 4);
 
 		if (bits <= 8) {
 			copy32 = copy_bswap32;
@@ -982,7 +986,7 @@ static int sh_msiof_transfer_one(struct spi_controller *ctlr,
 		if (tx_buf)
 			copy32(p->tx_dma_page, tx_buf, l / 4);
 
-		ret = sh_msiof_dma_once(p, tx_buf, rx_buf, l);
+		ret = sh_msiof_dma_once(p, tx_buf, rx_buf, l, max_wdlen);
 		if (ret == -EAGAIN) {
 			dev_warn_once(&p->pdev->dev,
 				"DMA not available, falling back to PIO\n");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 20/22] spi: sh-msiof: Document frame start sync pulse mode
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (18 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 19/22] spi: sh-msiof: Double maximum DMA transfer size using two groups Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 21/22] spi: sh-msiof: Move register definitions to <linux/spi/sh_msiof.h> Geert Uytterhoeven
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Unused, but nice to have it documented.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - No changes.
---
 drivers/spi/spi-sh-msiof.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 4d9a44118e1c9d6c..5d9d551dbd220389 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -86,6 +86,7 @@ struct sh_msiof_spi_priv {
 /* SITMDR1 and SIRMDR1 */
 #define SIMDR1_TRMD		BIT(31)		/* Transfer Mode (1 = Master mode) */
 #define SIMDR1_SYNCMD		GENMASK(29, 28)	/* SYNC Mode */
+#define SIMDR1_SYNCMD_PULSE	0U		/*   Frame start sync pulse */
 #define SIMDR1_SYNCMD_SPI	2U		/*   Level mode/SPI */
 #define SIMDR1_SYNCMD_LR	3U		/*   L/R mode */
 #define SIMDR1_SYNCAC		BIT(25)		/* Sync Polarity (1 = Active-low) */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 21/22] spi: sh-msiof: Move register definitions to <linux/spi/sh_msiof.h>
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (19 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 20/22] spi: sh-msiof: Document frame start sync pulse mode Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-16 13:32 ` [PATCH v2 22/22] ASoC: renesas: msiof: Convert " Geert Uytterhoeven
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Move the MSIOF register and register bit definitions from the MSIOF SPI
driver to the existing header file <linux/spi/sh_msiof.h>, so they can
be shared with the MSIOF I2S driver.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - Make include/linux/spi/sh_msiof.h self-contained, to fix a build
    failure of sound/soc/renesas/rcar/msiof.c on some architectures
    after the next patch.
---
 drivers/spi/spi-sh-msiof.c   | 124 ----------------------------------
 include/linux/spi/sh_msiof.h | 125 +++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 124 deletions(-)

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 5d9d551dbd220389..94a867967e024446 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -7,7 +7,6 @@
  * Copyright (C) 2014-2017 Glider bvba
  */
 
-#include <linux/bitfield.h>
 #include <linux/bitmap.h>
 #include <linux/clk.h>
 #include <linux/completion.h>
@@ -64,129 +63,6 @@ struct sh_msiof_spi_priv {
 
 #define MAX_SS	3	/* Maximum number of native chip selects */
 
-#define SITMDR1	0x00	/* Transmit Mode Register 1 */
-#define SITMDR2	0x04	/* Transmit Mode Register 2 */
-#define SITMDR3	0x08	/* Transmit Mode Register 3 */
-#define SIRMDR1	0x10	/* Receive Mode Register 1 */
-#define SIRMDR2	0x14	/* Receive Mode Register 2 */
-#define SIRMDR3	0x18	/* Receive Mode Register 3 */
-#define SITSCR	0x20	/* Transmit Clock Select Register */
-#define SIRSCR	0x22	/* Receive Clock Select Register (SH, A1, APE6) */
-#define SICTR	0x28	/* Control Register */
-#define SIFCTR	0x30	/* FIFO Control Register */
-#define SISTR	0x40	/* Status Register */
-#define SIIER	0x44	/* Interrupt Enable Register */
-#define SITDR1	0x48	/* Transmit Control Data Register 1 (SH, A1) */
-#define SITDR2	0x4c	/* Transmit Control Data Register 2 (SH, A1) */
-#define SITFDR	0x50	/* Transmit FIFO Data Register */
-#define SIRDR1	0x58	/* Receive Control Data Register 1 (SH, A1) */
-#define SIRDR2	0x5c	/* Receive Control Data Register 2 (SH, A1) */
-#define SIRFDR	0x60	/* Receive FIFO Data Register */
-
-/* SITMDR1 and SIRMDR1 */
-#define SIMDR1_TRMD		BIT(31)		/* Transfer Mode (1 = Master mode) */
-#define SIMDR1_SYNCMD		GENMASK(29, 28)	/* SYNC Mode */
-#define SIMDR1_SYNCMD_PULSE	0U		/*   Frame start sync pulse */
-#define SIMDR1_SYNCMD_SPI	2U		/*   Level mode/SPI */
-#define SIMDR1_SYNCMD_LR	3U		/*   L/R mode */
-#define SIMDR1_SYNCAC		BIT(25)		/* Sync Polarity (1 = Active-low) */
-#define SIMDR1_BITLSB		BIT(24)		/* MSB/LSB First (1 = LSB first) */
-#define SIMDR1_DTDL		GENMASK(22, 20)	/* Data Pin Bit Delay for MSIOF_SYNC */
-#define SIMDR1_SYNCDL		GENMASK(18, 16)	/* Frame Sync Signal Timing Delay */
-#define SIMDR1_FLD		GENMASK(3, 2)	/* Frame Sync Signal Interval (0-3) */
-#define SIMDR1_XXSTP		BIT(0)		/* Transmission/Reception Stop on FIFO */
-/* SITMDR1 */
-#define SITMDR1_PCON		BIT(30)		/* Transfer Signal Connection */
-#define SITMDR1_SYNCCH		GENMASK(27, 26)	/* Sync Signal Channel Select */
-						/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
-
-/* SITMDR2 and SIRMDR2 */
-#define SIMDR2_GRP		GENMASK(31, 30)	/* Group Count */
-#define SIMDR2_BITLEN1		GENMASK(28, 24)	/* Data Size (8-32 bits) */
-#define SIMDR2_WDLEN1		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
-#define SIMDR2_GRPMASK		GENMASK(3, 0)	/* Group Output Mask 1-4 (SH, A1) */
-
-/* SITMDR3 and SIRMDR3 */
-#define SIMDR3_BITLEN2		GENMASK(28, 24)	/* Data Size (8-32 bits) */
-#define SIMDR3_WDLEN2		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
-
-/* SITSCR and SIRSCR */
-#define SISCR_BRPS		GENMASK(12, 8)	/* Prescaler Setting (1-32) */
-#define SISCR_BRDV		GENMASK(2, 0)	/* Baud Rate Generator's Division Ratio */
-
-/* SICTR */
-#define SICTR_TSCKIZ		GENMASK(31, 30)	/* Transmit Clock I/O Polarity Select */
-#define SICTR_TSCKIZ_SCK	BIT(31)		/*   Disable SCK when TX disabled */
-#define SICTR_TSCKIZ_POL	BIT(30)		/*   Transmit Clock Polarity */
-#define SICTR_RSCKIZ		GENMASK(29, 28) /* Receive Clock Polarity Select */
-#define SICTR_RSCKIZ_SCK	BIT(29)		/*   Must match CTR_TSCKIZ_SCK */
-#define SICTR_RSCKIZ_POL	BIT(28)		/*   Receive Clock Polarity */
-#define SICTR_TEDG		BIT(27)		/* Transmit Timing (1 = falling edge) */
-#define SICTR_REDG		BIT(26)		/* Receive Timing (1 = falling edge) */
-#define SICTR_TXDIZ		GENMASK(23, 22)	/* Pin Output When TX is Disabled */
-#define SICTR_TXDIZ_LOW		0U		/*   0 */
-#define SICTR_TXDIZ_HIGH	1U		/*   1 */
-#define SICTR_TXDIZ_HIZ		2U		/*   High-impedance */
-#define SICTR_TSCKE		BIT(15)		/* Transmit Serial Clock Output Enable */
-#define SICTR_TFSE		BIT(14)		/* Transmit Frame Sync Signal Output Enable */
-#define SICTR_TXE		BIT(9)		/* Transmit Enable */
-#define SICTR_RXE		BIT(8)		/* Receive Enable */
-#define SICTR_TXRST		BIT(1)		/* Transmit Reset */
-#define SICTR_RXRST		BIT(0)		/* Receive Reset */
-
-/* SIFCTR */
-#define SIFCTR_TFWM		GENMASK(31, 29)	/* Transmit FIFO Watermark */
-#define SIFCTR_TFWM_64		0U		/*  Transfer Request when 64 empty stages */
-#define SIFCTR_TFWM_32		1U		/*  Transfer Request when 32 empty stages */
-#define SIFCTR_TFWM_24		2U		/*  Transfer Request when 24 empty stages */
-#define SIFCTR_TFWM_16		3U		/*  Transfer Request when 16 empty stages */
-#define SIFCTR_TFWM_12		4U		/*  Transfer Request when 12 empty stages */
-#define SIFCTR_TFWM_8		5U		/*  Transfer Request when 8 empty stages */
-#define SIFCTR_TFWM_4		6U		/*  Transfer Request when 4 empty stages */
-#define SIFCTR_TFWM_1		7U		/*  Transfer Request when 1 empty stage */
-#define SIFCTR_TFUA		GENMASK(28, 20) /* Transmit FIFO Usable Area */
-#define SIFCTR_RFWM		GENMASK(15, 13)	/* Receive FIFO Watermark */
-#define SIFCTR_RFWM_1		0U		/*  Transfer Request when 1 valid stages */
-#define SIFCTR_RFWM_4		1U		/*  Transfer Request when 4 valid stages */
-#define SIFCTR_RFWM_8		2U		/*  Transfer Request when 8 valid stages */
-#define SIFCTR_RFWM_16		3U		/*  Transfer Request when 16 valid stages */
-#define SIFCTR_RFWM_32		4U		/*  Transfer Request when 32 valid stages */
-#define SIFCTR_RFWM_64		5U		/*  Transfer Request when 64 valid stages */
-#define SIFCTR_RFWM_128		6U		/*  Transfer Request when 128 valid stages */
-#define SIFCTR_RFWM_256		7U		/*  Transfer Request when 256 valid stages */
-#define SIFCTR_RFUA		GENMASK(12, 4)	/* Receive FIFO Usable Area (0x40 = full) */
-
-/* SISTR */
-#define SISTR_TFEMP		BIT(29) /* Transmit FIFO Empty */
-#define SISTR_TDREQ		BIT(28) /* Transmit Data Transfer Request */
-#define SISTR_TEOF		BIT(23) /* Frame Transmission End */
-#define SISTR_TFSERR		BIT(21) /* Transmit Frame Synchronization Error */
-#define SISTR_TFOVF		BIT(20) /* Transmit FIFO Overflow */
-#define SISTR_TFUDF		BIT(19) /* Transmit FIFO Underflow */
-#define SISTR_RFFUL		BIT(13) /* Receive FIFO Full */
-#define SISTR_RDREQ		BIT(12) /* Receive Data Transfer Request */
-#define SISTR_REOF		BIT(7)  /* Frame Reception End */
-#define SISTR_RFSERR		BIT(5)  /* Receive Frame Synchronization Error */
-#define SISTR_RFUDF		BIT(4)  /* Receive FIFO Underflow */
-#define SISTR_RFOVF		BIT(3)  /* Receive FIFO Overflow */
-
-/* SIIER */
-#define SIIER_TDMAE		BIT(31) /* Transmit Data DMA Transfer Req. Enable */
-#define SIIER_TFEMPE		BIT(29) /* Transmit FIFO Empty Enable */
-#define SIIER_TDREQE		BIT(28) /* Transmit Data Transfer Request Enable */
-#define SIIER_TEOFE		BIT(23) /* Frame Transmission End Enable */
-#define SIIER_TFSERRE		BIT(21) /* Transmit Frame Sync Error Enable */
-#define SIIER_TFOVFE		BIT(20) /* Transmit FIFO Overflow Enable */
-#define SIIER_TFUDFE		BIT(19) /* Transmit FIFO Underflow Enable */
-#define SIIER_RDMAE		BIT(15) /* Receive Data DMA Transfer Req. Enable */
-#define SIIER_RFFULE		BIT(13) /* Receive FIFO Full Enable */
-#define SIIER_RDREQE		BIT(12) /* Receive Data Transfer Request Enable */
-#define SIIER_REOFE		BIT(7)  /* Frame Reception End Enable */
-#define SIIER_RFSERRE		BIT(5)  /* Receive Frame Sync Error Enable */
-#define SIIER_RFUDFE		BIT(4)  /* Receive FIFO Underflow Enable */
-#define SIIER_RFOVFE		BIT(3)  /* Receive FIFO Overflow Enable */
-
-
 static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
 {
 	switch (reg_offs) {
diff --git a/include/linux/spi/sh_msiof.h b/include/linux/spi/sh_msiof.h
index f950d280461b917d..9fbef3fd40567d04 100644
--- a/include/linux/spi/sh_msiof.h
+++ b/include/linux/spi/sh_msiof.h
@@ -2,6 +2,131 @@
 #ifndef __SPI_SH_MSIOF_H__
 #define __SPI_SH_MSIOF_H__
 
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+
+#define SITMDR1	0x00	/* Transmit Mode Register 1 */
+#define SITMDR2	0x04	/* Transmit Mode Register 2 */
+#define SITMDR3	0x08	/* Transmit Mode Register 3 */
+#define SIRMDR1	0x10	/* Receive Mode Register 1 */
+#define SIRMDR2	0x14	/* Receive Mode Register 2 */
+#define SIRMDR3	0x18	/* Receive Mode Register 3 */
+#define SITSCR	0x20	/* Transmit Clock Select Register */
+#define SIRSCR	0x22	/* Receive Clock Select Register (SH, A1, APE6) */
+#define SICTR	0x28	/* Control Register */
+#define SIFCTR	0x30	/* FIFO Control Register */
+#define SISTR	0x40	/* Status Register */
+#define SIIER	0x44	/* Interrupt Enable Register */
+#define SITDR1	0x48	/* Transmit Control Data Register 1 (SH, A1) */
+#define SITDR2	0x4c	/* Transmit Control Data Register 2 (SH, A1) */
+#define SITFDR	0x50	/* Transmit FIFO Data Register */
+#define SIRDR1	0x58	/* Receive Control Data Register 1 (SH, A1) */
+#define SIRDR2	0x5c	/* Receive Control Data Register 2 (SH, A1) */
+#define SIRFDR	0x60	/* Receive FIFO Data Register */
+
+/* SITMDR1 and SIRMDR1 */
+#define SIMDR1_TRMD		BIT(31)		/* Transfer Mode (1 = Master mode) */
+#define SIMDR1_SYNCMD		GENMASK(29, 28)	/* SYNC Mode */
+#define SIMDR1_SYNCMD_PULSE	0U		/*   Frame start sync pulse */
+#define SIMDR1_SYNCMD_SPI	2U		/*   Level mode/SPI */
+#define SIMDR1_SYNCMD_LR	3U		/*   L/R mode */
+#define SIMDR1_SYNCAC		BIT(25)		/* Sync Polarity (1 = Active-low) */
+#define SIMDR1_BITLSB		BIT(24)		/* MSB/LSB First (1 = LSB first) */
+#define SIMDR1_DTDL		GENMASK(22, 20)	/* Data Pin Bit Delay for MSIOF_SYNC */
+#define SIMDR1_SYNCDL		GENMASK(18, 16)	/* Frame Sync Signal Timing Delay */
+#define SIMDR1_FLD		GENMASK(3, 2)	/* Frame Sync Signal Interval (0-3) */
+#define SIMDR1_XXSTP		BIT(0)		/* Transmission/Reception Stop on FIFO */
+/* SITMDR1 */
+#define SITMDR1_PCON		BIT(30)		/* Transfer Signal Connection */
+#define SITMDR1_SYNCCH		GENMASK(27, 26)	/* Sync Signal Channel Select */
+						/* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */
+
+/* SITMDR2 and SIRMDR2 */
+#define SIMDR2_GRP		GENMASK(31, 30)	/* Group Count */
+#define SIMDR2_BITLEN1		GENMASK(28, 24)	/* Data Size (8-32 bits) */
+#define SIMDR2_WDLEN1		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
+#define SIMDR2_GRPMASK		GENMASK(3, 0)	/* Group Output Mask 1-4 (SH, A1) */
+
+/* SITMDR3 and SIRMDR3 */
+#define SIMDR3_BITLEN2		GENMASK(28, 24)	/* Data Size (8-32 bits) */
+#define SIMDR3_WDLEN2		GENMASK(23, 16)	/* Word Count (1-64/256 (SH, A1))) */
+
+/* SITSCR and SIRSCR */
+#define SISCR_BRPS		GENMASK(12, 8)	/* Prescaler Setting (1-32) */
+#define SISCR_BRDV		GENMASK(2, 0)	/* Baud Rate Generator's Division Ratio */
+
+/* SICTR */
+#define SICTR_TSCKIZ		GENMASK(31, 30)	/* Transmit Clock I/O Polarity Select */
+#define SICTR_TSCKIZ_SCK	BIT(31)		/*   Disable SCK when TX disabled */
+#define SICTR_TSCKIZ_POL	BIT(30)		/*   Transmit Clock Polarity */
+#define SICTR_RSCKIZ		GENMASK(29, 28) /* Receive Clock Polarity Select */
+#define SICTR_RSCKIZ_SCK	BIT(29)		/*   Must match CTR_TSCKIZ_SCK */
+#define SICTR_RSCKIZ_POL	BIT(28)		/*   Receive Clock Polarity */
+#define SICTR_TEDG		BIT(27)		/* Transmit Timing (1 = falling edge) */
+#define SICTR_REDG		BIT(26)		/* Receive Timing (1 = falling edge) */
+#define SICTR_TXDIZ		GENMASK(23, 22)	/* Pin Output When TX is Disabled */
+#define SICTR_TXDIZ_LOW		0U		/*   0 */
+#define SICTR_TXDIZ_HIGH	1U		/*   1 */
+#define SICTR_TXDIZ_HIZ		2U		/*   High-impedance */
+#define SICTR_TSCKE		BIT(15)		/* Transmit Serial Clock Output Enable */
+#define SICTR_TFSE		BIT(14)		/* Transmit Frame Sync Signal Output Enable */
+#define SICTR_TXE		BIT(9)		/* Transmit Enable */
+#define SICTR_RXE		BIT(8)		/* Receive Enable */
+#define SICTR_TXRST		BIT(1)		/* Transmit Reset */
+#define SICTR_RXRST		BIT(0)		/* Receive Reset */
+
+/* SIFCTR */
+#define SIFCTR_TFWM		GENMASK(31, 29)	/* Transmit FIFO Watermark */
+#define SIFCTR_TFWM_64		0U		/*  Transfer Request when 64 empty stages */
+#define SIFCTR_TFWM_32		1U		/*  Transfer Request when 32 empty stages */
+#define SIFCTR_TFWM_24		2U		/*  Transfer Request when 24 empty stages */
+#define SIFCTR_TFWM_16		3U		/*  Transfer Request when 16 empty stages */
+#define SIFCTR_TFWM_12		4U		/*  Transfer Request when 12 empty stages */
+#define SIFCTR_TFWM_8		5U		/*  Transfer Request when 8 empty stages */
+#define SIFCTR_TFWM_4		6U		/*  Transfer Request when 4 empty stages */
+#define SIFCTR_TFWM_1		7U		/*  Transfer Request when 1 empty stage */
+#define SIFCTR_TFUA		GENMASK(28, 20) /* Transmit FIFO Usable Area */
+#define SIFCTR_RFWM		GENMASK(15, 13)	/* Receive FIFO Watermark */
+#define SIFCTR_RFWM_1		0U		/*  Transfer Request when 1 valid stages */
+#define SIFCTR_RFWM_4		1U		/*  Transfer Request when 4 valid stages */
+#define SIFCTR_RFWM_8		2U		/*  Transfer Request when 8 valid stages */
+#define SIFCTR_RFWM_16		3U		/*  Transfer Request when 16 valid stages */
+#define SIFCTR_RFWM_32		4U		/*  Transfer Request when 32 valid stages */
+#define SIFCTR_RFWM_64		5U		/*  Transfer Request when 64 valid stages */
+#define SIFCTR_RFWM_128		6U		/*  Transfer Request when 128 valid stages */
+#define SIFCTR_RFWM_256		7U		/*  Transfer Request when 256 valid stages */
+#define SIFCTR_RFUA		GENMASK(12, 4)	/* Receive FIFO Usable Area (0x40 = full) */
+
+/* SISTR */
+#define SISTR_TFEMP		BIT(29) /* Transmit FIFO Empty */
+#define SISTR_TDREQ		BIT(28) /* Transmit Data Transfer Request */
+#define SISTR_TEOF		BIT(23) /* Frame Transmission End */
+#define SISTR_TFSERR		BIT(21) /* Transmit Frame Synchronization Error */
+#define SISTR_TFOVF		BIT(20) /* Transmit FIFO Overflow */
+#define SISTR_TFUDF		BIT(19) /* Transmit FIFO Underflow */
+#define SISTR_RFFUL		BIT(13) /* Receive FIFO Full */
+#define SISTR_RDREQ		BIT(12) /* Receive Data Transfer Request */
+#define SISTR_REOF		BIT(7)  /* Frame Reception End */
+#define SISTR_RFSERR		BIT(5)  /* Receive Frame Synchronization Error */
+#define SISTR_RFUDF		BIT(4)  /* Receive FIFO Underflow */
+#define SISTR_RFOVF		BIT(3)  /* Receive FIFO Overflow */
+
+/* SIIER */
+#define SIIER_TDMAE		BIT(31) /* Transmit Data DMA Transfer Req. Enable */
+#define SIIER_TFEMPE		BIT(29) /* Transmit FIFO Empty Enable */
+#define SIIER_TDREQE		BIT(28) /* Transmit Data Transfer Request Enable */
+#define SIIER_TEOFE		BIT(23) /* Frame Transmission End Enable */
+#define SIIER_TFSERRE		BIT(21) /* Transmit Frame Sync Error Enable */
+#define SIIER_TFOVFE		BIT(20) /* Transmit FIFO Overflow Enable */
+#define SIIER_TFUDFE		BIT(19) /* Transmit FIFO Underflow Enable */
+#define SIIER_RDMAE		BIT(15) /* Receive Data DMA Transfer Req. Enable */
+#define SIIER_RFFULE		BIT(13) /* Receive FIFO Full Enable */
+#define SIIER_RDREQE		BIT(12) /* Receive Data Transfer Request Enable */
+#define SIIER_REOFE		BIT(7)  /* Frame Reception End Enable */
+#define SIIER_RFSERRE		BIT(5)  /* Receive Frame Sync Error Enable */
+#define SIIER_RFUDFE		BIT(4)  /* Receive FIFO Underflow Enable */
+#define SIIER_RFOVFE		BIT(3)  /* Receive FIFO Overflow Enable */
+
 enum {
 	MSIOF_SPI_HOST,
 	MSIOF_SPI_TARGET,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 22/22] ASoC: renesas: msiof: Convert to <linux/spi/sh_msiof.h>
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (20 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 21/22] spi: sh-msiof: Move register definitions to <linux/spi/sh_msiof.h> Geert Uytterhoeven
@ 2025-05-16 13:32 ` Geert Uytterhoeven
  2025-05-20 11:20   ` Mark Brown
  2025-05-20 11:05 ` [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Mark Brown
  2025-06-09 15:39 ` (subset) " Mark Brown
  23 siblings, 1 reply; 28+ messages in thread
From: Geert Uytterhoeven @ 2025-05-16 13:32 UTC (permalink / raw)
  To: Mark Brown, Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Koji Matsuoka, Wolfram Sang
  Cc: linux-spi, linux-sound, linux-renesas-soc, Geert Uytterhoeven

Convert the MSIOF I2S driver to reuse the MSIOF register and register
bit definitions in the header file shared by the MSIOF SPI driver.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
Compile-tested and asm-inspected only due to lack of local sound
hardware.

v2:
  - Add Tested-by.
---
 sound/soc/renesas/rcar/msiof.c | 94 ++++++++++------------------------
 1 file changed, 28 insertions(+), 66 deletions(-)

diff --git a/sound/soc/renesas/rcar/msiof.c b/sound/soc/renesas/rcar/msiof.c
index 75c9e91bada10289..36d31ab8ac6a5f18 100644
--- a/sound/soc/renesas/rcar/msiof.c
+++ b/sound/soc/renesas/rcar/msiof.c
@@ -30,56 +30,15 @@
 #include <linux/of_graph.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/spi/sh_msiof.h>
 #include <sound/dmaengine_pcm.h>
 #include <sound/soc.h>
 
-/* register */
-#define SITMDR1		0x00
-#define SITMDR2		0x04
-#define SITMDR3		0x08
-#define SIRMDR1		0x10
-#define SIRMDR2		0x14
-#define SIRMDR3		0x18
-#define SICTR		0x28
-#define SISTR		0x40
-#define SIIER		0x44
-#define SITFDR		0x50
-#define SIRFDR		0x60
-
-/* SITMDR1/ SIRMDR1 */
-#define PCON		(1 << 30)		/* Transfer Signal Connection */
-#define SYNCMD_LR	(3 << 28)		/* L/R mode */
-#define SYNCAC		(1 << 25)		/* Sync Polarity (Active-low) */
-#define DTDL_1		(1 << 20)		/* 1-clock-cycle delay */
-#define TXSTP		(1 <<  0)		/* Transmission/Reception Stop on FIFO */
-
-/* SITMDR2 and SIRMDR2 */
-#define BITLEN1(x)	(((x) - 1) << 24)	/* Data Size (8-32 bits) */
-#define GRP		(1 << 30)		/* Group count */
-
-/* SICTR */
-#define TEDG		(1 << 27)		/* Transmit Timing (1 = falling edge) */
-#define REDG		(1 << 26)		/* Receive  Timing (1 = rising  edge) */
-#define TXE		(1 <<  9)		/* Transmit Enable */
-#define RXE		(1 <<  8)		/* Receive Enable */
-
 /* SISTR */
-#define TFSERR		(1 << 21)		/* Transmit Frame Synchronization Error */
-#define TFOVF		(1 << 20)		/* Transmit FIFO Overflow */
-#define TFUDF		(1 << 19)		/* Transmit FIFO Underflow */
-#define RFSERR		(1 <<  5)		/* Receive Frame Synchronization Error */
-#define RFUDF		(1 <<  4)		/* Receive FIFO Underflow */
-#define RFOVF		(1 <<  3)		/* Receive FIFO Overflow */
-#define SISTR_ERR_TX	(TFSERR | TFOVF | TFUDF)
-#define SISTR_ERR_RX	(RFSERR | RFOVF | RFUDF)
+#define SISTR_ERR_TX	(SISTR_TFSERR | SISTR_TFOVF | SISTR_TFUDF)
+#define SISTR_ERR_RX	(SISTR_RFSERR | SISTR_RFOVF | SISTR_RFUDF)
 #define SISTR_ERR	(SISTR_ERR_TX | SISTR_ERR_RX)
 
-/* SIIER */
-#define TDMAE		(1 << 31)		/* Transmit Data DMA Transfer Req. Enable */
-#define TDREQE		(1 << 28)		/* Transmit Data Transfer Request Enable */
-#define RDMAE		(1 << 15)		/* Receive Data DMA Transfer Req. Enable */
-#define RDREQE		(1 << 12)		/* Receive Data Transfer Request Enable */
-
 /*
  * The data on memory in 24bit case is located at <right> side
  *	[  xxxxxx]
@@ -174,42 +133,45 @@ static int msiof_hw_start(struct snd_soc_component *component,
 
 	/* SITMDRx */
 	if (is_play) {
-		val = PCON | SYNCMD_LR | SYNCAC | TXSTP;
+		val = SITMDR1_PCON |
+		      FIELD_PREP(SIMDR1_SYNCMD, SIMDR1_SYNCMD_LR) |
+		      SIMDR1_SYNCAC | SIMDR1_XXSTP;
 		if (msiof_flag_has(priv, MSIOF_FLAGS_NEED_DELAY))
-			val |= DTDL_1;
+			val |= FIELD_PREP(SIMDR1_DTDL, 1);
 
 		msiof_write(priv, SITMDR1, val);
 
-		val = BITLEN1(width);
-		msiof_write(priv, SITMDR2, val | GRP);
+		val = FIELD_PREP(SIMDR2_BITLEN1, width - 1);
+		msiof_write(priv, SITMDR2, val | FIELD_PREP(SIMDR2_GRP, 1));
 		msiof_write(priv, SITMDR3, val);
 
 	}
 	/* SIRMDRx */
 	else {
-		val = SYNCMD_LR | SYNCAC;
+		val = FIELD_PREP(SIMDR1_SYNCMD, SIMDR1_SYNCMD_LR) |
+		      SIMDR1_SYNCAC;
 		if (msiof_flag_has(priv, MSIOF_FLAGS_NEED_DELAY))
-			val |= DTDL_1;
+			val |= FIELD_PREP(SIMDR1_DTDL, 1);
 
 		msiof_write(priv, SIRMDR1, val);
 
-		val = BITLEN1(width);
-		msiof_write(priv, SIRMDR2, val | GRP);
+		val = FIELD_PREP(SIMDR2_BITLEN1, width - 1);
+		msiof_write(priv, SIRMDR2, val | FIELD_PREP(SIMDR2_GRP, 1));
 		msiof_write(priv, SIRMDR3, val);
 	}
 
 	/* SIIER */
 	if (is_play)
-		val = TDREQE | TDMAE | SISTR_ERR_TX;
+		val = SIIER_TDREQE | SIIER_TDMAE | SISTR_ERR_TX;
 	else
-		val = RDREQE | RDMAE | SISTR_ERR_RX;
+		val = SIIER_RDREQE | SIIER_RDMAE | SISTR_ERR_RX;
 	msiof_update(priv, SIIER, val, val);
 
 	/* SICTR */
 	if (is_play)
-		val = TXE | TEDG;
+		val = SICTR_TXE | SICTR_TEDG;
 	else
-		val = RXE | REDG;
+		val = SICTR_RXE | SICTR_REDG;
 	msiof_update_and_wait(priv, SICTR, val, val, val);
 
 	msiof_status_clear(priv);
@@ -230,9 +192,9 @@ static int msiof_hw_stop(struct snd_soc_component *component,
 
 	/* SIIER */
 	if (is_play)
-		val = TDREQE | TDMAE | SISTR_ERR_TX;
+		val = SIIER_TDREQE | SIIER_TDMAE | SISTR_ERR_TX;
 	else
-		val = RDREQE | RDMAE | SISTR_ERR_RX;
+		val = SIIER_RDREQE | SIIER_RDMAE | SISTR_ERR_RX;
 	msiof_update(priv, SIIER, val, 0);
 
 	/* Stop DMAC */
@@ -240,9 +202,9 @@ static int msiof_hw_stop(struct snd_soc_component *component,
 
 	/* SICTR */
 	if (is_play)
-		val = TXE;
+		val = SICTR_TXE;
 	else
-		val = RXE;
+		val = SICTR_RXE;
 	msiof_update_and_wait(priv, SICTR, val, 0, 0);
 
 	/* indicate error status if exist */
@@ -478,22 +440,22 @@ static irqreturn_t msiof_interrupt(int irq, void *data)
 	substream = priv->substream[SNDRV_PCM_STREAM_PLAYBACK];
 	if (substream && (sistr & SISTR_ERR_TX)) {
 		// snd_pcm_stop_xrun(substream);
-		if (sistr & TFSERR)
+		if (sistr & SISTR_TFSERR)
 			priv->err_syc[SNDRV_PCM_STREAM_PLAYBACK]++;
-		if (sistr & TFOVF)
+		if (sistr & SISTR_TFOVF)
 			priv->err_ovf[SNDRV_PCM_STREAM_PLAYBACK]++;
-		if (sistr & TFUDF)
+		if (sistr & SISTR_TFUDF)
 			priv->err_udf[SNDRV_PCM_STREAM_PLAYBACK]++;
 	}
 
 	substream = priv->substream[SNDRV_PCM_STREAM_CAPTURE];
 	if (substream && (sistr & SISTR_ERR_RX)) {
 		// snd_pcm_stop_xrun(substream);
-		if (sistr & RFSERR)
+		if (sistr & SISTR_RFSERR)
 			priv->err_syc[SNDRV_PCM_STREAM_CAPTURE]++;
-		if (sistr & RFOVF)
+		if (sistr & SISTR_RFOVF)
 			priv->err_ovf[SNDRV_PCM_STREAM_CAPTURE]++;
-		if (sistr & RFUDF)
+		if (sistr & SISTR_RFUDF)
 			priv->err_udf[SNDRV_PCM_STREAM_CAPTURE]++;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 04/22] spi: sh-msiof: Complete using dev in sh_msiof_spi_probe()
  2025-05-16 13:32 ` [PATCH v2 04/22] spi: sh-msiof: Complete using dev in sh_msiof_spi_probe() Geert Uytterhoeven
@ 2025-05-19  1:39   ` Kuninori Morimoto
  0 siblings, 0 replies; 28+ messages in thread
From: Kuninori Morimoto @ 2025-05-19  1:39 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Mark Brown, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Koji Matsuoka, Wolfram Sang, linux-spi, linux-sound,
	linux-renesas-soc


Hi Geert

> Commit c4887bd4b35b225f ("spi: sh-msiof: use dev in
> sh_msiof_spi_probe()") forgot to convert one instance.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---

Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

> v2:
>   - No changes.
> ---
>  drivers/spi/spi-sh-msiof.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
> index cf93c2ca821f84fa..367622985fea2a04 100644
> --- a/drivers/spi/spi-sh-msiof.c
> +++ b/drivers/spi/spi-sh-msiof.c
> @@ -1332,7 +1332,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
>  		goto err1;
>  	}
>  
> -	ret = devm_request_irq(dev, i, sh_msiof_spi_irq, 0, dev_name(&pdev->dev), p);
> +	ret = devm_request_irq(dev, i, sh_msiof_spi_irq, 0, dev_name(dev), p);
>  	if (ret) {
>  		dev_err(dev, "unable to request irq\n");
>  		goto err1;
> -- 
> 2.43.0
> 
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (21 preceding siblings ...)
  2025-05-16 13:32 ` [PATCH v2 22/22] ASoC: renesas: msiof: Convert " Geert Uytterhoeven
@ 2025-05-20 11:05 ` Mark Brown
  2025-06-09 15:39 ` (subset) " Mark Brown
  23 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2025-05-20 11:05 UTC (permalink / raw)
  To: Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Koji Matsuoka, Wolfram Sang, Geert Uytterhoeven
  Cc: linux-spi, linux-sound, linux-renesas-soc

On Fri, 16 May 2025 15:32:03 +0200, Geert Uytterhoeven wrote:
> 	Hi all,
> 
> This patch series (A) improves single transfer sizes in the MSIOF
> driver, using two methods:
>   - By increasing the assumed FIFO sizes, impacting both PIO and DMA
>     transfers,
>   - By using two groups, impacting DMA transfers,
> and (B) lets the recently-introduced MSIOF I2S drive reuse the SPI
> driver's register definitions.  All of this is covered with a thick
> sauce of fixes for (harmless) bugs, cleanups, and refactorings.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[01/22] spi: sh-msiof: Drop comma after OF match table sentinel
        commit: 0e1c7d0591ac4054c67529e200a9edfaf5344f4a
[02/22] spi: sh-msiof: Remove unneeded compatible values
        commit: ee44d3fc9d8b882cbc98acf2d3c773aba971aa67
[03/22] spi: sh-msiof: Fix maximum DMA transfer size
        commit: 0941d5166629cb766000530945e54b4e49680c68
[04/22] spi: sh-msiof: Complete using dev in sh_msiof_spi_probe()
        commit: 74df74ee83acfea4e9a6b47386c7907379c9295f
[05/22] spi: sh-msiof: Use bool for boolean flags
        commit: 3dd5ed19a2e8283f9ead5f2fd09b267a337ab86d
[06/22] spi: sh-msiof: Make words/bits unsigned in sh_msiof_spi_txrx_once()
        commit: b4eec5cdf112e3a4e286fb79fe507b09e2fca66f
[07/22] spi: sh-msiof: Make words/fs unsigned in FIFO helpers
        commit: 74cb19c943ddb46f3d06323c3d0469f14282c8ca
[08/22] spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion
        commit: 6bae252a9452ca8496670230a7821c34450763a2
[09/22] spi: sh-msiof: SITMDR2 and SIRMDR2 bitfield conversion
        commit: 386cc5207ba2b68a4672cb68810c44412531e74e
[10/22] spi: sh-msiof: SITSCR/SIRSCR bitfield conversion
        commit: c2cc4b72fc14c84fdb1bc49ec98af252ed64fbf3
[11/22] spi: sh-msiof: SICTR bitfield conversion
        commit: bd8d6658e7084ff9e78da9623633e79c9d31ad68
[12/22] spi: sh-msiof: SIFCTR bitfield conversion
        commit: 8f3903b382f73eb5c36d342dea838d991e4bbe08
[13/22] spi: sh-msiof: Correct SIMDR2_GRPMASK
        commit: acedbff0f0de1c116a0f8d943c4cf005f61f6143
[14/22] spi: sh-msiof: Add core support for dual-group transfers
        commit: 955f7ce6680564963765e5fc1c3e71027a39a806
[15/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen2
        commit: 1ab2c8c45f5c5df6707cc848686e674f4ec5c3d9
[16/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen3
        commit: f669c2827dd691b10fcf4e4c5546869a51d0a46e
[17/22] spi: sh-msiof: Increase TX FIFO size for R-Car V4H/V4M
        commit: 5b91dc7e3e371e7263b95c0d31151c645d6652a6
[18/22] spi: sh-msiof: Simplify BRG's Division Ratio
        commit: 39d0856f4102b6b61fdc650f90a1d9231e2bab17
[19/22] spi: sh-msiof: Double maximum DMA transfer size using two groups
        commit: acb47aa9b1e2f47121cf2233fcaf998151ab5410
[20/22] spi: sh-msiof: Document frame start sync pulse mode
        commit: 8f836868d848a9b84c38ae1f8e7366e01927c024
[21/22] spi: sh-msiof: Move register definitions to <linux/spi/sh_msiof.h>
        commit: ec23a899d96f9ee3389abe6c516d09cae2fde5e3
[22/22] ASoC: renesas: msiof: Convert to <linux/spi/sh_msiof.h>
        (no commit info)

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 22/22] ASoC: renesas: msiof: Convert to <linux/spi/sh_msiof.h>
  2025-05-16 13:32 ` [PATCH v2 22/22] ASoC: renesas: msiof: Convert " Geert Uytterhoeven
@ 2025-05-20 11:20   ` Mark Brown
  2025-06-09  0:02     ` Kuninori Morimoto
  0 siblings, 1 reply; 28+ messages in thread
From: Mark Brown @ 2025-05-20 11:20 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Koji Matsuoka, Wolfram Sang, linux-spi, linux-sound,
	linux-renesas-soc

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]

On Fri, May 16, 2025 at 03:32:25PM +0200, Geert Uytterhoeven wrote:
> Convert the MSIOF I2S driver to reuse the MSIOF register and register
> bit definitions in the header file shared by the MSIOF SPI driver.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

The dependencies and size of merge were looking nasty for a cross tree
merge, I'll try to remember to apply this at -rc1 but it's probably
worth checking that I manage to do that.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 22/22] ASoC: renesas: msiof: Convert to <linux/spi/sh_msiof.h>
  2025-05-20 11:20   ` Mark Brown
@ 2025-06-09  0:02     ` Kuninori Morimoto
  0 siblings, 0 replies; 28+ messages in thread
From: Kuninori Morimoto @ 2025-06-09  0:02 UTC (permalink / raw)
  To: Mark Brown
  Cc: Geert Uytterhoeven, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Koji Matsuoka, Wolfram Sang, linux-spi, linux-sound,
	linux-renesas-soc


Hi Mark, Geert

> > Convert the MSIOF I2S driver to reuse the MSIOF register and register
> > bit definitions in the header file shared by the MSIOF SPI driver.
> > 
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> The dependencies and size of merge were looking nasty for a cross tree
> merge, I'll try to remember to apply this at -rc1 but it's probably
> worth checking that I manage to do that.

-rc1 was released

Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: (subset) [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse
  2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
                   ` (22 preceding siblings ...)
  2025-05-20 11:05 ` [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Mark Brown
@ 2025-06-09 15:39 ` Mark Brown
  23 siblings, 0 replies; 28+ messages in thread
From: Mark Brown @ 2025-06-09 15:39 UTC (permalink / raw)
  To: Kuninori Morimoto, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Koji Matsuoka, Wolfram Sang, Geert Uytterhoeven
  Cc: linux-spi, linux-sound, linux-renesas-soc

On Fri, 16 May 2025 15:32:03 +0200, Geert Uytterhoeven wrote:
> 	Hi all,
> 
> This patch series (A) improves single transfer sizes in the MSIOF
> driver, using two methods:
>   - By increasing the assumed FIFO sizes, impacting both PIO and DMA
>     transfers,
>   - By using two groups, impacting DMA transfers,
> and (B) lets the recently-introduced MSIOF I2S drive reuse the SPI
> driver's register definitions.  All of this is covered with a thick
> sauce of fixes for (harmless) bugs, cleanups, and refactorings.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[22/22] ASoC: renesas: msiof: Convert to <linux/spi/sh_msiof.h>
        commit: 6ba68e5aa9d5d15c8877a655db279fcfc0b38b04

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2025-06-09 15:39 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-16 13:32 [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 01/22] spi: sh-msiof: Drop comma after OF match table sentinel Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 02/22] spi: sh-msiof: Remove unneeded compatible values Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 03/22] spi: sh-msiof: Fix maximum DMA transfer size Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 04/22] spi: sh-msiof: Complete using dev in sh_msiof_spi_probe() Geert Uytterhoeven
2025-05-19  1:39   ` Kuninori Morimoto
2025-05-16 13:32 ` [PATCH v2 05/22] spi: sh-msiof: Use bool for boolean flags Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 06/22] spi: sh-msiof: Make words/bits unsigned in sh_msiof_spi_txrx_once() Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 07/22] spi: sh-msiof: Make words/fs unsigned in FIFO helpers Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 08/22] spi: sh-msiof: SITMDR1/SIRMDR1 bitfield conversion Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 09/22] spi: sh-msiof: SITMDR2 and SIRMDR2 " Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 10/22] spi: sh-msiof: SITSCR/SIRSCR " Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 11/22] spi: sh-msiof: SICTR " Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 12/22] spi: sh-msiof: SIFCTR " Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 13/22] spi: sh-msiof: Correct SIMDR2_GRPMASK Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 14/22] spi: sh-msiof: Add core support for dual-group transfers Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 15/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen2 Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 16/22] spi: sh-msiof: Correct RX FIFO size for R-Car Gen3 Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 17/22] spi: sh-msiof: Increase TX FIFO size for R-Car V4H/V4M Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 18/22] spi: sh-msiof: Simplify BRG's Division Ratio Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 19/22] spi: sh-msiof: Double maximum DMA transfer size using two groups Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 20/22] spi: sh-msiof: Document frame start sync pulse mode Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 21/22] spi: sh-msiof: Move register definitions to <linux/spi/sh_msiof.h> Geert Uytterhoeven
2025-05-16 13:32 ` [PATCH v2 22/22] ASoC: renesas: msiof: Convert " Geert Uytterhoeven
2025-05-20 11:20   ` Mark Brown
2025-06-09  0:02     ` Kuninori Morimoto
2025-05-20 11:05 ` [PATCH v2 00/22] spi: sh-msiof: Transfer size improvements and I2S reuse Mark Brown
2025-06-09 15:39 ` (subset) " Mark Brown

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).